Frame/Layer/ARP.pm

filter: Statementstmt 86.3% 82 / 95 Branchbran 31.8% 7 / 22 Conditioncond 0.0% 0 / 9 MC/DCmcdc 0.0% 0 / 4 Subroutinesub 82.6% 19 / 23 Podpod 100% 9 / 9 totaltotal 72.2% 117 / 162 CC 15 SCAR 18.7
CC
15
Cov
71%
match
30.0
getLength
6.0
unpack
5.7
CRAP 6.5
« Frame/Layer/RAW.pm ↑ Summary Frame/Layer.pm »
1 #
2 # $Id: ARP.pm,v ce68fbcc7f6d 2019/05/23 05:58:40 gomor $
3 #
4 package Net::Frame::Layer::ARP;
5 3 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 3 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 3 ▶use Net::Frame::Layer qw(:consts :subs);
Subroutine BEGIN: called CC=1 SCAR=0.0
9 3 require Exporter;
10 3 our @ISA = qw(Net::Frame::Layer Exporter);
11  
12 3 our %EXPORT_TAGS = (
13 consts => [qw(
14 NF_ARP_HDR_LEN
15 NF_ARP_HTYPE_ETH
16 NF_ARP_PTYPE_IPv4
17 NF_ARP_PTYPE_IPv6
18 NF_ARP_HSIZE_ETH
19 NF_ARP_PSIZE_IPv4
20 NF_ARP_PSIZE_IPv6
21 NF_ARP_OPCODE_REQUEST
22 NF_ARP_OPCODE_REPLY
23 NF_ARP_ADDR_BROADCAST
24 )],
25 );
26 our @EXPORT_OK = (
27 3 @{$EXPORT_TAGS{consts}},
28 );
29  
30 3 ▶use constant NF_ARP_HDR_LEN => 28;
Subroutine BEGIN: called CC=1 SCAR=0.0
31 3 ▶use constant NF_ARP_HTYPE_ETH => 0x0001;
Subroutine BEGIN: called CC=1 SCAR=0.0
32 3 ▶use constant NF_ARP_PTYPE_IPv4 => 0x0800;
Subroutine BEGIN: called CC=1 SCAR=0.0
33 3 ▶use constant NF_ARP_PTYPE_IPv6 => 0x86dd;
Subroutine BEGIN: called CC=1 SCAR=0.0
34 3 ▶use constant NF_ARP_HSIZE_ETH => 0x06;
Subroutine BEGIN: called CC=1 SCAR=0.0
35 3 ▶use constant NF_ARP_PSIZE_IPv4 => 0x04;
Subroutine BEGIN: called CC=1 SCAR=0.0
36 3 ▶use constant NF_ARP_PSIZE_IPv6 => 0x16;
Subroutine BEGIN: called CC=1 SCAR=0.0
37 3 ▶use constant NF_ARP_OPCODE_REQUEST => 0x0001;
Subroutine BEGIN: called CC=1 SCAR=0.0
38 3 ▶use constant NF_ARP_OPCODE_REPLY => 0x0002;
Subroutine BEGIN: called CC=1 SCAR=0.0
39 3 ▶use constant NF_ARP_ADDR_BROADCAST => '00:00:00:00:00:00';
Subroutine BEGIN: called CC=1 SCAR=0.0
40  
41 3 our @AS = qw(
42 hType
43 pType
44 hSize
45 pSize
46 opCode
47 src
48 srcIp
49 dst
50 dstIp
51 );
52 3 __PACKAGE__->cgBuildIndices;
53 3 __PACKAGE__->cgBuildAccessorsScalar(\@AS);
54  
55 3 ▶no strict 'vars';
Subroutine BEGIN: called CC=1 SCAR=0.0
56  
57 1 ▶sub new {
Subroutine new: called CC=3 SCAR=11.4
Pod documented
58 1 my $self = shift->SUPER::new(
59 hType => NF_ARP_HTYPE_ETH,
60 pType => NF_ARP_PTYPE_IPv4,
61 hSize => NF_ARP_HSIZE_ETH,
62 pSize => NF_ARP_PSIZE_IPv4,
63 opCode => NF_ARP_OPCODE_REQUEST,
64 src => '00:00:00:00:00:00',
65 dst => NF_ARP_ADDR_BROADCAST,
66 srcIp => '127.0.0.1',
67 dstIp => '127.0.0.1',
68 @_,
69 );
70  
71 1 ▶ $self->[$__src] = lc($self->[$__src]) if $self->[$__src];
Branch: 1 branch
BranchTrueFalseTotal
if $self->[$__src] 1 0 1
72 1 ▶ $self->[$__dst] = lc($self->[$__dst]) if $self->[$__dst];
Branch: 1 branch
BranchTrueFalseTotal
if $self->[$__dst] 1 0 1
73  
74 1 return $self;
75 }
76  
77 0 ▶sub getLength {
Subroutine getLength: not called CC=2 SCAR=17.9
Pod documented
78 0 my $self = shift;
79 0 my $len = NF_ARP_HDR_LEN;
80 0 ▶ $len += 24 if $self->[$__pType] == NF_ARP_PTYPE_IPv6;
Branch: 1 branch
BranchTrueFalseTotal
if $self->[$__pType] == 34525 0 0 0
81 0 return $len;
82 }
83  
84 1 ▶sub pack {
Subroutine pack: called CC=4 SCAR=15.9
Pod documented
85 1 my $self = shift;
86  
87 1 (my $srcMac = $self->[$__src]) =~ s/://g;
88 1 (my $dstMac = $self->[$__dst]) =~ s/://g;
89  
90 # IPv4 packing
91 1 ▶ if ($self->[$__pType] == NF_ARP_PTYPE_IPv4) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->[$__pType] == 2048) { } 1 0 1
92 1 ▶ $self->[$__raw] = $self->SUPER::pack('nnCCnH12a4H12a4',
Branch: 1 branch
BranchTrueFalseTotal
$self->[$__raw] = $self->SUPER::pack("nnCCnH12a4H12a4", $self->[$__hType], $self->[$__pType], $self->[$__hSize], $self->[$__pSize], $self->[$__opCode], $srcMac, inetAton($self->[$__srcIp]), $dstMac, inetAton($self->[$__dstIp])) or return 1 0 1
93 $self->[$__hType],
94 $self->[$__pType],
95 $self->[$__hSize],
96 $self->[$__pSize],
97 $self->[$__opCode],
98 $srcMac,
99 inetAton($self->[$__srcIp]),
100 $dstMac,
101 inetAton($self->[$__dstIp]),
102 ) or return;
103 }
104 # IPv6 packing
105 else {
106 0 ▶ $self->[$__raw] = $self->SUPER::pack('nnCCnH12a*H12a*',
Branch: 1 branch
BranchTrueFalseTotal
$self->[$__raw] = $self->SUPER::pack("nnCCnH12a*H12a*", $self->[$__hType], $self->[$__pType], $self->[$__hSize], $self->[$__pSize], $self->[$__opCode], $srcMac, inet6Aton($self->[$__srcIp]), $dstMac, inet6Aton($self->[$__dstIp])) or return 0 0 0
107 $self->[$__hType],
108 $self->[$__pType],
109 $self->[$__hSize],
110 $self->[$__pSize],
111 $self->[$__opCode],
112 $srcMac,
113 inet6Aton($self->[$__srcIp]),
114 $dstMac,
115 inet6Aton($self->[$__dstIp]),
116 ) or return;
117 }
118  
119 1 return $self->[$__raw];
120 }
121  
122 1 ▶sub unpack {
Subroutine unpack: called CC=5 SCAR=17.3
Pod documented
123 1 my $self = shift;
124  
125 1 ▶ my ($hType, $pType, $tail) = $self->SUPER::unpack('nn a*',
Branch: 1 branch
BranchTrueFalseTotal
() = $self->SUPER::unpack("nn a*", $self->[$__raw]) or return 1 0 1
126 $self->[$__raw])
127 or return;
128  
129 1 my ($hSize, $pSize, $opCode, $srcMac, $srcIp, $dstMac, $dstIp,
130 $payload);
131  
132 # IPv4 unpacking
133 1 ▶ if ($pType == NF_ARP_PTYPE_IPv4) {
Branch: 1 branch
BranchTrueFalseTotal
if ($pType == 2048) { } 1 0 1
134 1 ▶ ($hSize, $pSize, $opCode, $srcMac, $srcIp, $dstMac, $dstIp,
Branch: 1 branch
BranchTrueFalseTotal
() = $self->SUPER::unpack("CCnH12a4H12a4 a*", $tail) or return 1 0 1
135 $payload) = $self->SUPER::unpack('CCnH12a4H12a4 a*', $tail)
136 or return;
137 1 $self->[$__srcIp] = inetNtoa($srcIp);
138 1 $self->[$__dstIp] = inetNtoa($dstIp);
139 }
140 # IPv6 unpacking
141 else {
142 0 ▶ ($hSize, $pSize, $opCode, $srcMac, $srcIp, $dstMac, $dstIp,
Branch: 1 branch
BranchTrueFalseTotal
() = $self->SUPER::unpack("CCnH12a16H12a16 a*", $tail) or return 0 0 0
143 $payload) = $self->SUPER::unpack('CCnH12a16H12a16 a*', $tail)
144 or return;
145 0 $self->[$__srcIp] = inet6Ntoa($srcIp);
146 0 $self->[$__dstIp] = inet6Ntoa($dstIp);
147 }
148  
149 1 $self->[$__hType] = $hType;
150 1 $self->[$__pType] = $pType;
151 1 $self->[$__hSize] = $hSize;
152 1 $self->[$__pSize] = $pSize;
153 1 $self->[$__opCode] = $opCode;
154 1 $self->[$__src] = convertMac($srcMac);
155 1 $self->[$__dst] = convertMac($dstMac);
156  
157 1 $self->[$__payload] = $payload;
158  
159 1 return $self;
160 }
161  
162 0 ▶sub getKey { shift->layer }
Subroutine getKey: not called CC=1 SCAR=6.9
Pod documented
163 0 ▶sub getKeyReverse { shift->layer }
Subroutine getKeyReverse: not called CC=1 SCAR=6.9
Pod documented
164  
165 0 ▶sub match {
Subroutine match: not called CC=5 SCAR=34.0
Pod documented
166 0 my $self = shift;
167 0 my ($with) = @_;
168 0 ▶ ($self->[$__opCode] == NF_ARP_OPCODE_REQUEST)
Branch: 1 branch
BranchTrueFalseTotal
$self->[$__opCode] == 1 and $with->[$__opCode] == 2 and $with->[$__dst] eq $self->[$__src] and $with->[$__srcIp] eq $self->[$__dstIp] and $with->[$__dstIp] eq $self->[$__srcIp] 0 0 0
Condition0%0/9
$self->[$__opCode] == 1 and $with->[$__opCode] == 2 and $with->[$__dst] eq $self->[$__src] and $with->[$__srcIp] eq $self->[$__dstIp]
!ll&&!rl&&r
000
$self->[$__opCode] == 1 and $with->[$__opCode] == 2 and $with->[$__dst] eq $self->[$__src]
!ll&&!rl&&r
000
$self->[$__opCode] == 1 and $with->[$__opCode] == 2
!ll&&!rl&&r
000
MC/DC0%0/4
$self->[$__opCode] == 1 and $with->[$__opCode] == 2 and $with->[$__dst] eq $self->[$__src] and $with->[$__srcIp] eq $self->[$__dstIp]
$self->[$__opCode] == 1 $with->[$__opCode] == 2 $with->[$__dst] eq $self->[$__src] $with->[$__srcIp] eq $self->[$__dstIp]
Truth table0%0/5
A and B and C and D
A= $self->[$__opCode] == 1B= $with->[$__opCode] == 2C= $with->[$__dst] eq $self->[$__src]D= $with->[$__srcIp] eq $self->[$__dstIp]
ABCDresult
0XXX0
10XX0
110X0
11100
11111
169 && ($with->[$__opCode] == NF_ARP_OPCODE_REPLY)
170 && ($with->[$__dst] eq $self->[$__src])
171 && ($with->[$__srcIp] eq $self->[$__dstIp])
172 && ($with->[$__dstIp] eq $self->[$__srcIp]);
173 }
174  
175 1 ▶sub encapsulate {
Subroutine encapsulate: called CC=1 SCAR=0.0
Pod documented
176 1 my $self = shift;
177 1 return $self->[$__nextLayer];
178 }
179  
180 1 ▶sub print {
Subroutine print: called CC=1 SCAR=0.0
Pod documented
181 1 my $self = shift;
182  
183 1 my $l = $self->layer;
184 1 sprintf
185 "$l: hType:0x%04x pType:0x%04x hSize:0x%02x pSize:0x%02x".
186 " opCode:0x%04x\n".
187 "$l: src:%s srcIp:%s\n".
188 "$l: dst:%s dstIp:%s",
189 $self->[$__hType], $self->[$__pType], $self->[$__hSize],
190 $self->[$__pSize], $self->[$__opCode], $self->[$__src],
191 $self->[$__srcIp], $self->[$__dst], $self->[$__dstIp];
192 }
193  
194 3 1;
195  
196 __END__
« Frame/Layer/RAW.pm ↑ Summary Frame/Layer.pm »