blib/lib/Net/Frame/Layer/IPv6/HopByHop.pm

filter: Statementstmt 51.9% 41 / 79 Branchbran 25.0% 4 / 16 Conditioncond 16.6% 1 / 6 MC/DCmcdc 0.0% 0 / 4 Subroutinesub 60.0% 9 / 15 Podpod 100% 8 / 8 totaltotal 49.2% 63 / 128 CC 15 SCAR 18.2
CC
15
Cov
46%
_unpackOptions
12.0
computeLengths
12.0
encapsulate
12.0
CRAP 6.2
« blib/lib/Net/Frame/Layer/IPv6/Destination.pm ↑ Summary blib/lib/Net/Frame/Layer/IPv6/Option.pm »
1 #
2 # $Id: HopByHop.pm 47 2015-01-20 18:20:28Z gomor $
3 #
4 package Net::Frame::Layer::IPv6::HopByHop;
5 3 ▶use strict; use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 3 our $VERSION = '1.07';
8  
9 3 ▶use Net::Frame::Layer qw(:consts :subs);
Subroutine BEGIN: called CC=1 SCAR=0.0
10 3 ▶use Exporter;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 3 our @ISA = qw(Net::Frame::Layer Exporter);
12  
13 3 our @AS = qw(
14 nextHeader
15 hdrExtLen
16 );
17 3 our @AA = qw(
18 options
19 );
20 3 __PACKAGE__->cgBuildIndices;
21 3 __PACKAGE__->cgBuildAccessorsScalar(\@AS);
22 3 __PACKAGE__->cgBuildAccessorsArray(\@AA);
23  
24 3 ▶use Net::Frame::Layer::IPv6 qw(:consts);
Subroutine BEGIN: called CC=1 SCAR=0.0
25 3 ▶use Net::Frame::Layer::IPv6::Option;
Subroutine BEGIN: called CC=1 SCAR=0.0
26  
27 sub new {
28 shift->SUPER::new(
29 1 ▶ nextHeader => NF_IPv6_PROTOCOL_TCP,
Subroutine new: called CC=1 SCAR=0.0
Pod documented
30 hdrExtLen => 0,
31 options => [],
32 @_,
33 );
34 }
35  
36 sub getOptionsLength {
37 0 ▶ my $self = shift;
Subroutine getOptionsLength: not called CC=2 SCAR=17.9
Pod documented
38 0 my $len = 0;
39 0 $len += $_->getLength for $self->options;
40 0 return $len;
41 }
42  
43 sub getLength {
44 0 ▶ my $self = shift;
Subroutine getLength: not called CC=1 SCAR=6.9
Pod documented
45 0 return 2 + $self->getOptionsLength;
46 }
47  
48 sub pack {
49 1 ▶ my $self = shift;
Subroutine pack: called CC=3 SCAR=11.7
Pod documented
50  
51 1 ▶ my $raw = $self->SUPER::pack('CC',
Branch: 1 branch
BranchTrueFalseTotal
my $raw = $self->SUPER::pack("CC", $self->nextHeader, $self->hdrExtLen) or return 0 1 1
52 $self->nextHeader, $self->hdrExtLen
53 ) or return;
54  
55 1 for ($self->options) {
56 0 $raw .= $_->pack;
57 }
58  
59 1 return $self->raw($raw);
60 }
61  
62 sub _unpackOptions {
63 0 ▶ my $self = shift;
Subroutine _unpackOptions: not called CC=3 SCAR=24.8
64 0 my ($payload) = @_;
65  
66 0 my @options = ();
67 0 ▶ while (defined($payload) && length($payload)) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $payload and length $payload) 0 0 0
Condition0%0/3
defined $payload and length $payload
!ll&&!rl&&r
000
MC/DC0%0/2
defined $payload and length $payload
defined $payload length $payload
Truth table0%0/3
A and B
A= defined $payloadB= length $payload
ABresult
0X0
100
111
68 0 my $opt = Net::Frame::Layer::IPv6::Option->new(raw => $payload)->unpack;
69 0 push @options, $opt;
70 0 $payload = $opt->payload;
71 0 $opt->payload(undef);
72 }
73 0 $self->options(\@options);
74  
75 0 return $payload;
76 }
77  
78 sub unpack {
79 1 ▶ my $self = shift;
Subroutine unpack: called CC=5 SCAR=17.4
Pod documented
80  
81 1 ▶ my ($nextHeader, $hdrExtLen, $payload) =
Branch: 1 branch
BranchTrueFalseTotal
() = $self->SUPER::unpack("CC a*", $self->raw) or return 0 1 1
82 $self->SUPER::unpack('CC a*', $self->raw)
83 or return;
84  
85 1 $self->nextHeader($nextHeader);
86 1 $self->hdrExtLen($hdrExtLen);
87  
88 1 my $options = '';
89 1 my $optionsLen = $hdrExtLen*8 + 6; # 8 - 2 bytes offset
90 1 ▶ ($options, $payload) = $self->SUPER::unpack("a$optionsLen a*", $payload)
Branch: 1 branch
BranchTrueFalseTotal
($options, $payload) = $self->SUPER::unpack("a$optionsLen a*", $payload) or return 0 1 1
91 or return;
92  
93 1 ▶ if (defined($options) && length($options)) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $options and length $options) 0 1 1
Condition33%1/3
defined $options and length $options
!ll&&!rl&&r
010
MC/DC0%0/2
defined $options and length $options
defined $options length $options
Truth table33%1/3
A and B
A= defined $optionsB= length $options
ABresult
0X0
100
111
94 0 $self->_unpackOptions($options);
95 }
96  
97 1 $self->payload($payload);
98  
99 1 return $self;
100 }
101  
102 sub computeLengths {
103 0 ▶ my $self = shift;
Subroutine computeLengths: not called CC=3 SCAR=24.8
Pod documented
104  
105 0 my $hdrExtLen = int($self->getLength/8) - 1;
106 0 ▶ if ($hdrExtLen < 0) {
Branch: 1 branch
BranchTrueFalseTotal
if ($hdrExtLen < 0) 0 0 0
107 0 $hdrExtLen = 0;
108 }
109 0 $self->hdrExtLen($hdrExtLen);
110  
111 0 for my $option ($self->options) {
112 0 $option->computeLengths;
113 }
114  
115 0 return 1;
116 }
117  
118 sub encapsulate {
119 0 ▶ my $self = shift;
Subroutine encapsulate: not called CC=3 SCAR=24.8
Pod documented
120  
121 0 ▶ return $self->nextLayer if $self->nextLayer;
Branch: 1 branch
BranchTrueFalseTotal
if $self->nextLayer 0 0 0
122  
123 0 ▶ if ($self->payload) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->payload) 0 0 0
124 0 my $next = $self->nextHeader;
125 0 return Net::Frame::Layer::IPv6->new(nextHeader => $next)->encapsulate;
126 }
127  
128 0 return NF_LAYER_NONE;
129 }
130  
131 sub print {
132 0 ▶ my $self = shift;
Subroutine print: not called CC=2 SCAR=17.9
Pod documented
133  
134 0 my $l = $self->layer;
135 0 my $buf = sprintf
136 "$l: nextHeader:0x%02x hdrExtLen:%d",
137 $self->nextHeader, $self->hdrExtLen;
138  
139 0 for ($self->options) {
140 0 $buf .= "\n" . $_->print;
141 }
142  
143 0 return $buf;
144 }
145  
146 3 1;
147  
148 __END__
« blib/lib/Net/Frame/Layer/IPv6/Destination.pm ↑ Summary blib/lib/Net/Frame/Layer/IPv6/Option.pm »