line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Data::ParseBinary::Data::Netflow; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
642
|
use strict; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
29
|
|
4
|
1
|
|
|
1
|
|
5
|
use warnings; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
21
|
|
5
|
1
|
|
|
1
|
|
5
|
use Data::ParseBinary; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
661
|
|
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
our $netflow_v5_parser = Struct("nfv5_header", |
8
|
|
|
|
|
|
|
Const(UBInt16("version"), 5), |
9
|
|
|
|
|
|
|
UBInt16("count"), |
10
|
|
|
|
|
|
|
UBInt32("sys_uptime"), |
11
|
|
|
|
|
|
|
UBInt32("unix_secs"), |
12
|
|
|
|
|
|
|
UBInt32("unix_nsecs"), |
13
|
|
|
|
|
|
|
UBInt32("flow_seq"), |
14
|
|
|
|
|
|
|
UBInt8("engine_type"), |
15
|
|
|
|
|
|
|
UBInt8("engine_id"), |
16
|
|
|
|
|
|
|
Padding(2), |
17
|
|
|
|
|
|
|
Array(sub { $_->ctx->{count} }, |
18
|
|
|
|
|
|
|
Struct("nfv5_record", |
19
|
|
|
|
|
|
|
Data::ParseBinary::lib::DataNetflow::IPAddr->create( |
20
|
|
|
|
|
|
|
UBInt32("src_addr") |
21
|
|
|
|
|
|
|
), |
22
|
|
|
|
|
|
|
Data::ParseBinary::lib::DataNetflow::IPAddr->create( |
23
|
|
|
|
|
|
|
UBInt32("dst_addr") |
24
|
|
|
|
|
|
|
), |
25
|
|
|
|
|
|
|
Data::ParseBinary::lib::DataNetflow::IPAddr->create( |
26
|
|
|
|
|
|
|
UBInt32("next_hop") |
27
|
|
|
|
|
|
|
), |
28
|
|
|
|
|
|
|
UBInt16("i_ifx"), |
29
|
|
|
|
|
|
|
UBInt16("o_ifx"), |
30
|
|
|
|
|
|
|
UBInt32("packets"), |
31
|
|
|
|
|
|
|
UBInt32("octets"), |
32
|
|
|
|
|
|
|
UBInt32("first"), |
33
|
|
|
|
|
|
|
UBInt32("last"), |
34
|
|
|
|
|
|
|
UBInt16("s_port"), |
35
|
|
|
|
|
|
|
UBInt16("d_port"), |
36
|
|
|
|
|
|
|
Padding(1), |
37
|
|
|
|
|
|
|
UBInt8("flags"), |
38
|
|
|
|
|
|
|
UBInt8("prot"), |
39
|
|
|
|
|
|
|
UBInt8("tos"), |
40
|
|
|
|
|
|
|
UBInt16("src_as"), |
41
|
|
|
|
|
|
|
UBInt16("dst_as"), |
42
|
|
|
|
|
|
|
UBInt8("src_mask"), |
43
|
|
|
|
|
|
|
UBInt8("dst_mask"), |
44
|
|
|
|
|
|
|
UBInt16("unused2")), |
45
|
|
|
|
|
|
|
), |
46
|
|
|
|
|
|
|
); |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
require Exporter; |
49
|
|
|
|
|
|
|
our @ISA = qw(Exporter); |
50
|
|
|
|
|
|
|
our @EXPORT = qw($netflow_v5_parser); |
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
package Data::ParseBinary::lib::DataNetflow::IPAddr; |
53
|
|
|
|
|
|
|
|
54
|
1
|
|
|
1
|
|
853
|
use Socket qw(inet_ntoa inet_aton); |
|
1
|
|
|
|
|
3907
|
|
|
1
|
|
|
|
|
322
|
|
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
our @ISA; |
57
|
1
|
|
|
1
|
|
157
|
BEGIN { @ISA = qw{Data::ParseBinary::Adapter}; } |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
sub _decode { |
60
|
270
|
|
|
270
|
|
375
|
my ($self, $value) = @_; |
61
|
270
|
|
|
|
|
1643
|
return inet_ntoa(pack('N',$value)); |
62
|
|
|
|
|
|
|
} |
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
sub _encode { |
65
|
90
|
|
|
90
|
|
115
|
my ($self, $value) = @_; |
66
|
90
|
|
|
|
|
484
|
return sprintf("%d", unpack('N',inet_aton($value))); |
67
|
|
|
|
|
|
|
} |
68
|
|
|
|
|
|
|
1; |
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
=head1 NAME |
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
Data::ParseBinary::Data::Netflow - Parsing Netflow PDU binary structures |
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
=head1 SYNOPSIS |
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
use Data::ParseBinary::Data::Netflow qw($netflow_v5_parser); |
77
|
|
|
|
|
|
|
$data = $netflow_v5_parser->parse(CreateStreamReader(File => $fh)); |
78
|
|
|
|
|
|
|
# If file contain multiple flows, parse them till EOF |
79
|
|
|
|
|
|
|
while () { |
80
|
|
|
|
|
|
|
last if eof($fh); |
81
|
|
|
|
|
|
|
$data = $netflow_v5_parser->parse(CreateStreamReader(File => $fh)); |
82
|
|
|
|
|
|
|
} |
83
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
=head1 CAVEAT |
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
As for this moment version 5 format is supported only. |
87
|
|
|
|
|
|
|
Read files only in network byte order (BE). |
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
This is a part of the Data::ParseBinary package, and is just one ready-made parser. |
90
|
|
|
|
|
|
|
please go to the main page for additional usage info. |
91
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
=cut |