| 1 | # | ||||||||||
| 2 | # $Id: CDP.pm 2002 2015-02-15 16:50:35Z gomor $ | ||||||||||
| 3 | # | ||||||||||
| 4 | package Net::Packet::CDP; | ||||||||||
| 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::Layer4; | ||||||||||
| 9 | our @ISA = qw(Net::Packet::Layer4); | ||||||||||
| 10 | |||||||||||
| 11 | 1 | ▶ | use Net::Packet::Consts qw(:cdp :layer); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 12 | require Net::Packet::CDP::TypeDeviceId; | ||||||||||
| 13 | require Net::Packet::CDP::TypeAddresses; | ||||||||||
| 14 | require Net::Packet::CDP::TypePortId; | ||||||||||
| 15 | require Net::Packet::CDP::TypeCapabilities; | ||||||||||
| 16 | require Net::Packet::CDP::TypeSoftwareVersion; | ||||||||||
| 17 | |||||||||||
| 18 | our @AS = qw( | ||||||||||
| 19 | version | ||||||||||
| 20 | ttl | ||||||||||
| 21 | checksum | ||||||||||
| 22 | typeDeviceId | ||||||||||
| 23 | typeAddresses | ||||||||||
| 24 | typePortId | ||||||||||
| 25 | typeCapabilities | ||||||||||
| 26 | typeSoftwareVersion | ||||||||||
| 27 | ); | ||||||||||
| 28 | __PACKAGE__->cgBuildIndices; | ||||||||||
| 29 | __PACKAGE__->cgBuildAccessorsScalar(\@AS); | ||||||||||
| 30 | |||||||||||
| 31 | 1 | ▶ | no strict 'vars'; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 32 | |||||||||||
| 33 | 0 | ▶ | sub new { | ||||||||
|
Subroutine
new: not called CC=1 SCAR=6.9
| |||||||||||
| 34 | shift->SUPER::new( | ||||||||||
| 35 | 0 | version => 2, | |||||||||
| 36 | ttl => 180, | ||||||||||
| 37 | checksum => 0, | ||||||||||
| 38 | @_, | ||||||||||
| 39 | ); | ||||||||||
| 40 | } | ||||||||||
| 41 | |||||||||||
| 42 | 0 | ▶ | sub getLength { NP_CDP_HDR_LEN } | ||||||||
|
Subroutine
getLength: not called CC=1 SCAR=6.9
| |||||||||||
| 43 | |||||||||||
| 44 | 0 | ▶ | sub pack { | ||||||||
|
Subroutine
pack: not called CC=12 SCAR=50.5
| |||||||||||
| 45 | 0 | my $self = shift; | |||||||||
| 46 | |||||||||||
| 47 | 0 | ▶ | $self->[$__raw] = $self->SUPER::pack('CCn', | ||||||||
|
Branch: 1 branch
| |||||||||||
| 48 | $self->[$__version], | ||||||||||
| 49 | $self->[$__ttl], | ||||||||||
| 50 | $self->[$__checksum], | ||||||||||
| 51 | ) or return undef; | ||||||||||
| 52 | |||||||||||
| 53 | 0 | ▶ | if ($self->[$__typeDeviceId]) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 54 | 0 | ▶ | $self->[$__raw] .= $self->[$__typeDeviceId]->pack | ||||||||
|
Branch: 1 branch
| |||||||||||
| 55 | or return undef; | ||||||||||
| 56 | } | ||||||||||
| 57 | 0 | ▶ | if ($self->[$__typeAddresses]) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 58 | 0 | ▶ | $self->[$__raw] .= $self->[$__typeAddresses]->pack | ||||||||
|
Branch: 1 branch
| |||||||||||
| 59 | or return undef; | ||||||||||
| 60 | } | ||||||||||
| 61 | 0 | ▶ | if ($self->[$__typePortId]) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 62 | 0 | ▶ | $self->[$__raw] .= $self->[$__typePortId]->pack | ||||||||
|
Branch: 1 branch
| |||||||||||
| 63 | or return undef; | ||||||||||
| 64 | } | ||||||||||
| 65 | 0 | ▶ | if ($self->[$__typeCapabilities]) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 66 | 0 | ▶ | $self->[$__raw] .= $self->[$__typeCapabilities]->pack | ||||||||
|
Branch: 1 branch
| |||||||||||
| 67 | or return undef; | ||||||||||
| 68 | } | ||||||||||
| 69 | 0 | ▶ | if ($self->[$__typeSoftwareVersion]) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 70 | 0 | ▶ | $self->[$__raw] .= $self->[$__typeSoftwareVersion]->pack | ||||||||
|
Branch: 1 branch
| |||||||||||
| 71 | or return undef; | ||||||||||
| 72 | } | ||||||||||
| 73 | |||||||||||
| 74 | 0 | 1; | |||||||||
| 75 | } | ||||||||||
| 76 | |||||||||||
| 77 | 0 | ▶ | sub unpack { | ||||||||
|
Subroutine
unpack: not called CC=7 SCAR=40.3
| |||||||||||
| 78 | 0 | my $self = shift; | |||||||||
| 79 | |||||||||||
| 80 | 0 | ▶ | my ($version, $ttl, $checksum, $payload) = | ||||||||
|
Branch: 1 branch
| |||||||||||
| 81 | $self->SUPER::unpack('CCn a*', $self->[$__raw]) | ||||||||||
| 82 | or return undef; | ||||||||||
| 83 | |||||||||||
| 84 | 0 | $self->[$__version] = $version; | |||||||||
| 85 | 0 | $self->[$__ttl] = $ttl; | |||||||||
| 86 | 0 | $self->[$__checksum] = $checksum; | |||||||||
| 87 | |||||||||||
| 88 | 0 | my $tail = CORE::unpack('H*', $payload); | |||||||||
| 89 | |||||||||||
| 90 | 0 | ▶ | if ($tail =~ /^0001/) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 91 | 0 | my $type = Net::Packet::CDP::TypeDeviceId->new(raw => $payload); | |||||||||
| 92 | 0 | $self->[$__typeDeviceId] = $type; | |||||||||
| 93 | 0 | $payload = $type->payload; | |||||||||
| 94 | 0 | $tail = CORE::unpack('H*', $payload); | |||||||||
| 95 | } | ||||||||||
| 96 | 0 | ▶ | if ($tail =~ /^0002/) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 97 | 0 | my $type = Net::Packet::CDP::TypeAddresses->new(raw => $payload); | |||||||||
| 98 | 0 | $self->[$__typeAddresses] = $type; | |||||||||
| 99 | 0 | $payload = $type->payload; | |||||||||
| 100 | 0 | $tail = CORE::unpack('H*', $payload); | |||||||||
| 101 | } | ||||||||||
| 102 | 0 | ▶ | if ($tail =~ /^0003/) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 103 | 0 | my $type = Net::Packet::CDP::TypePortId->new(raw => $payload); | |||||||||
| 104 | 0 | $self->[$__typePortId] = $type; | |||||||||
| 105 | 0 | $payload = $type->payload; | |||||||||
| 106 | 0 | $tail = CORE::unpack('H*', $payload); | |||||||||
| 107 | } | ||||||||||
| 108 | 0 | ▶ | if ($tail =~ /^0004/) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 109 | 0 | my $type = Net::Packet::CDP::TypeCapabilities->new(raw => $payload); | |||||||||
| 110 | 0 | $self->[$__typeCapabilities] = $type; | |||||||||
| 111 | 0 | $payload = $type->payload; | |||||||||
| 112 | 0 | $tail = CORE::unpack('H*', $payload); | |||||||||
| 113 | } | ||||||||||
| 114 | 0 | ▶ | if ($tail =~ /^0005/) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 115 | 0 | my $type = Net::Packet::CDP::TypeSoftwareVersion->new(raw => $payload); | |||||||||
| 116 | 0 | $self->[$__typeSoftwareVersion] = $type; | |||||||||
| 117 | 0 | $payload = $type->payload; | |||||||||
| 118 | 0 | $tail = CORE::unpack('H*', $payload); | |||||||||
| 119 | } | ||||||||||
| 120 | |||||||||||
| 121 | 0 | $self->[$__payload] = $payload; | |||||||||
| 122 | |||||||||||
| 123 | 0 | 1; | |||||||||
| 124 | } | ||||||||||
| 125 | |||||||||||
| 126 | 0 | ▶ | sub encapsulate { | ||||||||
|
Subroutine
encapsulate: not called CC=2 SCAR=17.9
| |||||||||||
| 127 | 0 | my $types = { | |||||||||
| 128 | NP_LAYER_NONE() => NP_LAYER_NONE(), | ||||||||||
| 129 | }; | ||||||||||
| 130 | |||||||||||
| 131 | 0 | ▶ | $types->{NP_LAYER_NONE()} || NP_LAYER_UNKNOWN(); | ||||||||
|
Branch: 1 branch
| |||||||||||
| 132 | } | ||||||||||
| 133 | |||||||||||
| 134 | 0 | ▶ | sub print { | ||||||||
|
Subroutine
print: not called CC=6 SCAR=37.4
| |||||||||||
| 135 | 0 | my $self = shift; | |||||||||
| 136 | |||||||||||
| 137 | 0 | my $buf = ''; | |||||||||
| 138 | |||||||||||
| 139 | 0 | my $l = $self->layer; | |||||||||
| 140 | 0 | my $i = $self->is; | |||||||||
| 141 | 0 | $buf .= sprintf "$l:+$i: version:%d ttl:%d checksum:0x%04x", | |||||||||
| 142 | $self->[$__version], $self->[$__ttl], $self->[$__checksum]; | ||||||||||
| 143 | |||||||||||
| 144 | 0 | ▶ | if ($self->[$__typeDeviceId]) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 145 | 0 | $buf .= "\n".$self->[$__typeDeviceId]->print; | |||||||||
| 146 | } | ||||||||||
| 147 | 0 | ▶ | if ($self->[$__typeAddresses]) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 148 | 0 | $buf .= "\n".$self->[$__typeAddresses]->print; | |||||||||
| 149 | } | ||||||||||
| 150 | 0 | ▶ | if ($self->[$__typePortId]) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 151 | 0 | $buf .= "\n".$self->[$__typePortId]->print; | |||||||||
| 152 | } | ||||||||||
| 153 | 0 | ▶ | if ($self->[$__typeCapabilities]) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 154 | 0 | $buf .= "\n".$self->[$__typeCapabilities]->print; | |||||||||
| 155 | } | ||||||||||
| 156 | 0 | ▶ | if ($self->[$__typeSoftwareVersion]) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 157 | 0 | $buf .= "\n".$self->[$__typeSoftwareVersion]->print; | |||||||||
| 158 | } | ||||||||||
| 159 | |||||||||||
| 160 | 0 | $buf; | |||||||||
| 161 | } | ||||||||||
| 162 | |||||||||||
| 163 | 1; | ||||||||||
| 164 | |||||||||||
| 165 | __END__ | ||||||||||