| 1 | # | ||||||||||
| 2 | # $Id: TypeAddresses.pm 2002 2015-02-15 16:50:35Z gomor $ | ||||||||||
| 3 | # | ||||||||||
| 4 | package Net::Packet::CDP::TypeAddresses; | ||||||||||
| 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 | |||||||||||
| 8 | require Net::Packet::CDP::Type; | ||||||||||
| 9 | our @ISA = qw(Net::Packet::CDP::Type); | ||||||||||
| 10 | |||||||||||
| 11 | 1 | ▶ | use Net::Packet::Consts qw(:cdp); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 12 | require Net::Packet::CDP::Address; | ||||||||||
| 13 | |||||||||||
| 14 | our @AS = qw( | ||||||||||
| 15 | numberOfAddresses | ||||||||||
| 16 | ); | ||||||||||
| 17 | our @AA = qw( | ||||||||||
| 18 | addresses | ||||||||||
| 19 | ); | ||||||||||
| 20 | __PACKAGE__->cgBuildIndices; | ||||||||||
| 21 | __PACKAGE__->cgBuildAccessorsScalar(\@AS); | ||||||||||
| 22 | __PACKAGE__->cgBuildAccessorsArray (\@AA); | ||||||||||
| 23 | |||||||||||
| 24 | #no strict 'vars'; | ||||||||||
| 25 | |||||||||||
| 26 | 0 | ▶ | sub new { | ||||||||
|
Subroutine
new: not called CC=1 SCAR=6.9
| |||||||||||
| 27 | shift->SUPER::new( | ||||||||||
| 28 | 0 | type => NP_CDP_TYPE_ADDRESSES, | |||||||||
| 29 | length => 8, | ||||||||||
| 30 | numberOfAddresses => 0, | ||||||||||
| 31 | addresses => [], | ||||||||||
| 32 | @_, | ||||||||||
| 33 | ); | ||||||||||
| 34 | } | ||||||||||
| 35 | |||||||||||
| 36 | 0 | ▶ | sub pack { | ||||||||
|
Subroutine
pack: not called CC=3 SCAR=24.8
| |||||||||||
| 37 | 0 | my $self = shift; | |||||||||
| 38 | |||||||||||
| 39 | 0 | ▶ | $self->raw($self->SUPER::pack('nn', | ||||||||
|
Branch: 1 branch
| |||||||||||
| 40 | $self->type, | ||||||||||
| 41 | $self->length, | ||||||||||
| 42 | )) or return undef; | ||||||||||
| 43 | |||||||||||
| 44 | 0 | my $raw = $self->raw; | |||||||||
| 45 | 0 | $raw .= $_->pack for $self->addresses; | |||||||||
| 46 | 0 | $self->raw($raw); | |||||||||
| 47 | |||||||||||
| 48 | 0 | 1; | |||||||||
| 49 | } | ||||||||||
| 50 | |||||||||||
| 51 | 0 | ▶ | sub unpack { | ||||||||
|
Subroutine
unpack: not called CC=3 SCAR=24.8
| |||||||||||
| 52 | 0 | my $self = shift; | |||||||||
| 53 | |||||||||||
| 54 | 0 | ▶ | my ($type, $length, $numberOfAddresses, $tail) = | ||||||||
|
Branch: 1 branch
| |||||||||||
| 55 | $self->SUPER::unpack('nnNa*', $self->raw) | ||||||||||
| 56 | or return undef; | ||||||||||
| 57 | |||||||||||
| 58 | 0 | $self->type($type); | |||||||||
| 59 | 0 | $self->length($length); | |||||||||
| 60 | 0 | $self->numberOfAddresses($numberOfAddresses); | |||||||||
| 61 | |||||||||||
| 62 | 0 | my @addressList; | |||||||||
| 63 | 0 | for my $n (1..$numberOfAddresses) { | |||||||||
| 64 | 0 | my $a = Net::Packet::CDP::Address->new(raw => $tail); | |||||||||
| 65 | 0 | push @addressList, $a; | |||||||||
| 66 | 0 | $tail = $a->payload; | |||||||||
| 67 | } | ||||||||||
| 68 | |||||||||||
| 69 | 0 | $self->addresses(\@addressList); | |||||||||
| 70 | 0 | $self->payload($tail); | |||||||||
| 71 | |||||||||||
| 72 | 0 | 1; | |||||||||
| 73 | } | ||||||||||
| 74 | |||||||||||
| 75 | 0 | ▶ | sub print { | ||||||||
|
Subroutine
print: not called CC=2 SCAR=17.9
| |||||||||||
| 76 | 0 | my $self = shift; | |||||||||
| 77 | |||||||||||
| 78 | 0 | my $buf = ''; | |||||||||
| 79 | 0 | my $i = $self->is; | |||||||||
| 80 | 0 | my $l = $self->layer; | |||||||||
| 81 | 0 | $buf .= sprintf "$l: $i: type:0x%04x length:%d numberOfAddresses:%d", | |||||||||
| 82 | $self->type, $self->length, $self->numberOfAddresses; | ||||||||||
| 83 | |||||||||||
| 84 | 0 | for ($self->addresses) { | |||||||||
| 85 | 0 | $buf .= "\n".$_->print; | |||||||||
| 86 | } | ||||||||||
| 87 | |||||||||||
| 88 | 0 | $buf; | |||||||||
| 89 | } | ||||||||||
| 90 | |||||||||||
| 91 | 1; | ||||||||||
| 92 | |||||||||||
| 93 | __END__ | ||||||||||