| 1 | # | ||||||||||
| 2 | # $Id: Option.pm 47 2015-01-20 18:20:28Z gomor $ | ||||||||||
| 3 | # | ||||||||||
| 4 | package Net::Frame::Layer::IPv6::Option; | ||||||||||
| 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 | our @ISA = qw(Net::Frame::Layer); | |||||||||
| 10 | |||||||||||
| 11 | 3 | our @AS = qw( | |||||||||
| 12 | type | ||||||||||
| 13 | length | ||||||||||
| 14 | value | ||||||||||
| 15 | ); | ||||||||||
| 16 | 3 | __PACKAGE__->cgBuildIndices; | |||||||||
| 17 | 3 | __PACKAGE__->cgBuildAccessorsScalar(\@AS); | |||||||||
| 18 | |||||||||||
| 19 | sub new { | ||||||||||
| 20 | shift->SUPER::new( | ||||||||||
| 21 | 1 | ▶ | type => 1, | ||||||||
|
Subroutine
new: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||
| 22 | length => 0, | ||||||||||
| 23 | value => '', | ||||||||||
| 24 | @_, | ||||||||||
| 25 | ); | ||||||||||
| 26 | } | ||||||||||
| 27 | |||||||||||
| 28 | sub getLength { | ||||||||||
| 29 | 0 | ▶ | my $self = shift; | ||||||||
|
Subroutine
getLength: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||
| 30 | |||||||||||
| 31 | 0 | ▶ | if ($self->type == 0) { # Pad1, only type is used | ||||||||
|
Branch: 1 branch
| |||||||||||
| 32 | 0 | return 1; | |||||||||
| 33 | } | ||||||||||
| 34 | |||||||||||
| 35 | 0 | return length($self->value) + 2; | |||||||||
| 36 | } | ||||||||||
| 37 | |||||||||||
| 38 | sub pack { | ||||||||||
| 39 | 1 | ▶ | my $self = shift; | ||||||||
|
Subroutine
pack: called CC=4 SCAR=14.6
Pod
documented
| |||||||||||
| 40 | |||||||||||
| 41 | 1 | ▶ | my $raw = $self->SUPER::pack('C', $self->type) | ||||||||
|
Branch: 1 branch
| |||||||||||
| 42 | or return; | ||||||||||
| 43 | |||||||||||
| 44 | 1 | ▶ | if ($self->type != 0) { # Not a Pad1 option | ||||||||
|
Branch: 1 branch
| |||||||||||
| 45 | 1 | ▶ | $raw .= $self->SUPER::pack('Ca*', $self->length, $self->value) | ||||||||
|
Branch: 1 branch
| |||||||||||
| 46 | or return; | ||||||||||
| 47 | } | ||||||||||
| 48 | |||||||||||
| 49 | 1 | return $self->raw($raw); | |||||||||
| 50 | } | ||||||||||
| 51 | |||||||||||
| 52 | sub unpack { | ||||||||||
| 53 | 1 | ▶ | my $self = shift; | ||||||||
|
Subroutine
unpack: called CC=5 SCAR=16.6
Pod
documented
| |||||||||||
| 54 | |||||||||||
| 55 | 1 | ▶ | my ($type, $payload) = $self->SUPER::unpack('C a*', $self->raw) | ||||||||
|
Branch: 1 branch
| |||||||||||
| 56 | or return; | ||||||||||
| 57 | 1 | $self->type($type); | |||||||||
| 58 | |||||||||||
| 59 | 1 | ▶ | if ($self->type != 0) { # Not a Pad1 option | ||||||||
|
Branch: 1 branch
| |||||||||||
| 60 | 1 | ▶ | my ($length, $tail) = $self->SUPER::unpack('C a*', $payload) | ||||||||
|
Branch: 1 branch
| |||||||||||
| 61 | or return; | ||||||||||
| 62 | |||||||||||
| 63 | 1 | my $value = ''; | |||||||||
| 64 | 1 | ▶ | ($value, $payload) = $self->SUPER::unpack("a$length a*", $tail) | ||||||||
|
Branch: 1 branch
| |||||||||||
| 65 | or return; | ||||||||||
| 66 | |||||||||||
| 67 | 1 | $self->length($length); | |||||||||
| 68 | 1 | $self->value($value); | |||||||||
| 69 | } | ||||||||||
| 70 | |||||||||||
| 71 | 1 | $self->payload($payload); | |||||||||
| 72 | |||||||||||
| 73 | 1 | return $self; | |||||||||
| 74 | } | ||||||||||
| 75 | |||||||||||
| 76 | sub computeLengths { | ||||||||||
| 77 | 0 | ▶ | my $self = shift; | ||||||||
|
Subroutine
computeLengths: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||
| 78 | |||||||||||
| 79 | 0 | my $length = 0; | |||||||||
| 80 | 0 | ▶ | if ($self->type != 0) { # Not a Pad1 option | ||||||||
|
Branch: 1 branch
| |||||||||||
| 81 | 0 | $length = length($self->value); | |||||||||
| 82 | } | ||||||||||
| 83 | 0 | $self->length($length); | |||||||||
| 84 | |||||||||||
| 85 | 0 | return 1; | |||||||||
| 86 | } | ||||||||||
| 87 | |||||||||||
| 88 | sub print { | ||||||||||
| 89 | 0 | ▶ | my $self = shift; | ||||||||
|
Subroutine
print: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||
| 90 | |||||||||||
| 91 | 0 | my $buf = ''; | |||||||||
| 92 | 0 | my $l = $self->layer; | |||||||||
| 93 | 0 | ▶ | if ($self->type == 0x00) { # Pad1 specific type | ||||||||
|
Branch: 1 branch
| |||||||||||
| 94 | 0 | $buf .= sprintf "$l: type:0x%02x", $self->type; | |||||||||
| 95 | } | ||||||||||
| 96 | else { | ||||||||||
| 97 | 0 | $buf .= sprintf "$l: type:0x%02x length:%d value:%s", | |||||||||
| 98 | $self->type, $self->length, CORE::unpack('H*', $self->value); | ||||||||||
| 99 | } | ||||||||||
| 100 | |||||||||||
| 101 | 0 | return $buf; | |||||||||
| 102 | } | ||||||||||
| 103 | |||||||||||
| 104 | 3 | 1; | |||||||||
| 105 | |||||||||||
| 106 | __END__ | ||||||||||