| 1 | # | ||
| 2 | # $Id: OSPF.pm 2002 2015-02-15 16:50:35Z gomor $ | ||
| 3 | # | ||
| 4 | package Net::Packet::OSPF; | ||
| 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(:ospf :layer); |
|
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 | version | ||
| 16 | messageType | ||
| 17 | length | ||
| 18 | sourceOspfRouter | ||
| 19 | areaId | ||
| 20 | checksum | ||
| 21 | authType | ||
| 22 | authData | ||
| 23 | ); | ||
| 24 | __PACKAGE__->cgBuildIndices; | ||
| 25 | __PACKAGE__->cgBuildAccessorsScalar(\@AS); | ||
| 26 | |||
| 27 | #no strict 'vars'; | ||
| 28 | |||
| 29 | sub new { | ||
| 30 | shift->SUPER::new( | ||
| 31 | version => 2, | ||
| 32 | messageType => 0, | ||
| 33 | length => NP_OSPF_HDR_LEN, | ||
| 34 | sourceOspfRouter => '127.0.0.1', | ||
| 35 | areaId => '127.0.0.1', | ||
| 36 | checksum => 0, | ||
| 37 | authType => NP_OSPF_AUTH_TYPE_NULL, | ||
| 38 | authData => '', | ||
| 39 | @_, | ||
| 40 | ); | ||
| 41 | } | ||
| 42 | |||
| 43 | sub getLength { shift->length } | ||
| 44 | |||
| 45 | sub pack { | ||
| 46 | my $self = shift; | ||
| 47 | |||
| 48 | $self->raw($self->SUPER::pack('CCna4a4nnH16', | ||
| 49 | $self->version, $self->messageType, $self->length, | ||
| 50 | inetAton($self->sourceOspfRouter), inetAton($self->areaId), | ||
| 51 | $self->checksum, $self->authType, $self->authData, | ||
| 52 | )) or return undef; | ||
| 53 | |||
| 54 | 1; | ||
| 55 | } | ||
| 56 | |||
| 57 | sub unpack { | ||
| 58 | my $self = shift; | ||
| 59 | |||
| 60 | my ($version, $messageType, $length, $sourceOspfRouter, $areaId, $checksum, | ||
| 61 | $authType, $authData, $payload) = | ||
| 62 | $self->SUPER::unpack('CCna4a4nnH16 a*', $self->raw) | ||
| 63 | or return undef; | ||
| 64 | |||
| 65 | $self->version($version); | ||
| 66 | $self->messageType($messageType); | ||
| 67 | $self->length($length); | ||
| 68 | $self->sourceOspfRouter(inetNtoa($sourceOspfRouter)); | ||
| 69 | $self->areaId(inetNtoa($areaId)); | ||
| 70 | $self->checksum($checksum); | ||
| 71 | $self->authType($authType); | ||
| 72 | $self->authData($authData); | ||
| 73 | |||
| 74 | $self->payload($payload); | ||
| 75 | |||
| 76 | 1; | ||
| 77 | } | ||
| 78 | |||
| 79 | sub encapsulate { | ||
| 80 | my $types = { | ||
| 81 | NP_LAYER_NONE() => NP_LAYER_NONE(), | ||
| 82 | }; | ||
| 83 | |||
| 84 | $types->{NP_LAYER_NONE()} || NP_LAYER_UNKNOWN(); | ||
| 85 | } | ||
| 86 | |||
| 87 | sub print { | ||
| 88 | my $self = shift; | ||
| 89 | |||
| 90 | my $l = $self->layer; | ||
| 91 | my $i = $self->is; | ||
| 92 | sprintf "$l:+$i: version:%d messageType:0x%02x length:%d\n". | ||
| 93 | "$l: $i: sourceOspfRouter:%s areaId:%s\n". | ||
| 94 | "$l: $i: checksum:0x%04x authType:0x%04x\n". | ||
| 95 | "$l: $i: authData:%s", | ||
| 96 | $self->version, $self->messageType, $self->length, | ||
| 97 | $self->sourceOspfRouter, $self->areaId, $self->checksum, | ||
| 98 | $self->authType, $self->authData; | ||
| 99 | } | ||
| 100 | |||
| 101 | 1; | ||
| 102 | |||
| 103 | __END__ | ||