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-2016 -- leonerd@leonerd.org.uk |
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
package Socket::Netlink::Generic; |
7
|
|
|
|
|
|
|
|
8
|
2
|
|
|
2
|
|
18940
|
use strict; |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
55
|
|
9
|
2
|
|
|
2
|
|
7
|
use warnings; |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
83
|
|
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
our $VERSION = '0.05'; |
12
|
|
|
|
|
|
|
|
13
|
2
|
|
|
2
|
|
14
|
use Exporter 'import'; |
|
2
|
|
|
|
|
2
|
|
|
2
|
|
|
|
|
61
|
|
14
|
|
|
|
|
|
|
|
15
|
2
|
|
|
2
|
|
802
|
use Socket::Netlink::Generic_const; |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
111
|
|
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 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 and its payload body. |
98
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
=cut |
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
=head1 SEE ALSO |
102
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
=over 4 |
104
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
=item * |
106
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
L - interface to Linux's C socket family |
108
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
=item * |
110
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
L - Object interface to C |
112
|
|
|
|
|
|
|
netlink protocol sockets |
113
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
=back |
115
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
=head1 AUTHOR |
117
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
Paul Evans |
119
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
=cut |
121
|
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
0x55AA; |