File Coverage

blib/lib/Socket/Netlink/Generic.pm
Criterion Covered Total %
statement 12 12 100.0
branch n/a
condition n/a
subroutine 4 4 100.0
pod n/a
total 16 16 100.0


line stmt bran cond sub pod time code
1             # You may distribute under the terms of either the GNU General Public License
2             # or the Artistic License (the same terms as Perl itself)
3             #
4             # (C) Paul Evans, 2010-2011 -- leonerd@leonerd.org.uk
5              
6             package Socket::Netlink::Generic;
7              
8 2     2   25736 use strict;
  2         6  
  2         80  
9 2     2   12 use warnings;
  2         4  
  2         98  
10              
11             our $VERSION = '0.04';
12              
13 2     2   10 use Exporter 'import';
  2         4  
  2         69  
14              
15 2     2   1164 use Socket::Netlink::Generic_const;
  2         4  
  2         85  
16              
17             =head1 NAME
18              
19             C - interface to Linux's C netlink
20             socket protocol
21              
22             =head1 SYNOPSIS
23              
24             use Socket;
25             use Socket::Netlink qw( :DEFAULT
26             pack_nlmsghdr unpack_nlmsghdr pack_nlattrs unpack_nlattrs );
27             use Socket::Netlink::Generic qw( :DEFAULT pack_genlmsghdr unpack_genlmsghdr );
28              
29             socket( my $sock, PF_NETLINK, SOCK_RAW, NETLINK_GENERIC ) or die "socket: $!";
30              
31             send( $sock, pack_nlmsghdr( NETLINK_GENERIC, NLM_F_REQUEST, 0, 0,
32             pack_genlmsghdr( CTRL_CMD_GETFAMILY, 0,
33             pack_nlattrs( CTRL_ATTR_FAMILY_NAME, "TASKSTATS\0" )
34             ),
35             ),
36             0 ) or die "send: $!";
37              
38             recv( $sock, my $buffer, 65536, 0 ) or die "recv: $!";
39              
40             my %attrs = unpack_nlattrs(
41             (unpack_genlmsghdr( (unpack_nlmsghdr $buffer )[4] ) )[2]
42             );
43              
44             printf "TASKSTATS family ID is %d\n",
45             unpack( "S", $attrs{CTRL_ATTR_FAMILY_ID()} );
46              
47             =head1 DESCRIPTION
48              
49             This module contains the low-level constants and structure handling functions
50             required to use the C protocol of Linux's C
51             socket family. It is suggested to use the high-level object interface to this
52             instead; see L.
53              
54             =cut
55              
56             =head1 CONSTANTS
57              
58             The following sets of constants are exported:
59              
60             The netlink protocol constant:
61              
62             NETLINK_GENERIC
63              
64             Control commands:
65              
66             CTRL_CMD_NEWFAMILY CTRL_CMD_DELFAMILY CTRL_CMD_GETFAMILY
67             CTRL_CMD_NEWOPS CTRL_CMD_DELOPS CTRL_CMD_GETOPS
68             CTRL_CMD_NEWMCAST_GRP CTRL_CMD_DELMCAST_GRP CTRL_CMD_GETMCAST_GRP
69              
70             Attribute IDs:
71              
72             CTRL_ATTR_FAMILY_ID CTRL_ATTR_FAMILY_NAME CTRL_ATTR_VERSION
73             CTRL_ATTR_HDRSIZE CTRL_ATTR_MAXATTR CTRL_ATTR_OPS
74             CTRL_ATTR_MCAST_GROUPS
75              
76             Nested attribute IDs:
77              
78             CTRL_ATTR_OP_ID CTRL_ATTR_OP_FLAGS
79             CTRL_ATTR_MCAST_GRP_NAME CTRL_ATTR_MCAST_GRP_ID
80              
81             Note that if the kernel headers are particularly old, not all of these
82             constants may be available. If they are unavailable at compile time, no
83             constant functions will be generated.
84              
85             =cut
86              
87             =head1 STRUCTURE FUNCTIONS
88              
89             =head2 $buffer = pack_genlmsghdr( $cmd, $version, $body )
90              
91             =head2 ( $cmd, $version, $body ) = unpack_genlmsghdr( $buffer )
92              
93             Pack or unpack a C and its payload body.
94              
95             =cut
96              
97             =head1 SEE ALSO
98              
99             =over 4
100              
101             =item *
102              
103             L - interface to Linux's C socket family
104              
105             =item *
106              
107             L - Object interface to C
108             netlink protocol sockets
109              
110             =back
111              
112             =head1 AUTHOR
113              
114             Paul Evans
115              
116             =cut
117              
118             0x55AA;