| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package NetPacket::ARP; |
|
2
|
|
|
|
|
|
|
BEGIN { |
|
3
|
1
|
|
|
1
|
|
796
|
$NetPacket::ARP::AUTHORITY = 'cpan:YANICK'; |
|
4
|
|
|
|
|
|
|
} |
|
5
|
|
|
|
|
|
|
# ABSTRACT: Assemble and disassemble ARP (Address Resolution Protocol) packets. |
|
6
|
|
|
|
|
|
|
$NetPacket::ARP::VERSION = '1.6.0'; |
|
7
|
1
|
|
|
1
|
|
8
|
use strict; |
|
|
1
|
|
|
|
|
1
|
|
|
|
1
|
|
|
|
|
39
|
|
|
8
|
1
|
|
|
1
|
|
4
|
use warnings; |
|
|
1
|
|
|
|
|
1
|
|
|
|
1
|
|
|
|
|
26
|
|
|
9
|
|
|
|
|
|
|
|
|
10
|
1
|
|
|
1
|
|
3
|
use parent 'NetPacket'; |
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
6
|
|
|
11
|
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
our @EXPORT = qw(); |
|
13
|
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
# Other items we are prepared to export if requested |
|
15
|
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
our @EXPORT_OK = qw( |
|
17
|
|
|
|
|
|
|
arp_strip |
|
18
|
|
|
|
|
|
|
ARP_OPCODE_REQUEST ARP_OPCODE_REPLY RARP_OPCODE_REQUEST |
|
19
|
|
|
|
|
|
|
RARP_OPCODE_REPLY |
|
20
|
|
|
|
|
|
|
ARPHRD_NETROM ARPHRD_ETHER ARPHRD_EETHER ARPHRD_AX25 |
|
21
|
|
|
|
|
|
|
ARPHRD_PRONET ARPHRD_CHAOS ARPHRD_IEEE802 ARPHRD_ARCNET |
|
22
|
|
|
|
|
|
|
ARPHRD_APPLETLK ARPHRD_DLCI ARPHRD_ATM ARPHRD_METRICOM |
|
23
|
|
|
|
|
|
|
ARPHRD_IEEE1394 ARPHRD_EUI64 ARPHRD_INFINIBAND |
|
24
|
|
|
|
|
|
|
); |
|
25
|
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
our %EXPORT_TAGS = ( |
|
27
|
|
|
|
|
|
|
ALL => [@EXPORT, @EXPORT_OK], |
|
28
|
|
|
|
|
|
|
opcodes => [qw(ARP_OPCODE_REQUEST ARP_OPCODE_REPLY RARP_OPCODE_REQUEST |
|
29
|
|
|
|
|
|
|
RARP_OPCODE_REPLY)], |
|
30
|
|
|
|
|
|
|
protos => [qw(ARPHRD_NETROM ARPHRD_ETHER ARPHRD_AX25 ARPHRD_PRONET |
|
31
|
|
|
|
|
|
|
ARPHRD_CHAOS ARPHRD_IEEE802 ARPHRD_ARCNET |
|
32
|
|
|
|
|
|
|
ARPHRD_APPLETLK ARPHRD_DLCI ARPHRD_ATM ARPHRD_METRICOM |
|
33
|
|
|
|
|
|
|
ARPHRD_IEEE1394 ARPHRD_EUI64 ARPHRD_INFINIBAND)], |
|
34
|
|
|
|
|
|
|
strip => [qw(arp_strip)], |
|
35
|
|
|
|
|
|
|
); |
|
36
|
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
# |
|
39
|
|
|
|
|
|
|
# List of opcode values |
|
40
|
|
|
|
|
|
|
# |
|
41
|
|
|
|
|
|
|
|
|
42
|
1
|
|
|
1
|
|
118
|
use constant ARP_OPCODE_REQUEST => 1; |
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
63
|
|
|
43
|
1
|
|
|
1
|
|
6
|
use constant ARP_OPCODE_REPLY => 2; |
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
70
|
|
|
44
|
1
|
|
|
1
|
|
6
|
use constant RARP_OPCODE_REQUEST => 3; |
|
|
1
|
|
|
|
|
1
|
|
|
|
1
|
|
|
|
|
39
|
|
|
45
|
1
|
|
|
1
|
|
4
|
use constant RARP_OPCODE_REPLY => 4; |
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
45
|
|
|
46
|
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
# |
|
48
|
|
|
|
|
|
|
# List of hardware identifiers |
|
49
|
|
|
|
|
|
|
# |
|
50
|
|
|
|
|
|
|
|
|
51
|
1
|
|
|
1
|
|
4
|
use constant ARPHRD_NETROM => 0; |
|
|
1
|
|
|
|
|
1
|
|
|
|
1
|
|
|
|
|
30
|
|
|
52
|
1
|
|
|
1
|
|
3
|
use constant ARPHRD_ETHER => 1; |
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
33
|
|
|
53
|
1
|
|
|
1
|
|
3
|
use constant ARPHRD_EETHER => 2; |
|
|
1
|
|
|
|
|
1
|
|
|
|
1
|
|
|
|
|
32
|
|
|
54
|
1
|
|
|
1
|
|
4
|
use constant ARPHRD_AX25 => 3; |
|
|
1
|
|
|
|
|
1
|
|
|
|
1
|
|
|
|
|
29
|
|
|
55
|
1
|
|
|
1
|
|
3
|
use constant ARPHRD_PRONET => 4; |
|
|
1
|
|
|
|
|
4
|
|
|
|
1
|
|
|
|
|
35
|
|
|
56
|
1
|
|
|
1
|
|
7
|
use constant ARPHRD_CHAOS => 5; |
|
|
1
|
|
|
|
|
1
|
|
|
|
1
|
|
|
|
|
30
|
|
|
57
|
1
|
|
|
1
|
|
4
|
use constant ARPHRD_IEEE802 => 6; |
|
|
1
|
|
|
|
|
0
|
|
|
|
1
|
|
|
|
|
40
|
|
|
58
|
1
|
|
|
1
|
|
4
|
use constant ARPHRD_ARCNET => 7; |
|
|
1
|
|
|
|
|
0
|
|
|
|
1
|
|
|
|
|
39
|
|
|
59
|
1
|
|
|
1
|
|
4
|
use constant ARPHRD_APPLETLK => 8; |
|
|
1
|
|
|
|
|
1
|
|
|
|
1
|
|
|
|
|
31
|
|
|
60
|
1
|
|
|
1
|
|
3
|
use constant ARPHRD_DLCI => 15; |
|
|
1
|
|
|
|
|
1
|
|
|
|
1
|
|
|
|
|
63
|
|
|
61
|
1
|
|
|
1
|
|
5
|
use constant ARPHRD_ATM => 19; |
|
|
1
|
|
|
|
|
0
|
|
|
|
1
|
|
|
|
|
37
|
|
|
62
|
1
|
|
|
1
|
|
3
|
use constant ARPHRD_METRICOM => 23; |
|
|
1
|
|
|
|
|
1
|
|
|
|
1
|
|
|
|
|
35
|
|
|
63
|
1
|
|
|
1
|
|
3
|
use constant ARPHRD_IEEE1394 => 24; |
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
49
|
|
|
64
|
1
|
|
|
1
|
|
7
|
use constant ARPHRD_EUI64 => 27; |
|
|
1
|
|
|
|
|
1
|
|
|
|
1
|
|
|
|
|
59
|
|
|
65
|
1
|
|
|
1
|
|
4
|
use constant ARPHRD_INFINIBAND => 32; |
|
|
1
|
|
|
|
|
1
|
|
|
|
1
|
|
|
|
|
241
|
|
|
66
|
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
# |
|
68
|
|
|
|
|
|
|
# Decode the packet |
|
69
|
|
|
|
|
|
|
# |
|
70
|
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
sub decode { |
|
72
|
0
|
|
|
0
|
1
|
|
my $class = shift; |
|
73
|
0
|
|
|
|
|
|
my($pkt, $parent) = @_; |
|
74
|
0
|
|
|
|
|
|
my $self = {}; |
|
75
|
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
# Class fields |
|
77
|
|
|
|
|
|
|
|
|
78
|
0
|
|
|
|
|
|
$self->{_parent} = $parent; |
|
79
|
0
|
|
|
|
|
|
$self->{_frame} = $pkt; |
|
80
|
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
# Decode ARP packet |
|
82
|
|
|
|
|
|
|
|
|
83
|
0
|
0
|
|
|
|
|
if (defined($pkt)) { |
|
84
|
|
|
|
|
|
|
|
|
85
|
0
|
|
|
|
|
|
($self->{htype}, $self->{proto}, $self->{hlen}, $self->{plen}, |
|
86
|
|
|
|
|
|
|
$self->{opcode}, $self->{sha}, $self->{spa}, $self->{tha}, |
|
87
|
|
|
|
|
|
|
$self->{tpa}) = |
|
88
|
|
|
|
|
|
|
unpack('nnCCnH12H8H12H8' , $pkt); |
|
89
|
|
|
|
|
|
|
|
|
90
|
0
|
|
|
|
|
|
$self->{data} = undef; |
|
91
|
|
|
|
|
|
|
} |
|
92
|
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
# Return a blessed object |
|
94
|
|
|
|
|
|
|
|
|
95
|
0
|
|
|
|
|
|
bless($self, $class); |
|
96
|
0
|
|
|
|
|
|
return $self; |
|
97
|
|
|
|
|
|
|
} |
|
98
|
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
# |
|
101
|
|
|
|
|
|
|
# Strip header from packet and return the data contained in it. ARP |
|
102
|
|
|
|
|
|
|
# packets contain no encapsulated data. |
|
103
|
|
|
|
|
|
|
# |
|
104
|
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
undef &arp_strip; |
|
106
|
|
|
|
|
|
|
*arp_strip = \&strip; |
|
107
|
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
sub strip { |
|
109
|
0
|
|
|
0
|
1
|
|
return undef; |
|
110
|
|
|
|
|
|
|
} |
|
111
|
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
# |
|
113
|
|
|
|
|
|
|
# Encode a packet |
|
114
|
|
|
|
|
|
|
# |
|
115
|
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
sub encode { |
|
117
|
0
|
|
|
0
|
1
|
|
die("Not implemented"); |
|
118
|
|
|
|
|
|
|
} |
|
119
|
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
# Module return value |
|
121
|
|
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
1; |
|
123
|
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
=pod |
|
125
|
|
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
=head1 NAME |
|
127
|
|
|
|
|
|
|
|
|
128
|
|
|
|
|
|
|
NetPacket::ARP - Assemble and disassemble ARP (Address Resolution Protocol) packets. |
|
129
|
|
|
|
|
|
|
|
|
130
|
|
|
|
|
|
|
=head1 VERSION |
|
131
|
|
|
|
|
|
|
|
|
132
|
|
|
|
|
|
|
version 1.6.0 |
|
133
|
|
|
|
|
|
|
|
|
134
|
|
|
|
|
|
|
=head1 SYNOPSIS |
|
135
|
|
|
|
|
|
|
|
|
136
|
|
|
|
|
|
|
use NetPacket::ARP; |
|
137
|
|
|
|
|
|
|
|
|
138
|
|
|
|
|
|
|
$tcp_obj = NetPacket::ARP->decode($raw_pkt); |
|
139
|
|
|
|
|
|
|
$tcp_pkt = NetPacket::ARP->encode(params...); # Not implemented |
|
140
|
|
|
|
|
|
|
|
|
141
|
|
|
|
|
|
|
=head1 DESCRIPTION |
|
142
|
|
|
|
|
|
|
|
|
143
|
|
|
|
|
|
|
C provides a set of routines for assembling and |
|
144
|
|
|
|
|
|
|
disassembling packets using ARP (Address Resolution Protocol). |
|
145
|
|
|
|
|
|
|
|
|
146
|
|
|
|
|
|
|
=head2 Methods |
|
147
|
|
|
|
|
|
|
|
|
148
|
|
|
|
|
|
|
=over |
|
149
|
|
|
|
|
|
|
|
|
150
|
|
|
|
|
|
|
=item Cdecode([RAW PACKET])> |
|
151
|
|
|
|
|
|
|
|
|
152
|
|
|
|
|
|
|
Decode the raw packet data given and return an object containing |
|
153
|
|
|
|
|
|
|
instance data. This method will quite happily decode garbage input. |
|
154
|
|
|
|
|
|
|
It is the responsibility of the programmer to ensure valid packet data |
|
155
|
|
|
|
|
|
|
is passed to this method. |
|
156
|
|
|
|
|
|
|
|
|
157
|
|
|
|
|
|
|
=item Cencode(param =E value)> |
|
158
|
|
|
|
|
|
|
|
|
159
|
|
|
|
|
|
|
Return a ARP packet encoded with the instance data specified. Not |
|
160
|
|
|
|
|
|
|
implemented. |
|
161
|
|
|
|
|
|
|
|
|
162
|
|
|
|
|
|
|
=back |
|
163
|
|
|
|
|
|
|
|
|
164
|
|
|
|
|
|
|
=head2 Functions |
|
165
|
|
|
|
|
|
|
|
|
166
|
|
|
|
|
|
|
=over |
|
167
|
|
|
|
|
|
|
|
|
168
|
|
|
|
|
|
|
=item C |
|
169
|
|
|
|
|
|
|
|
|
170
|
|
|
|
|
|
|
Return the encapsulated data (or payload) contained in the TCP packet. |
|
171
|
|
|
|
|
|
|
Since no payload data is encapulated in an ARP packet (only instance |
|
172
|
|
|
|
|
|
|
data), this function returns undef. |
|
173
|
|
|
|
|
|
|
|
|
174
|
|
|
|
|
|
|
=back |
|
175
|
|
|
|
|
|
|
|
|
176
|
|
|
|
|
|
|
=head2 Instance data |
|
177
|
|
|
|
|
|
|
|
|
178
|
|
|
|
|
|
|
The instance data for the C object consists of |
|
179
|
|
|
|
|
|
|
the following fields. |
|
180
|
|
|
|
|
|
|
|
|
181
|
|
|
|
|
|
|
=over |
|
182
|
|
|
|
|
|
|
|
|
183
|
|
|
|
|
|
|
=item htype |
|
184
|
|
|
|
|
|
|
|
|
185
|
|
|
|
|
|
|
Hardware type. |
|
186
|
|
|
|
|
|
|
|
|
187
|
|
|
|
|
|
|
=item proto |
|
188
|
|
|
|
|
|
|
|
|
189
|
|
|
|
|
|
|
Protocol type. |
|
190
|
|
|
|
|
|
|
|
|
191
|
|
|
|
|
|
|
=item hlen |
|
192
|
|
|
|
|
|
|
|
|
193
|
|
|
|
|
|
|
Header length. |
|
194
|
|
|
|
|
|
|
|
|
195
|
|
|
|
|
|
|
=item plen |
|
196
|
|
|
|
|
|
|
|
|
197
|
|
|
|
|
|
|
Protocol length. |
|
198
|
|
|
|
|
|
|
|
|
199
|
|
|
|
|
|
|
=item opcode |
|
200
|
|
|
|
|
|
|
|
|
201
|
|
|
|
|
|
|
One of the following constants: |
|
202
|
|
|
|
|
|
|
|
|
203
|
|
|
|
|
|
|
=over |
|
204
|
|
|
|
|
|
|
|
|
205
|
|
|
|
|
|
|
=item * ARP_OPCODE_REQUEST |
|
206
|
|
|
|
|
|
|
|
|
207
|
|
|
|
|
|
|
=item * ARP_OPCODE_REPLY |
|
208
|
|
|
|
|
|
|
|
|
209
|
|
|
|
|
|
|
=item * RARP_OPCODE_REQUEST |
|
210
|
|
|
|
|
|
|
|
|
211
|
|
|
|
|
|
|
=item * RARP_OPCODE_REPLY |
|
212
|
|
|
|
|
|
|
|
|
213
|
|
|
|
|
|
|
=back |
|
214
|
|
|
|
|
|
|
|
|
215
|
|
|
|
|
|
|
=item sha |
|
216
|
|
|
|
|
|
|
|
|
217
|
|
|
|
|
|
|
Source hardware address. |
|
218
|
|
|
|
|
|
|
|
|
219
|
|
|
|
|
|
|
=item spa |
|
220
|
|
|
|
|
|
|
|
|
221
|
|
|
|
|
|
|
Source protocol address. |
|
222
|
|
|
|
|
|
|
|
|
223
|
|
|
|
|
|
|
=item tha |
|
224
|
|
|
|
|
|
|
|
|
225
|
|
|
|
|
|
|
Target hardware address. |
|
226
|
|
|
|
|
|
|
|
|
227
|
|
|
|
|
|
|
=item tpa |
|
228
|
|
|
|
|
|
|
|
|
229
|
|
|
|
|
|
|
Target protocol address. |
|
230
|
|
|
|
|
|
|
|
|
231
|
|
|
|
|
|
|
=back |
|
232
|
|
|
|
|
|
|
|
|
233
|
|
|
|
|
|
|
=head2 Exports |
|
234
|
|
|
|
|
|
|
|
|
235
|
|
|
|
|
|
|
=over |
|
236
|
|
|
|
|
|
|
|
|
237
|
|
|
|
|
|
|
=item default |
|
238
|
|
|
|
|
|
|
|
|
239
|
|
|
|
|
|
|
none |
|
240
|
|
|
|
|
|
|
|
|
241
|
|
|
|
|
|
|
=item exportable |
|
242
|
|
|
|
|
|
|
|
|
243
|
|
|
|
|
|
|
none |
|
244
|
|
|
|
|
|
|
|
|
245
|
|
|
|
|
|
|
=item tags |
|
246
|
|
|
|
|
|
|
|
|
247
|
|
|
|
|
|
|
The following tags group together related exportable items. |
|
248
|
|
|
|
|
|
|
|
|
249
|
|
|
|
|
|
|
=over |
|
250
|
|
|
|
|
|
|
|
|
251
|
|
|
|
|
|
|
=item C<:ALL> |
|
252
|
|
|
|
|
|
|
|
|
253
|
|
|
|
|
|
|
All the above exportable items. |
|
254
|
|
|
|
|
|
|
|
|
255
|
|
|
|
|
|
|
=back |
|
256
|
|
|
|
|
|
|
|
|
257
|
|
|
|
|
|
|
=back |
|
258
|
|
|
|
|
|
|
|
|
259
|
|
|
|
|
|
|
=head1 EXAMPLE |
|
260
|
|
|
|
|
|
|
|
|
261
|
|
|
|
|
|
|
Print out arp requests on the local network. |
|
262
|
|
|
|
|
|
|
|
|
263
|
|
|
|
|
|
|
#!/usr/bin/perl -w |
|
264
|
|
|
|
|
|
|
|
|
265
|
|
|
|
|
|
|
use Net::PcapUtils; |
|
266
|
|
|
|
|
|
|
use NetPacket::Ethernet qw(:types); |
|
267
|
|
|
|
|
|
|
use NetPacket::ARP; |
|
268
|
|
|
|
|
|
|
|
|
269
|
|
|
|
|
|
|
sub process_pkt { |
|
270
|
|
|
|
|
|
|
my ($arg, $hdr, $pkt) = @_; |
|
271
|
|
|
|
|
|
|
|
|
272
|
|
|
|
|
|
|
my $eth_obj = NetPacket::Ethernet->decode($pkt); |
|
273
|
|
|
|
|
|
|
|
|
274
|
|
|
|
|
|
|
if ($eth_obj->{type} == ETH_TYPE_ARP) { |
|
275
|
|
|
|
|
|
|
my $arp_obj = NetPacket::ARP->decode($eth_obj->{data}, $eth_obj); |
|
276
|
|
|
|
|
|
|
print("source hw addr=$arp_obj->{sha}, " . |
|
277
|
|
|
|
|
|
|
"dest hw addr=$arp_obj->{tha}\n"); |
|
278
|
|
|
|
|
|
|
} |
|
279
|
|
|
|
|
|
|
} |
|
280
|
|
|
|
|
|
|
|
|
281
|
|
|
|
|
|
|
Net::PcapUtils::loop(\&process_pkt); |
|
282
|
|
|
|
|
|
|
|
|
283
|
|
|
|
|
|
|
=head1 TODO |
|
284
|
|
|
|
|
|
|
|
|
285
|
|
|
|
|
|
|
=over |
|
286
|
|
|
|
|
|
|
|
|
287
|
|
|
|
|
|
|
=item Implement encode() function |
|
288
|
|
|
|
|
|
|
|
|
289
|
|
|
|
|
|
|
=item Does this work for protocols other than IP? Need to read RFC. |
|
290
|
|
|
|
|
|
|
|
|
291
|
|
|
|
|
|
|
=item Example is a bit silly |
|
292
|
|
|
|
|
|
|
|
|
293
|
|
|
|
|
|
|
=back |
|
294
|
|
|
|
|
|
|
|
|
295
|
|
|
|
|
|
|
=head1 COPYRIGHT |
|
296
|
|
|
|
|
|
|
|
|
297
|
|
|
|
|
|
|
Copyright (c) 2001 Tim Potter. |
|
298
|
|
|
|
|
|
|
|
|
299
|
|
|
|
|
|
|
Copyright (c) 1995,1996,1997,1998,1999 ANU and CSIRO on behalf of |
|
300
|
|
|
|
|
|
|
the participants in the CRC for Advanced Computational Systems |
|
301
|
|
|
|
|
|
|
('ACSys'). |
|
302
|
|
|
|
|
|
|
|
|
303
|
|
|
|
|
|
|
This module is free software. You can redistribute it and/or |
|
304
|
|
|
|
|
|
|
modify it under the terms of the Artistic License 2.0. |
|
305
|
|
|
|
|
|
|
|
|
306
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful, |
|
307
|
|
|
|
|
|
|
but without any warranty; without even the implied warranty of |
|
308
|
|
|
|
|
|
|
merchantability or fitness for a particular purpose. |
|
309
|
|
|
|
|
|
|
|
|
310
|
|
|
|
|
|
|
=head1 AUTHOR |
|
311
|
|
|
|
|
|
|
|
|
312
|
|
|
|
|
|
|
Tim Potter Etpot@samba.orgE |
|
313
|
|
|
|
|
|
|
|
|
314
|
|
|
|
|
|
|
=cut |
|
315
|
|
|
|
|
|
|
|
|
316
|
|
|
|
|
|
|
__END__ |