1Socket::Netlink(3)    User Contributed Perl Documentation   Socket::Netlink(3)
2
3
4

NAME

6       "Socket::Netlink" - interface to Linux's "PF_NETLINK" socket family
7

SYNOPSIS

9        use Socket;
10        use Socket::Netlink qw( :DEFAULT pack_nlmsghdr unpack_nlmsghdr );
11
12        socket( my $sock, PF_NETLINK, SOCK_RAW, 0 ) or die "socket: $!";
13
14        send( $sock, pack_nlmsghdr( 18, NLM_F_REQUEST|NLM_F_DUMP, 0, 0,
15             "\0\0\0\0\0\0\0\0" ), 0 )
16           or die "send: $!";
17
18        recv( $sock, my $buffer, 65536, 0 ) or die "recv: $!";
19
20        printf "Received type=%d flags=%x:\n%v02x\n",
21           ( unpack_nlmsghdr( $buffer ) )[ 0, 1, 4 ];
22

DESCRIPTION

24       This module contains the low-level constants and structure handling
25       functions required to use Linux's "PF_NETLINK" socket family. It is
26       suggested to use the high-level object interface to this instead; see
27       IO::Socket::Netlink.
28

CONSTANTS

30       The following constants are exported
31
32       PF_NETLINK
33               The packet family (for "socket()" calls)
34
35       AF_NETLINK
36               The address family
37

ADDRESS FUNCTIONS

39       The following pair of functions operate on "AF_NETLINK" address
40       structures.  The meainings of the parameters are:
41
42       pid     The unique endpoint number for this netlink socket. If given as
43               0 to the "bind()" syscall, the kernel will allocate an endpoint
44               number of the process's PID.
45
46       groups  A 32-bit bitmask of the multicast groups to join.
47
48   pack_sockaddr_nl
49          $addr = pack_sockaddr_nl( $pid, $groups )
50
51       Returns a "sockaddr_nl" structure with the fields packed into it.
52
53   unpack_sockaddr_nl
54          ( $pid, $groups ) = unpack_sockaddr_nl( $addr )
55
56       Takes a "sockaddr_nl" structure and returns the unpacked fields from
57       it.
58

STRUCTURE FUNCTIONS

60       The following function pairs operate on structure types used by netlink
61
62   pack_nlmsghdr
63          $buffer = pack_nlmsghdr( $type, $flags, $seq, $pid, $body )
64
65   unpack_nlmsghdr
66          ( $type, $flags, $seq, $pid, $body, $morebuffer ) = unpack_nlmsghdr( $buffer )
67
68       Pack or unpack a "struct nlmsghdr" and its payload body.
69
70       Because a single netlink message can contain more than payload body,
71       the "unpack_nlmsghdr" function will return the remaining buffer after
72       unpacking the first message, in case there are others. If there are no
73       more, the $morebuffer list element will not be returned.
74
75        while( defined $buffer ) {
76           ( my ( $type, $flags, $seq, $pid, $body ), $buffer ) = unpack_nlmsghdr( $buffer );
77           ...
78        }
79
80       There is no similar functionallity for "pack_nlmsghdr"; simply
81       concatenate multiple results together to send more than one message.
82
83   pack_nlmsgerr
84          $buffer = pack_nlmsgerr( $error, $msg )
85
86   unpack_nlmsgerr
87          ( $error, $msg ) = unpack_nlmsgerr( $buffer )
88
89       Pack or unpack a "struct nlmsgerr". The kernel expects or reports
90       negative integers in its structures; these functions take or return
91       normal positive error values suitable for use with $!.
92
93   pack_nlattrs
94          $buffer = pack_nlattrs( %attrs )
95
96   unpack_nlattrs
97          %attrs = unpack_nlattrs( $buffer )
98
99       Pack or unpack a list of netlink attributes.
100
101       These functions take or return even-sized lists of "$type, $value"
102       pairs.  The type will be the number in the netlink attribute message,
103       and the value will be a plain packed string buffer. It is the caller's
104       responsibilty to further pack/unpack this buffer as appropriate for the
105       specific type.
106
107       Because these functions take/return even-sized lists, they may be
108       passed or returned into hashes.
109

SEE ALSO

111netlink(7) - netlink - Communication between kernel and userspace
112           (AF_NETLINK)
113
114       •   IO::Socket::Netlink - Object interface to "AF_NETLINK" domain
115           sockets
116

AUTHOR

118       Paul Evans <leonerd@leonerd.org.uk>
119
120
121
122perl v5.36.0                      2022-07-22                Socket::Netlink(3)
Impressum