line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
7
|
|
|
7
|
|
42
|
use strict; |
|
7
|
|
|
|
|
14
|
|
|
7
|
|
|
|
|
176
|
|
2
|
7
|
|
|
7
|
|
37
|
use warnings; |
|
7
|
|
|
|
|
30
|
|
|
7
|
|
|
|
|
257
|
|
3
|
|
|
|
|
|
|
package Net::PcapWriter::ICMP_Echo; |
4
|
7
|
|
|
7
|
|
34
|
use fields qw(id src dst seq ip6 l2prefix writer); |
|
7
|
|
|
|
|
13
|
|
|
7
|
|
|
|
|
33
|
|
5
|
7
|
|
|
7
|
|
862
|
use Net::PcapWriter::IP; |
|
7
|
|
|
|
|
15
|
|
|
7
|
|
|
|
|
3831
|
|
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
sub new { |
8
|
2
|
|
|
2
|
0
|
6
|
my ($class,$writer,$src,$dst,$identifier) = @_; |
9
|
2
|
50
|
|
|
|
12
|
$identifier = 0 if ! defined $identifier; |
10
|
2
|
|
|
|
|
9
|
my $self = fields::new($class); |
11
|
2
|
|
|
|
|
6416
|
$self->{writer} = $writer; |
12
|
2
|
|
|
|
|
6
|
$self->{id} = $identifier; |
13
|
2
|
|
|
|
|
6
|
$self->{src} = $src; |
14
|
2
|
|
|
|
|
5
|
$self->{dst} = $dst; |
15
|
2
|
|
|
|
|
11
|
$self->{l2prefix} = $self->{writer}->layer2prefix($src); |
16
|
2
|
|
|
|
|
10
|
$self->{ip6} = $src =~m{:}; |
17
|
2
|
|
|
|
|
9
|
return $self; |
18
|
|
|
|
|
|
|
} |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
sub _write { |
23
|
6
|
|
|
6
|
|
17
|
my ($self,$dir,$seq,$data,$timestamp) = @_; |
24
|
|
|
|
|
|
|
|
25
|
6
|
100
|
|
|
|
16
|
my ($src,$dst) = $dir ? @{$self}{qw(dst src)} : @{$self}{qw(src dst)}; |
|
2
|
|
|
|
|
7
|
|
|
4
|
|
|
|
|
13
|
|
26
|
|
|
|
|
|
|
my $type = $dir ? |
27
|
|
|
|
|
|
|
$self->{ip6} ? 129 : 0 : # echo reply |
28
|
6
|
100
|
|
|
|
25
|
$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
|
|
|
|
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
|
29
|
my ($self,$seq,$data,$timestamp) = @_; |
53
|
4
|
|
|
|
|
12
|
$self->_write(0,$seq,$data,$timestamp); |
54
|
|
|
|
|
|
|
} |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
*echo_response = \&pong; |
57
|
|
|
|
|
|
|
sub pong { |
58
|
2
|
|
|
2
|
0
|
16
|
my ($self,$seq,$data,$timestamp) = @_; |
59
|
2
|
|
|
|
|
8
|
$self->_write(1,$seq,$data,$timestamp); |
60
|
|
|
|
|
|
|
} |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
1; |