| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
# |
|
2
|
|
|
|
|
|
|
# $Id: Dump.pm,v 1.7 2006/12/17 16:26:17 gomor Exp $ |
|
3
|
|
|
|
|
|
|
# |
|
4
|
|
|
|
|
|
|
package Net::Frame::Dump; |
|
5
|
1
|
|
|
1
|
|
6722
|
use strict; |
|
|
1
|
|
|
|
|
3
|
|
|
|
1
|
|
|
|
|
40
|
|
|
6
|
1
|
|
|
1
|
|
7
|
use warnings; |
|
|
1
|
|
|
|
|
4
|
|
|
|
1
|
|
|
|
|
173
|
|
|
7
|
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
our $VERSION = '1.00_05'; |
|
9
|
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
require Class::Gomor::Array; |
|
11
|
|
|
|
|
|
|
require Exporter; |
|
12
|
|
|
|
|
|
|
our @ISA = qw(Class::Gomor::Array Exporter); |
|
13
|
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
our %EXPORT_TAGS = ( |
|
15
|
|
|
|
|
|
|
consts => [qw( |
|
16
|
|
|
|
|
|
|
NF_DUMP_LAYER_NULL |
|
17
|
|
|
|
|
|
|
NF_DUMP_LAYER_ETH |
|
18
|
|
|
|
|
|
|
NF_DUMP_LAYER_RAW |
|
19
|
|
|
|
|
|
|
NF_DUMP_LAYER_SLL |
|
20
|
|
|
|
|
|
|
NF_DUMP_LAYER_PPP |
|
21
|
|
|
|
|
|
|
)], |
|
22
|
|
|
|
|
|
|
); |
|
23
|
|
|
|
|
|
|
our @EXPORT_OK = ( |
|
24
|
|
|
|
|
|
|
@{$EXPORT_TAGS{consts}}, |
|
25
|
|
|
|
|
|
|
); |
|
26
|
|
|
|
|
|
|
|
|
27
|
1
|
|
|
1
|
|
10
|
use constant NF_DUMP_LAYER_NULL => 0; |
|
|
1
|
|
|
|
|
12
|
|
|
|
1
|
|
|
|
|
110
|
|
|
28
|
1
|
|
|
1
|
|
8
|
use constant NF_DUMP_LAYER_ETH => 1; |
|
|
1
|
|
|
|
|
4
|
|
|
|
1
|
|
|
|
|
69
|
|
|
29
|
1
|
|
|
1
|
|
8
|
use constant NF_DUMP_LAYER_PPP => 9; |
|
|
1
|
|
|
|
|
3
|
|
|
|
1
|
|
|
|
|
64
|
|
|
30
|
1
|
|
|
1
|
|
8
|
use constant NF_DUMP_LAYER_RAW => 12; |
|
|
1
|
|
|
|
|
3
|
|
|
|
1
|
|
|
|
|
64
|
|
|
31
|
1
|
|
|
1
|
|
7
|
use constant NF_DUMP_LAYER_SLL => 113; |
|
|
1
|
|
|
|
|
4
|
|
|
|
1
|
|
|
|
|
155
|
|
|
32
|
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
our @AS = qw( |
|
34
|
|
|
|
|
|
|
file |
|
35
|
|
|
|
|
|
|
filter |
|
36
|
|
|
|
|
|
|
overwrite |
|
37
|
|
|
|
|
|
|
firstLayer |
|
38
|
|
|
|
|
|
|
isRunning |
|
39
|
|
|
|
|
|
|
keepTimestamp |
|
40
|
|
|
|
|
|
|
_framesStored |
|
41
|
|
|
|
|
|
|
_pcapd |
|
42
|
|
|
|
|
|
|
_dumper |
|
43
|
|
|
|
|
|
|
); |
|
44
|
|
|
|
|
|
|
our @AA = qw( |
|
45
|
|
|
|
|
|
|
frames |
|
46
|
|
|
|
|
|
|
); |
|
47
|
|
|
|
|
|
|
__PACKAGE__->cgBuildIndices; |
|
48
|
|
|
|
|
|
|
__PACKAGE__->cgBuildAccessorsScalar(\@AS); |
|
49
|
|
|
|
|
|
|
__PACKAGE__->cgBuildAccessorsArray(\@AA); |
|
50
|
|
|
|
|
|
|
|
|
51
|
1
|
|
|
1
|
|
9
|
use Carp; |
|
|
1
|
|
|
|
|
3
|
|
|
|
1
|
|
|
|
|
89
|
|
|
52
|
1
|
|
|
1
|
|
1334
|
use Net::Pcap; |
|
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
use Time::HiRes qw(gettimeofday); |
|
54
|
|
|
|
|
|
|
use Net::Frame::Layer qw(:consts :subs); |
|
55
|
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
sub new { |
|
57
|
|
|
|
|
|
|
my $int = getRandom32bitsInt(); |
|
58
|
|
|
|
|
|
|
shift->SUPER::new( |
|
59
|
|
|
|
|
|
|
file => "netframe-tmp-$$.$int.pcap", |
|
60
|
|
|
|
|
|
|
filter => '', |
|
61
|
|
|
|
|
|
|
overwrite => 0, |
|
62
|
|
|
|
|
|
|
isRunning => 0, |
|
63
|
|
|
|
|
|
|
frames => [], |
|
64
|
|
|
|
|
|
|
_framesStored => {}, |
|
65
|
|
|
|
|
|
|
@_, |
|
66
|
|
|
|
|
|
|
); |
|
67
|
|
|
|
|
|
|
} |
|
68
|
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
sub _dumpFlush { |
|
70
|
|
|
|
|
|
|
my $self = shift; |
|
71
|
|
|
|
|
|
|
$self->frames([]); |
|
72
|
|
|
|
|
|
|
$self->_framesStored({}); |
|
73
|
|
|
|
|
|
|
} |
|
74
|
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
sub _dumpStore { |
|
76
|
|
|
|
|
|
|
my $self = shift; |
|
77
|
|
|
|
|
|
|
my ($oSimple) = @_; |
|
78
|
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
$self->_dumpFramesStored($oSimple); |
|
80
|
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
my @frames = $self->frames; |
|
82
|
|
|
|
|
|
|
push @frames, $oSimple; |
|
83
|
|
|
|
|
|
|
$self->frames(\@frames); |
|
84
|
|
|
|
|
|
|
} |
|
85
|
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
sub _getTimestamp { |
|
87
|
|
|
|
|
|
|
my $self = shift; |
|
88
|
|
|
|
|
|
|
my ($hdr) = @_; |
|
89
|
|
|
|
|
|
|
$hdr->{tv_sec}.'.'.sprintf("%06d", $hdr->{tv_usec}); |
|
90
|
|
|
|
|
|
|
} |
|
91
|
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
sub _setTimestamp { |
|
93
|
|
|
|
|
|
|
my $self = shift; |
|
94
|
|
|
|
|
|
|
my @time = Time::HiRes::gettimeofday(); |
|
95
|
|
|
|
|
|
|
$time[0].'.'.sprintf("%06d", $time[1]); |
|
96
|
|
|
|
|
|
|
} |
|
97
|
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
my $mapLinks = { |
|
99
|
|
|
|
|
|
|
NF_DUMP_LAYER_NULL() => 'NULL', |
|
100
|
|
|
|
|
|
|
NF_DUMP_LAYER_ETH() => 'ETH', |
|
101
|
|
|
|
|
|
|
NF_DUMP_LAYER_RAW() => 'RAW', |
|
102
|
|
|
|
|
|
|
NF_DUMP_LAYER_SLL() => 'SLL', |
|
103
|
|
|
|
|
|
|
NF_DUMP_LAYER_PPP() => 'PPP', |
|
104
|
|
|
|
|
|
|
}; |
|
105
|
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
sub _dumpPcapNext { |
|
107
|
|
|
|
|
|
|
my $self = shift; |
|
108
|
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
my %hdr; |
|
110
|
|
|
|
|
|
|
if (my $raw = Net::Pcap::next($self->_pcapd, \%hdr)) { |
|
111
|
|
|
|
|
|
|
my $ts = $self->keepTimestamp ? $self->_getTimestamp(\%hdr) |
|
112
|
|
|
|
|
|
|
: $self->_setTimestamp; |
|
113
|
|
|
|
|
|
|
return { |
|
114
|
|
|
|
|
|
|
firstLayer => $mapLinks->{$self->firstLayer} || NF_LAYER_UNKNOWN, |
|
115
|
|
|
|
|
|
|
timestamp => $ts, |
|
116
|
|
|
|
|
|
|
raw => $raw, |
|
117
|
|
|
|
|
|
|
}; |
|
118
|
|
|
|
|
|
|
} |
|
119
|
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
undef; |
|
121
|
|
|
|
|
|
|
} |
|
122
|
|
|
|
|
|
|
|
|
123
|
|
|
|
|
|
|
sub _dumpGetFramesFor { |
|
124
|
|
|
|
|
|
|
my $self = shift; |
|
125
|
|
|
|
|
|
|
my ($oSimple) = @_; |
|
126
|
|
|
|
|
|
|
|
|
127
|
|
|
|
|
|
|
my $results; |
|
128
|
|
|
|
|
|
|
my $key = $oSimple->getKeyReverse; |
|
129
|
|
|
|
|
|
|
push @$results, @{$self->_framesStored->{$key}} |
|
130
|
|
|
|
|
|
|
if exists $self->_framesStored->{$key}; |
|
131
|
|
|
|
|
|
|
|
|
132
|
|
|
|
|
|
|
# Add also ICMPv4 |
|
133
|
|
|
|
|
|
|
if (exists $self->_framesStored->{ICMPv4}) { |
|
134
|
|
|
|
|
|
|
push @$results, @{$self->_framesStored->{ICMPv4}}; |
|
135
|
|
|
|
|
|
|
} |
|
136
|
|
|
|
|
|
|
|
|
137
|
|
|
|
|
|
|
$results ? @$results : (); |
|
138
|
|
|
|
|
|
|
} |
|
139
|
|
|
|
|
|
|
|
|
140
|
|
|
|
|
|
|
sub _dumpFramesStored { |
|
141
|
|
|
|
|
|
|
my $self = shift; |
|
142
|
|
|
|
|
|
|
my ($oSimple) = @_; |
|
143
|
|
|
|
|
|
|
|
|
144
|
|
|
|
|
|
|
# If parameter, we store it |
|
145
|
|
|
|
|
|
|
if ($oSimple) { |
|
146
|
|
|
|
|
|
|
my $key = $oSimple->getKey; |
|
147
|
|
|
|
|
|
|
push @{$self->_framesStored->{$key}}, $oSimple; |
|
148
|
|
|
|
|
|
|
|
|
149
|
|
|
|
|
|
|
# If it is ICMPv4, we store a second time |
|
150
|
|
|
|
|
|
|
if (exists $oSimple->ref->{ICMPv4}) { |
|
151
|
|
|
|
|
|
|
push @{$self->_framesStored->{$oSimple->ref->{ICMPv4}->getKey}}, |
|
152
|
|
|
|
|
|
|
$oSimple; |
|
153
|
|
|
|
|
|
|
} |
|
154
|
|
|
|
|
|
|
} |
|
155
|
|
|
|
|
|
|
|
|
156
|
|
|
|
|
|
|
# We return the hash ref |
|
157
|
|
|
|
|
|
|
$self->_framesStored; |
|
158
|
|
|
|
|
|
|
} |
|
159
|
|
|
|
|
|
|
|
|
160
|
|
|
|
|
|
|
1; |
|
161
|
|
|
|
|
|
|
|
|
162
|
|
|
|
|
|
|
__END__ |