Socket::Netlink::Generic
- interface to Linux's NETLINK_GENERIC
netlink socket protocol
use Socket; use Socket::Netlink qw( :DEFAULT pack_nlmsghdr unpack_nlmsghdr pack_nlattrs unpack_nlattrs ); use Socket::Netlink::Generic qw( :DEFAULT pack_genlmsghdr unpack_genlmsghdr ); socket( my $sock, PF_NETLINK, SOCK_RAW, NETLINK_GENERIC ) or die "socket: $!"; send( $sock, pack_nlmsghdr( NETLINK_GENERIC, NLM_F_REQUEST, 0, 0, pack_genlmsghdr( CTRL_CMD_GETFAMILY, 0, pack_nlattrs( CTRL_ATTR_FAMILY_NAME, "TASKSTATS\0" ) ), ), 0 ) or die "send: $!"; recv( $sock, my $buffer, 65536, 0 ) or die "recv: $!"; my %attrs = unpack_nlattrs( (unpack_genlmsghdr( (unpack_nlmsghdr $buffer )[4] ) )[2] ); printf "TASKSTATS family ID is %d\n", unpack( "S", $attrs{CTRL_ATTR_FAMILY_ID()} );
This module contains the low-level constants and structure handling functions required to use the NETLINK_GENERIC
protocol of Linux's PF_NETLINK
socket family. It is suggested to use the high-level object interface to this instead; see IO::Socket::Netlink::Generic.
The following sets of constants are exported:
The netlink protocol constant:
NETLINK_GENERIC
Control commands:
CTRL_CMD_NEWFAMILY CTRL_CMD_DELFAMILY CTRL_CMD_GETFAMILY CTRL_CMD_NEWOPS CTRL_CMD_DELOPS CTRL_CMD_GETOPS CTRL_CMD_NEWMCAST_GRP CTRL_CMD_DELMCAST_GRP CTRL_CMD_GETMCAST_GRP
Attribute IDs:
CTRL_ATTR_FAMILY_ID CTRL_ATTR_FAMILY_NAME CTRL_ATTR_VERSION CTRL_ATTR_HDRSIZE CTRL_ATTR_MAXATTR CTRL_ATTR_OPS CTRL_ATTR_MCAST_GROUPS
Nested attribute IDs:
CTRL_ATTR_OP_ID CTRL_ATTR_OP_FLAGS CTRL_ATTR_MCAST_GRP_NAME CTRL_ATTR_MCAST_GRP_ID
Note that if the kernel headers are particularly old, not all of these constants may be available. If they are unavailable at compile time, no constant functions will be generated.
Pack or unpack a struct genlmsghdr
and its payload body.
PF_NETLINK
socket familyNETLINK_GENERIC
netlink protocol socketsPaul Evans <leonerd@leonerd.org.uk>