Write/Layer2.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
« Write.pm ↑ Summary
1 #
2 # $Id: Layer2.pm 2005 2015-01-23 06:56:13Z gomor $
3 #
4 package Net::Write::Layer2;
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::Write::Layer);
Subroutine BEGIN: called CC=1 SCAR=0.0
9 __PACKAGE__->cgBuildIndices;
10  
11 no strict 'vars';
12  
13 use Net::Pcap;
14  
15 sub new {
16 my $self = shift->SUPER::new(
17 @_,
18 ) or return;
19  
20 if (! $self->[$__dev]) {
21 print STDERR "[-] @{[(caller(0))[3]]}: you must pass `dev' parameter\n";
22 return;
23 }
24  
25 return $self;
26 }
27  
28 sub open {
29 my $self = shift;
30  
31 my $err;
32 my $pd = Net::Pcap::open_live(
33 $self->[$__dev],
34 0,
35 0,
36 1000,
37 \$err,
38 );
39 unless ($pd) {
40 print STDERR "[-] @{[(caller(0))[3]]}: Net::Pcap::open_live: ".
41 "@{[$self->dev]}: $err\n";
42 return;
43 }
44  
45 $self->[$___io] = $pd;
46  
47 return 1;
48 }
49  
50 sub send {
51 my $self = shift;
52 my ($raw) = @_;
53  
54 while (1) {
55 if (Net::Pcap::sendpacket($self->[$___io], $raw) < 0) {
56 if ($!{ENOBUFS}) {
57 $self->cgDebugPrint(2, "ENOBUFS, sleeping for 1 second");
58 sleep 1;
59 next;
60 }
61 elsif ($!{EHOSTDOWN}) {
62 $self->cgDebugPrint(2, "host is down");
63 last;
64 }
65 print STDERR "[!] @{[(caller(0))[3]]}: ".
66 Net::Pcap::geterr($self->[$___io])."\n";
67 return;
68 }
69 last;
70 }
71  
72 return 1;
73 }
74  
75 sub close {
76 my $self = shift;
77 if ($self->[$___io]) {
78 Net::Pcap::close($self->[$___io]);
79 $self->[$___io] = undef;
80 }
81 }
82  
83 1;
84  
85 __END__
« Write.pm ↑ Summary