blib/lib/Socket/Netlink/Generic.pm

filter: Statementstmt 100% 14 / 14 Branchbran n/a Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 4 / 4 Podpod n/a totaltotal 100% 18 / 18 CC 1 SCAR 0.0
CC
1
Cov
100%
BEGIN
1.0
BEGIN
1.0
BEGIN
1.0
CRAP 1.0
« blib/lib/Socket/Netlink.pm ↑ Summary
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-2016 -- leonerd@leonerd.org.uk
5  
6 package Socket::Netlink::Generic;
7  
8 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 2 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 2 our $VERSION = '0.05';
12  
13 2 ▶use Exporter 'import';
Subroutine BEGIN: called CC=1 SCAR=0.0
14  
15 2 ▶use Socket::Netlink::Generic_const;
Subroutine BEGIN: called CC=1 SCAR=0.0
16  
17 =head1 NAME
18  
19 C<Socket::Netlink::Generic> - interface to Linux's C<NETLINK_GENERIC> 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<NETLINK_GENERIC> protocol of Linux's C<PF_NETLINK>
51 socket family. It is suggested to use the high-level object interface to this
52 instead; see L<IO::Socket::Netlink::Generic>.
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 pack_genlmsghdr
90  
91 $buffer = pack_genlmsghdr( $cmd, $version, $body )
92  
93 =head2 unpack_genlmsghdr
94  
95 ( $cmd, $version, $body ) = unpack_genlmsghdr( $buffer )
96  
97 Pack or unpack a C<struct genlmsghdr> and its payload body.
98  
99 =cut
100  
101 =head1 SEE ALSO
102  
103 =over 4
104  
105 =item *
106  
107 L<Socket::Netlink> - interface to Linux's C<PF_NETLINK> socket family
108  
109 =item *
110  
111 L<IO::Socket::Netlink::Generic> - Object interface to C<NETLINK_GENERIC>
112 netlink protocol sockets
113  
114 =back
115  
116 =head1 AUTHOR
117  
118 Paul Evans <leonerd@leonerd.org.uk>
119  
120 =cut
121  
122 2 0x55AA;
« blib/lib/Socket/Netlink.pm ↑ Summary