line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package NetPacket::IGMP; |
2
|
|
|
|
|
|
|
our $AUTHORITY = 'cpan:YANICK'; |
3
|
|
|
|
|
|
|
# ABSTRACT: Assemble and disassemble IGMP (Internet Group Management Protocol) packets. |
4
|
|
|
|
|
|
|
$NetPacket::IGMP::VERSION = '1.7.2'; |
5
|
1
|
|
|
1
|
|
658
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
34
|
|
6
|
1
|
|
|
1
|
|
6
|
use warnings; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
34
|
|
7
|
|
|
|
|
|
|
|
8
|
1
|
|
|
1
|
|
6
|
use parent 'NetPacket'; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
7
|
|
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
our @EXPORT_OK = qw(igmp_strip |
11
|
|
|
|
|
|
|
IGMP_VERSION_RFC998 IGMP_VERSION_RFC1112 |
12
|
|
|
|
|
|
|
IGMP_VERSION_RFC2236 IGMP_VERSION_RFC3376 |
13
|
|
|
|
|
|
|
IGMP_MSG_HOST_MQUERY IGMP_MSG_HOST_MREPORT |
14
|
|
|
|
|
|
|
IGMP_MSG_HOST_MQUERYv2 IGMP_MSG_HOST_MREPORTv1 |
15
|
|
|
|
|
|
|
IGMP_MSG_HOST_MREPORTv2 IGMP_MSG_HOST_LEAVE |
16
|
|
|
|
|
|
|
IGMP_MSG_HOST_MREPORTv3 |
17
|
|
|
|
|
|
|
IGMP_IP_NO_HOSTS IGMP_IP_ALL_HOSTS |
18
|
|
|
|
|
|
|
IGMP_IP_ALL_ROUTERS |
19
|
|
|
|
|
|
|
); |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
our %EXPORT_TAGS = ( |
22
|
|
|
|
|
|
|
ALL => [@EXPORT_OK], |
23
|
|
|
|
|
|
|
strip => [qw(igmp_strip)], |
24
|
|
|
|
|
|
|
versions => [qw(IGMP_VERSION_RFC998 IGMP_VERSION_RFC1112 |
25
|
|
|
|
|
|
|
IGMP_VERSION_RFC2236 IGMP_VERSION_RFC3376)], |
26
|
|
|
|
|
|
|
msgtypes => [qw(IGMP_MSG_HOST_MQUERY IGMP_MSG_HOST_MREPORT |
27
|
|
|
|
|
|
|
IGMP_MSG_HOST_MQUERYv2 IGMP_MSG_HOST_MREPORTv1 |
28
|
|
|
|
|
|
|
IGMP_MSG_HOST_MREPORTv2 IGMP_MSG_HOST_LEAVE |
29
|
|
|
|
|
|
|
IGMP_MSG_HOST_MREPORTv3)], |
30
|
|
|
|
|
|
|
group_addrs => [qw(IGMP_IP_NO_HOSTS IGMP_IP_ALL_HOSTS |
31
|
|
|
|
|
|
|
IGMP_IP_ALL_ROUTERS)] |
32
|
|
|
|
|
|
|
); |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
# |
35
|
|
|
|
|
|
|
# Version numbers |
36
|
|
|
|
|
|
|
# |
37
|
|
|
|
|
|
|
|
38
|
1
|
|
|
1
|
|
136
|
use constant IGMP_VERSION_RFC998 => 0; # Version 0 of IGMP (obsolete) |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
67
|
|
39
|
1
|
|
|
1
|
|
6
|
use constant IGMP_VERSION_RFC1112 => 1; # Version 1 of IGMP |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
73
|
|
40
|
1
|
|
|
1
|
|
7
|
use constant IGMP_VERSION_RFC2236 => 2; # Version 2 of IGMP |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
44
|
|
41
|
1
|
|
|
1
|
|
5
|
use constant IGMP_VERSION_RFC3376 => 3; # Version 3 of IGMP |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
51
|
|
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
# |
44
|
|
|
|
|
|
|
# Message types |
45
|
|
|
|
|
|
|
# |
46
|
|
|
|
|
|
|
|
47
|
1
|
|
|
1
|
|
7
|
use constant IGMP_MSG_HOST_MQUERY => 1; # Host membership query |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
43
|
|
48
|
1
|
|
|
1
|
|
13
|
use constant IGMP_MSG_HOST_MREPORT => 2; # Host membership report |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
56
|
|
49
|
|
|
|
|
|
|
|
50
|
1
|
|
|
1
|
|
7
|
use constant IGMP_MSG_HOST_MQUERYv2 => 0x11; # Host membership query |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
51
|
|
51
|
1
|
|
|
1
|
|
7
|
use constant IGMP_MSG_HOST_MREPORTv1 => 0x12; # Host membership report |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
44
|
|
52
|
1
|
|
|
1
|
|
5
|
use constant IGMP_MSG_HOST_MREPORTv2 => 0x16; # Host membership report |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
69
|
|
53
|
1
|
|
|
1
|
|
7
|
use constant IGMP_MSG_HOST_LEAVE => 0x17; # Leave group |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
58
|
|
54
|
|
|
|
|
|
|
|
55
|
1
|
|
|
1
|
|
6
|
use constant IGMP_MSG_HOST_MREPORTv3 => 0x22; # Host membership report |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
55
|
|
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
# |
58
|
|
|
|
|
|
|
# IGMP IP addresses |
59
|
|
|
|
|
|
|
# |
60
|
|
|
|
|
|
|
|
61
|
1
|
|
|
1
|
|
5
|
use constant IGMP_IP_NO_HOSTS => '224.0.0.0'; # Not assigned to anyone |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
51
|
|
62
|
1
|
|
|
1
|
|
6
|
use constant IGMP_IP_ALL_HOSTS => '224.0.0.1'; # All hosts on local net |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
43
|
|
63
|
1
|
|
|
1
|
|
5
|
use constant IGMP_IP_ALL_ROUTERS => '224.0.0.2'; # All routers on local net |
|
1
|
|
|
|
|
11
|
|
|
1
|
|
|
|
|
391
|
|
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
# Convert 32-bit IP address to "dotted quad" notation |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
sub to_dotquad { |
68
|
0
|
|
|
0
|
0
|
|
my($net) = @_ ; |
69
|
0
|
|
|
|
|
|
my($na, $nb, $nc, $nd); |
70
|
|
|
|
|
|
|
|
71
|
0
|
|
|
|
|
|
$na = $net >> 24 & 255; |
72
|
0
|
|
|
|
|
|
$nb = $net >> 16 & 255; |
73
|
0
|
|
|
|
|
|
$nc = $net >> 8 & 255; |
74
|
0
|
|
|
|
|
|
$nd = $net & 255; |
75
|
|
|
|
|
|
|
|
76
|
0
|
|
|
|
|
|
return ("$na.$nb.$nc.$nd"); |
77
|
|
|
|
|
|
|
} |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
# |
80
|
|
|
|
|
|
|
# Decode the packet |
81
|
|
|
|
|
|
|
# |
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
sub decode { |
84
|
0
|
|
|
0
|
1
|
|
my $class = shift; |
85
|
0
|
|
|
|
|
|
my($pkt, $parent) = @_; |
86
|
0
|
|
|
|
|
|
my $self = {}; |
87
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
# Class fields |
89
|
|
|
|
|
|
|
|
90
|
0
|
|
|
|
|
|
$self->{_parent} = $parent; |
91
|
0
|
|
|
|
|
|
$self->{_frame} = $pkt; |
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
# Decode IGMP packet |
94
|
|
|
|
|
|
|
|
95
|
0
|
0
|
|
|
|
|
if (defined($pkt)) { |
96
|
0
|
|
|
|
|
|
my $tmp; |
97
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
($tmp, $self->{subtype}, $self->{cksum}, $self->{group_addr}, |
99
|
0
|
|
|
|
|
|
$self->{data}) = unpack('CCnNa*', $pkt); |
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
# Extract bit fields |
102
|
|
|
|
|
|
|
|
103
|
0
|
|
|
|
|
|
$self->{version} = ($tmp & 0xf0) >> 4; |
104
|
0
|
|
|
|
|
|
$self->{type} = $tmp & 0x0f; |
105
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
# Convert to dq notation |
107
|
|
|
|
|
|
|
|
108
|
0
|
|
|
|
|
|
$self->{group_addr} = to_dotquad($self->{group_addr}); |
109
|
|
|
|
|
|
|
} |
110
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
# Return a blessed object |
112
|
|
|
|
|
|
|
|
113
|
0
|
|
|
|
|
|
bless($self, $class); |
114
|
0
|
|
|
|
|
|
return $self; |
115
|
|
|
|
|
|
|
} |
116
|
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
# |
118
|
|
|
|
|
|
|
# Strip header from packet and return the data contained in it. IGMP |
119
|
|
|
|
|
|
|
# packets contain no encapsulated data. |
120
|
|
|
|
|
|
|
# |
121
|
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
sub igmp_strip { |
123
|
0
|
|
|
0
|
0
|
|
goto \&strip; |
124
|
|
|
|
|
|
|
} |
125
|
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
sub strip { |
127
|
0
|
|
|
0
|
1
|
|
return undef; |
128
|
|
|
|
|
|
|
} |
129
|
|
|
|
|
|
|
|
130
|
|
|
|
|
|
|
# |
131
|
|
|
|
|
|
|
# Encode a packet |
132
|
|
|
|
|
|
|
# |
133
|
|
|
|
|
|
|
|
134
|
|
|
|
|
|
|
sub encode { |
135
|
0
|
|
|
0
|
1
|
|
die("Not implemented"); |
136
|
|
|
|
|
|
|
} |
137
|
|
|
|
|
|
|
|
138
|
|
|
|
|
|
|
# Module return value |
139
|
|
|
|
|
|
|
|
140
|
|
|
|
|
|
|
1; |
141
|
|
|
|
|
|
|
|
142
|
|
|
|
|
|
|
# autoloaded methods go after the END token (&& pod) below |
143
|
|
|
|
|
|
|
|
144
|
|
|
|
|
|
|
=pod |
145
|
|
|
|
|
|
|
|
146
|
|
|
|
|
|
|
=head1 NAME |
147
|
|
|
|
|
|
|
|
148
|
|
|
|
|
|
|
NetPacket::IGMP - Assemble and disassemble IGMP (Internet Group Management Protocol) packets. |
149
|
|
|
|
|
|
|
|
150
|
|
|
|
|
|
|
=head1 VERSION |
151
|
|
|
|
|
|
|
|
152
|
|
|
|
|
|
|
version 1.7.2 |
153
|
|
|
|
|
|
|
|
154
|
|
|
|
|
|
|
=head1 SYNOPSIS |
155
|
|
|
|
|
|
|
|
156
|
|
|
|
|
|
|
use NetPacket::IGMP; |
157
|
|
|
|
|
|
|
|
158
|
|
|
|
|
|
|
$igmp_obj = NetPacket::IGMP->decode($raw_pkt); |
159
|
|
|
|
|
|
|
$igmp_pkt = NetPacket::IGMP->encode(params...); # Not implemented |
160
|
|
|
|
|
|
|
$igmp_data = NetPacket::IGMP::strip($raw_pkt); |
161
|
|
|
|
|
|
|
|
162
|
|
|
|
|
|
|
=head1 DESCRIPTION |
163
|
|
|
|
|
|
|
|
164
|
|
|
|
|
|
|
C provides a set of routines for assembling and |
165
|
|
|
|
|
|
|
disassembling packets using IGMP (Internet Group Management Protocol). |
166
|
|
|
|
|
|
|
|
167
|
|
|
|
|
|
|
=head2 Methods |
168
|
|
|
|
|
|
|
|
169
|
|
|
|
|
|
|
=over |
170
|
|
|
|
|
|
|
|
171
|
|
|
|
|
|
|
=item Cdecode([RAW PACKET])> |
172
|
|
|
|
|
|
|
|
173
|
|
|
|
|
|
|
Decode the raw packet data given and return an object containing |
174
|
|
|
|
|
|
|
instance data. This method will quite happily decode garbage input. |
175
|
|
|
|
|
|
|
It is the responsibility of the programmer to ensure valid packet data |
176
|
|
|
|
|
|
|
is passed to this method. |
177
|
|
|
|
|
|
|
|
178
|
|
|
|
|
|
|
=item Cencode(param =E value)> |
179
|
|
|
|
|
|
|
|
180
|
|
|
|
|
|
|
Return an IGMP packet encoded with the instance data specified. Not |
181
|
|
|
|
|
|
|
implemented. |
182
|
|
|
|
|
|
|
|
183
|
|
|
|
|
|
|
=back |
184
|
|
|
|
|
|
|
|
185
|
|
|
|
|
|
|
=head2 Functions |
186
|
|
|
|
|
|
|
|
187
|
|
|
|
|
|
|
=over |
188
|
|
|
|
|
|
|
|
189
|
|
|
|
|
|
|
=item C |
190
|
|
|
|
|
|
|
|
191
|
|
|
|
|
|
|
Return the encapsulated data (or payload) contained in the IGMP |
192
|
|
|
|
|
|
|
packet. This function returns undef as there is no encapsulated data |
193
|
|
|
|
|
|
|
in an IGMP packet. |
194
|
|
|
|
|
|
|
|
195
|
|
|
|
|
|
|
=back |
196
|
|
|
|
|
|
|
|
197
|
|
|
|
|
|
|
=head2 Instance data |
198
|
|
|
|
|
|
|
|
199
|
|
|
|
|
|
|
The instance data for the C object consists of |
200
|
|
|
|
|
|
|
the following fields. |
201
|
|
|
|
|
|
|
|
202
|
|
|
|
|
|
|
=over |
203
|
|
|
|
|
|
|
|
204
|
|
|
|
|
|
|
=item version |
205
|
|
|
|
|
|
|
|
206
|
|
|
|
|
|
|
The IGMP version of this packet. |
207
|
|
|
|
|
|
|
|
208
|
|
|
|
|
|
|
=item type |
209
|
|
|
|
|
|
|
|
210
|
|
|
|
|
|
|
The message type for this packet. |
211
|
|
|
|
|
|
|
|
212
|
|
|
|
|
|
|
=item len |
213
|
|
|
|
|
|
|
|
214
|
|
|
|
|
|
|
The length (including length of header) in bytes for this packet. |
215
|
|
|
|
|
|
|
|
216
|
|
|
|
|
|
|
=item subtype |
217
|
|
|
|
|
|
|
|
218
|
|
|
|
|
|
|
The message subtype for this packet. |
219
|
|
|
|
|
|
|
|
220
|
|
|
|
|
|
|
=item cksum |
221
|
|
|
|
|
|
|
|
222
|
|
|
|
|
|
|
The checksum for this packet. |
223
|
|
|
|
|
|
|
|
224
|
|
|
|
|
|
|
=item group_addr |
225
|
|
|
|
|
|
|
|
226
|
|
|
|
|
|
|
The group address specified in this packet. |
227
|
|
|
|
|
|
|
|
228
|
|
|
|
|
|
|
=item data |
229
|
|
|
|
|
|
|
|
230
|
|
|
|
|
|
|
The encapsulated data (payload) for this packet. |
231
|
|
|
|
|
|
|
|
232
|
|
|
|
|
|
|
=back |
233
|
|
|
|
|
|
|
|
234
|
|
|
|
|
|
|
=head2 Exports |
235
|
|
|
|
|
|
|
|
236
|
|
|
|
|
|
|
=over |
237
|
|
|
|
|
|
|
|
238
|
|
|
|
|
|
|
=item default |
239
|
|
|
|
|
|
|
|
240
|
|
|
|
|
|
|
none |
241
|
|
|
|
|
|
|
|
242
|
|
|
|
|
|
|
=item exportable |
243
|
|
|
|
|
|
|
|
244
|
|
|
|
|
|
|
IGMP_VERSION_RFC998 IGMP_VERSION_RFC1112 IGMP_HOST_MQUERY |
245
|
|
|
|
|
|
|
IGMP_HOST_MREPORT IGMP_IP_NO_HOSTS IGMP_IP_ALL_HOSTS |
246
|
|
|
|
|
|
|
IGMP_IP_ALL_ROUTERS |
247
|
|
|
|
|
|
|
|
248
|
|
|
|
|
|
|
=item tags |
249
|
|
|
|
|
|
|
|
250
|
|
|
|
|
|
|
The following tags group together related exportable items. |
251
|
|
|
|
|
|
|
|
252
|
|
|
|
|
|
|
=over |
253
|
|
|
|
|
|
|
|
254
|
|
|
|
|
|
|
=item C<:strip> |
255
|
|
|
|
|
|
|
|
256
|
|
|
|
|
|
|
Import the strip function C. |
257
|
|
|
|
|
|
|
|
258
|
|
|
|
|
|
|
=item C<:versions> |
259
|
|
|
|
|
|
|
|
260
|
|
|
|
|
|
|
IGMP_VERSION_RFC998 IGMP_VERSION_RFC1112 |
261
|
|
|
|
|
|
|
|
262
|
|
|
|
|
|
|
=item C<:msgtypes> |
263
|
|
|
|
|
|
|
|
264
|
|
|
|
|
|
|
IGMP_HOST_MQUERY IGMP_HOST_MREPORT |
265
|
|
|
|
|
|
|
|
266
|
|
|
|
|
|
|
=item C<:group_addrs> |
267
|
|
|
|
|
|
|
|
268
|
|
|
|
|
|
|
IGMP_IP_NO_HOSTS IGMP_IP_ALL_HOSTS IGMP_IP_ALL_ROUTERS |
269
|
|
|
|
|
|
|
|
270
|
|
|
|
|
|
|
=item C<:ALL> |
271
|
|
|
|
|
|
|
|
272
|
|
|
|
|
|
|
All the above exportable items. |
273
|
|
|
|
|
|
|
|
274
|
|
|
|
|
|
|
=back |
275
|
|
|
|
|
|
|
|
276
|
|
|
|
|
|
|
=back |
277
|
|
|
|
|
|
|
|
278
|
|
|
|
|
|
|
=head1 EXAMPLE |
279
|
|
|
|
|
|
|
|
280
|
|
|
|
|
|
|
The following script dumps UDP frames by IP address and UDP port |
281
|
|
|
|
|
|
|
to standard output. |
282
|
|
|
|
|
|
|
|
283
|
|
|
|
|
|
|
#!/usr/bin/perl -w |
284
|
|
|
|
|
|
|
|
285
|
|
|
|
|
|
|
use strict; |
286
|
|
|
|
|
|
|
use Net::PcapUtils; |
287
|
|
|
|
|
|
|
use NetPacket::Ethernet qw(:strip); |
288
|
|
|
|
|
|
|
use NetPacket::IP; |
289
|
|
|
|
|
|
|
use NetPacket::IGMP; |
290
|
|
|
|
|
|
|
|
291
|
|
|
|
|
|
|
sub process_pkt { |
292
|
|
|
|
|
|
|
my($arg, $hdr, $pkt) = @_; |
293
|
|
|
|
|
|
|
|
294
|
|
|
|
|
|
|
my $ip_obj = NetPacket::IP->decode(eth_strip($pkt)); |
295
|
|
|
|
|
|
|
my $igmp_obj = NetPacket::IGMP->decode($ip_obj->{data}); |
296
|
|
|
|
|
|
|
|
297
|
|
|
|
|
|
|
print("$ip_obj->{src_ip} -> $ip_obj->{dest_ip} ", |
298
|
|
|
|
|
|
|
"$igmp_obj->{type}/$igmp_obj->{subtype} ", |
299
|
|
|
|
|
|
|
"$igmp_obj->{group_addr}\n"); |
300
|
|
|
|
|
|
|
} |
301
|
|
|
|
|
|
|
|
302
|
|
|
|
|
|
|
Net::PcapUtils::loop(\&process_pkt, FILTER => 'igmp'); |
303
|
|
|
|
|
|
|
|
304
|
|
|
|
|
|
|
=head1 TODO |
305
|
|
|
|
|
|
|
|
306
|
|
|
|
|
|
|
=over |
307
|
|
|
|
|
|
|
|
308
|
|
|
|
|
|
|
=item Implement encode() function |
309
|
|
|
|
|
|
|
|
310
|
|
|
|
|
|
|
=back |
311
|
|
|
|
|
|
|
|
312
|
|
|
|
|
|
|
=head1 COPYRIGHT |
313
|
|
|
|
|
|
|
|
314
|
|
|
|
|
|
|
Copyright (c) 2001 Tim Potter. |
315
|
|
|
|
|
|
|
|
316
|
|
|
|
|
|
|
Copyright (c) 1995,1996,1997,1998,1999 ANU and CSIRO on behalf of |
317
|
|
|
|
|
|
|
the participants in the CRC for Advanced Computational Systems |
318
|
|
|
|
|
|
|
('ACSys'). |
319
|
|
|
|
|
|
|
|
320
|
|
|
|
|
|
|
This module is free software. You can redistribute it and/or |
321
|
|
|
|
|
|
|
modify it under the terms of the Artistic License 2.0. |
322
|
|
|
|
|
|
|
|
323
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful, |
324
|
|
|
|
|
|
|
but without any warranty; without even the implied warranty of |
325
|
|
|
|
|
|
|
merchantability or fitness for a particular purpose. |
326
|
|
|
|
|
|
|
|
327
|
|
|
|
|
|
|
=head1 AUTHOR |
328
|
|
|
|
|
|
|
|
329
|
|
|
|
|
|
|
Tim Potter Etpot@samba.orgE |
330
|
|
|
|
|
|
|
|
331
|
|
|
|
|
|
|
=cut |
332
|
|
|
|
|
|
|
|
333
|
|
|
|
|
|
|
__END__ |