| 1 | # | ||
| 2 | # $Id: Address.pm 2002 2015-02-15 16:50:35Z gomor $ | ||
| 3 | # | ||
| 4 | package Net::Packet::CDP::Address; | ||
| 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); |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 12 | 0 | ▶ | use Net::Packet::Utils qw(inetAton inetNtoa); |
|
Subroutine
BEGIN: called CC=1 SCAR=2.6
| |||
| 13 | |||
| 14 | our @AS = qw( | ||
| 15 | protocolType | ||
| 16 | protocolLength | ||
| 17 | protocol | ||
| 18 | addressLength | ||
| 19 | address | ||
| 20 | ); | ||
| 21 | __PACKAGE__->cgBuildIndices; | ||
| 22 | __PACKAGE__->cgBuildAccessorsScalar(\@AS); | ||
| 23 | |||
| 24 | #no strict 'vars'; | ||
| 25 | |||
| 26 | sub new { | ||
| 27 | shift->SUPER::new( | ||
| 28 | protocolType => NP_CDP_ADDRESS_PROTOCOL_TYPE_NLPID, | ||
| 29 | protocolLength => NP_CDP_ADDRESS_PROTOCOL_LENGTH_NLPID, | ||
| 30 | protocol => NP_CDP_ADDRESS_PROTOCOL_IP, | ||
| 31 | addressLength => NP_CDP_ADDRESS_ADDRESS_LENGTH_IP, | ||
| 32 | address => '127.0.0.1', | ||
| 33 | @_, | ||
| 34 | ); | ||
| 35 | } | ||
| 36 | |||
| 37 | sub pack { | ||
| 38 | my $self = shift; | ||
| 39 | |||
| 40 | $self->raw($self->SUPER::pack('CCCna4', | ||
| 41 | $self->protocolType, | ||
| 42 | $self->protocolLength, | ||
| 43 | $self->protocol, | ||
| 44 | $self->addressLength, | ||
| 45 | inetAton($self->address), | ||
| 46 | )) or return undef; | ||
| 47 | |||
| 48 | 1; | ||
| 49 | } | ||
| 50 | |||
| 51 | sub unpack { | ||
| 52 | my $self = shift; | ||
| 53 | |||
| 54 | my ($protocolType, $protocolLength, $protocol, $addressLength, $tail) = | ||
| 55 | $self->SUPER::unpack('CCCn a*', $self->raw) | ||
| 56 | or return undef; | ||
| 57 | |||
| 58 | $self->protocolType($protocolType); | ||
| 59 | $self->protocolLength($protocolLength); | ||
| 60 | $self->protocol($protocol); | ||
| 61 | $self->addressLength($addressLength); | ||
| 62 | |||
| 63 | my $payload; | ||
| 64 | if ($protocol eq NP_CDP_ADDRESS_PROTOCOL_IP) { | ||
| 65 | my ($address, $lPayload) = $self->SUPER::unpack('a4 a*', $tail) | ||
| 66 | or return undef; | ||
| 67 | $self->address(inetNtoa($address)); | ||
| 68 | $payload = $lPayload; | ||
| 69 | } | ||
| 70 | else { | ||
| 71 | # Unknown | ||
| 72 | } | ||
| 73 | |||
| 74 | $self->payload($payload); | ||
| 75 | |||
| 76 | 1; | ||
| 77 | } | ||
| 78 | |||
| 79 | sub print { | ||
| 80 | my $self = shift; | ||
| 81 | |||
| 82 | my $i = $self->is; | ||
| 83 | my $l = $self->layer; | ||
| 84 | sprintf "$l: $i: protocolType:0x%02x protocolLength:%d protocol:0x%02x\n". | ||
| 85 | "$l: $i: addressLength:%d address:%s", | ||
| 86 | $self->protocolType, $self->protocolLength, $self->protocol, | ||
| 87 | $self->addressLength, $self->address; | ||
| 88 | } | ||
| 89 | |||
| 90 | 1; | ||
| 91 | |||
| 92 | __END__ | ||