line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
7
|
|
|
7
|
|
45
|
use strict; |
|
7
|
|
|
|
|
14
|
|
|
7
|
|
|
|
|
203
|
|
2
|
7
|
|
|
7
|
|
32
|
use warnings; |
|
7
|
|
|
|
|
13
|
|
|
7
|
|
|
|
|
277
|
|
3
|
|
|
|
|
|
|
package Net::PcapWriter::ICMP_Echo; |
4
|
7
|
|
|
7
|
|
37
|
use fields qw(id src dst seq ip6 l2prefix writer); |
|
7
|
|
|
|
|
19
|
|
|
7
|
|
|
|
|
49
|
|
5
|
7
|
|
|
7
|
|
702
|
use Net::PcapWriter::IP; |
|
7
|
|
|
|
|
15
|
|
|
7
|
|
|
|
|
3273
|
|
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
sub new { |
8
|
2
|
|
|
2
|
0
|
8
|
my ($class,$writer,$src,$dst,$identifier) = @_; |
9
|
2
|
50
|
|
|
|
7
|
$identifier = 0 if ! defined $identifier; |
10
|
2
|
|
|
|
|
9
|
my $self = fields::new($class); |
11
|
2
|
|
|
|
|
6923
|
$self->{writer} = $writer; |
12
|
2
|
|
|
|
|
6
|
$self->{id} = $identifier; |
13
|
2
|
|
|
|
|
5
|
$self->{src} = $src; |
14
|
2
|
|
|
|
|
8
|
$self->{dst} = $dst; |
15
|
2
|
|
|
|
|
7
|
$self->{l2prefix} = $self->{writer}->layer2prefix($src); |
16
|
2
|
|
|
|
|
58
|
$self->{ip6} = $src =~m{:}; |
17
|
2
|
|
|
|
|
13
|
return $self; |
18
|
|
|
|
|
|
|
} |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
sub _write { |
23
|
6
|
|
|
6
|
|
13
|
my ($self,$dir,$seq,$data,$timestamp) = @_; |
24
|
|
|
|
|
|
|
|
25
|
6
|
100
|
|
|
|
16
|
my ($src,$dst) = $dir ? @{$self}{qw(dst src)} : @{$self}{qw(src dst)}; |
|
2
|
|
|
|
|
5
|
|
|
4
|
|
|
|
|
11
|
|
26
|
|
|
|
|
|
|
my $type = $dir ? |
27
|
|
|
|
|
|
|
$self->{ip6} ? 129 : 0 : # echo reply |
28
|
6
|
100
|
|
|
|
21
|
$self->{ip6} ? 128 : 8; # echo request |
|
|
100
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
29
|
|
|
|
|
|
|
my $echo = pack("CCnnna*", |
30
|
|
|
|
|
|
|
$type, |
31
|
|
|
|
|
|
|
0, # code = 0 |
32
|
|
|
|
|
|
|
0, # checksum, computed below |
33
|
|
|
|
|
|
|
$self->{id}, # identifier |
34
|
6
|
|
|
|
|
27
|
$seq, # sequence |
35
|
|
|
|
|
|
|
$data # payload |
36
|
|
|
|
|
|
|
); |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
$self->{writer}->packet( |
39
|
|
|
|
|
|
|
# checksum at offset 2 |
40
|
|
|
|
|
|
|
# for ip4 no pseudo-header will be included in checksum |
41
|
|
|
|
|
|
|
$self->{l2prefix} . ( $self->{ip6} |
42
|
6
|
100
|
|
|
|
27
|
? ip6_packet($echo,$src,$dst, 58, 2 ) |
43
|
|
|
|
|
|
|
: ip4_packet($echo,$src,$dst, 1, 2,1) |
44
|
|
|
|
|
|
|
), |
45
|
|
|
|
|
|
|
$timestamp |
46
|
|
|
|
|
|
|
); |
47
|
|
|
|
|
|
|
} |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
*echo_request = \&ping; |
51
|
|
|
|
|
|
|
sub ping { |
52
|
4
|
|
|
4
|
0
|
28
|
my ($self,$seq,$data,$timestamp) = @_; |
53
|
4
|
|
|
|
|
14
|
$self->_write(0,$seq,$data,$timestamp); |
54
|
|
|
|
|
|
|
} |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
*echo_response = \&pong; |
57
|
|
|
|
|
|
|
sub pong { |
58
|
2
|
|
|
2
|
0
|
15
|
my ($self,$seq,$data,$timestamp) = @_; |
59
|
2
|
|
|
|
|
10
|
$self->_write(1,$seq,$data,$timestamp); |
60
|
|
|
|
|
|
|
} |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
1; |