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