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