| 1 | # | ||||||||||||||||||||||||||||
| 2 | # $Id: Destination.pm 47 2015-01-20 18:20:28Z gomor $ | ||||||||||||||||||||||||||||
| 3 | # | ||||||||||||||||||||||||||||
| 4 | package Net::Frame::Layer::IPv6::Destination; | ||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 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
Condition0%0/3
defined $payload and length $payload
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
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 91 | or return; | ||||||||||||||||||||||||||||
| 92 | |||||||||||||||||||||||||||||
| 93 | 1 | ▶ | if (defined($options) && length($options)) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
defined $options and length $options
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
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 122 | |||||||||||||||||||||||||||||
| 123 | 0 | ▶ | if ($self->payload) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 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__ | ||||||||||||||||||||||||||||