Dump/Offline.pm

filter: Statementstmt 100% 9 / 9 Branchbran n/a Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 3 / 3 Podpod n/a totaltotal 100% 12 / 12 CC 1 SCAR 0.0
CC
1
Cov
100%
BEGIN
1.0
BEGIN
1.0
BEGIN
1.0
CRAP 1.0
« Dump.pm ↑ Summary Dump/Online.pm »
1 #
2 # $Id: Offline.pm,v a93481b098ec 2020/05/01 08:55:56 gomor $
3 #
4 package Net::Frame::Dump::Offline;
5 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 1 ▶use base qw(Net::Frame::Dump);
Subroutine BEGIN: called CC=1 SCAR=0.0
9 __PACKAGE__->cgBuildIndices;
10  
11 use Net::Frame::Dump qw(:consts);
12  
13 use Net::Pcap;
14 use Time::HiRes qw(gettimeofday);
15  
16 sub _openFile {
17 my $self = shift;
18  
19 my $err;
20 my $pcapd = Net::Pcap::open_offline($self->file, \$err);
21 if (!defined($pcapd)) {
22 print("[-] ".__PACKAGE__.": Net::Pcap::open_offline: ".
23 "@{[$self->file]}: $err\n");
24 return;
25 }
26 $self->_pcapd($pcapd);
27  
28 return $self->getFirstLayer;
29 }
30  
31 sub _setFilter {
32 my $self = shift;
33  
34 my $str = $self->filter;
35 if (!defined($str)) {
36 return;
37 }
38  
39 my $filter;
40 Net::Pcap::compile($self->_pcapd, \$filter, $str, $self->filterCodeOptimizer, 0);
41 if (!defined($filter)) {
42 print("[-] ".__PACKAGE__.": Net::Pcap::compile: error\n");
43 return;
44 }
45  
46 Net::Pcap::setfilter($self->_pcapd, $filter);
47 }
48  
49 sub start {
50 my $self = shift;
51  
52 $self->isRunning(1);
53  
54 if (! -f $self->file) {
55 print("[-] ".__PACKAGE__.": File does not exists: ".$self->file."\n");
56 return;
57 }
58  
59 $self->_openFile;
60 $self->_setFilter;
61  
62 return 1;
63 }
64  
65 sub stop {
66 my $self = shift;
67  
68 if (!$self->isRunning) {
69 return;
70 }
71  
72 Net::Pcap::close($self->_pcapd);
73 $self->_pcapd(undef);
74 $self->isRunning(0);
75  
76 return 1;
77 }
78  
79 1;
80  
81 __END__
« Dump.pm ↑ Summary Dump/Online.pm »