line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
7
|
|
|
7
|
|
49
|
use strict; |
|
7
|
|
|
|
|
13
|
|
|
7
|
|
|
|
|
174
|
|
2
|
7
|
|
|
7
|
|
36
|
use warnings; |
|
7
|
|
|
|
|
13
|
|
|
7
|
|
|
|
|
273
|
|
3
|
|
|
|
|
|
|
package Net::PcapWriter::ICMP_Echo; |
4
|
7
|
|
|
7
|
|
33
|
use fields qw(id src dst seq ip6 l2prefix writer); |
|
7
|
|
|
|
|
12
|
|
|
7
|
|
|
|
|
37
|
|
5
|
7
|
|
|
7
|
|
602
|
use Net::PcapWriter::IP; |
|
7
|
|
|
|
|
13
|
|
|
7
|
|
|
|
|
3342
|
|
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
sub new { |
8
|
2
|
|
|
2
|
0
|
6
|
my ($class,$writer,$src,$dst,$identifier) = @_; |
9
|
2
|
50
|
|
|
|
18
|
$identifier = 0 if ! defined $identifier; |
10
|
2
|
|
|
|
|
15
|
my $self = fields::new($class); |
11
|
2
|
|
|
|
|
8988
|
$self->{writer} = $writer; |
12
|
2
|
|
|
|
|
7
|
$self->{id} = $identifier; |
13
|
2
|
|
|
|
|
7
|
$self->{src} = $src; |
14
|
2
|
|
|
|
|
5
|
$self->{dst} = $dst; |
15
|
2
|
|
|
|
|
14
|
$self->{l2prefix} = $self->{writer}->layer2prefix($src); |
16
|
2
|
|
|
|
|
9
|
$self->{ip6} = $src =~m{:}; |
17
|
2
|
|
|
|
|
12
|
return $self; |
18
|
|
|
|
|
|
|
} |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
sub _write { |
23
|
6
|
|
|
6
|
|
14
|
my ($self,$dir,$seq,$data,$timestamp) = @_; |
24
|
|
|
|
|
|
|
|
25
|
6
|
100
|
|
|
|
18
|
my ($src,$dst) = $dir ? @{$self}{qw(dst src)} : @{$self}{qw(src dst)}; |
|
2
|
|
|
|
|
6
|
|
|
4
|
|
|
|
|
13
|
|
26
|
|
|
|
|
|
|
my $type = $dir ? |
27
|
|
|
|
|
|
|
$self->{ip6} ? 129 : 0 : # echo reply |
28
|
6
|
100
|
|
|
|
29
|
$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
|
|
|
|
|
37
|
$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
|
|
|
|
32
|
? 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
|
|
|
|
|
8
|
$self->_write(1,$seq,$data,$timestamp); |
60
|
|
|
|
|
|
|
} |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
1; |