Packet/DescL3.pm

filter: Statementstmt 86.6% 13 / 15 Branchbran n/a Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 5 / 5 Podpod n/a totaltotal 90.0% 18 / 20 CC 1 SCAR 0.6
CC
1
Cov
87%
BEGIN
1.3
BEGIN
1.0
BEGIN
1.0
CRAP 1.1
« Packet/STP.pm ↑ Summary Packet/Frame.pm »
1 #
2 # $Id: DescL3.pm 2002 2015-02-15 16:50:35Z gomor $
3 #
4 package Net::Packet::DescL3;
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 1 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 require Net::Packet::Desc;
10 our @ISA = qw(Net::Packet::Desc);
11  
12 our @AS = qw(
13 _ethHeader
14 );
15 __PACKAGE__->cgBuildIndices;
16 __PACKAGE__->cgBuildAccessorsScalar(\@AS);
17  
18 1 ▶no strict 'vars';
Subroutine BEGIN: called CC=1 SCAR=0.0
19  
20 0 ▶use Net::Packet::Utils qw(getIpMac);
Subroutine BEGIN: called CC=1 SCAR=2.6
21  
22 BEGIN {
23 my $osname = {
24 cygwin => [ \&_newWin32, \&_sendWin32 ],
25 MSWin32 => [ \&_newWin32, \&_sendWin32 ],
26 };
27  
28 *new = $osname->{$^O}->[0] || \&_newOther;
29 *send = $osname->{$^O}->[1] || \&_sendOther;
30 }
31  
32 sub _newWin32 {
33 my $self = shift->SUPER::new(@_);
34  
35 confess("@{[(caller(0))[3]]}: you must pass `target' parameter\n")
36 unless $self->[$__target];
37  
38 require Net::Write::Layer2;
39 my $nwrite = Net::Write::Layer2->new(
40 dev => $self->[$__dev],
41 );
42 $nwrite->open;
43  
44 $self->[$___io] = $nwrite;
45  
46 $self->[$__targetMac] = getIpMac($self->[$__target]);
47 $self->_buildEthHeaderWin32;
48  
49 $self->cgDebugPrint(1, "target: [@{[$self->target]}]")
50 if $self->target;
51 $self->cgDebugPrint(1, "targetMac: [@{[$self->targetMac]}]")
52 if $self->targetMac;
53  
54 $self;
55 }
56  
57 # XXX: only support for IPv4 as now
58 # XXX: should add an attribute to tell one wants autocreation of L2, even
59 # under Unix systems (useful with IPv6)
60 sub _buildEthHeaderWin32 {
61 my $self = shift;
62 use Net::Packet::Env qw($Env);
63 $Env->doIPv4Checksum(1);
64 require Net::Packet::ETH;
65 use Net::Packet::Consts qw(:eth);
66 my $eth = Net::Packet::ETH->new(
67 src => $Env->mac,
68 dst => $self->[$__targetMac],
69 type => NP_ETH_TYPE_IPv4,
70 );
71 $eth->pack;
72 $self->[$___ethHeader] = $eth;
73 }
74  
75 sub _newOther {
76 my $self = shift->SUPER::new(@_);
77  
78 confess("@{[(caller(0))[3]]}: you must pass `target' parameter\n")
79 unless $self->[$__target];
80  
81 require Net::Write::Layer3;
82 my $nwrite = Net::Write::Layer3->new(
83 dev => $self->[$__dev],
84 dst => $self->[$__target],
85 );
86 $nwrite->open;
87  
88 $self->[$___io] = $nwrite;
89  
90 $self;
91 }
92  
93 sub _sendWin32 {
94 my $self = shift;
95 my ($raw) = @_;
96 $self->_io->send($self->[$___ethHeader]->raw.$raw);
97 }
98  
99 sub _sendOther { shift->SUPER::send(@_) }
100  
101 1;
102  
103 __END__
« Packet/STP.pm ↑ Summary Packet/Frame.pm »