| line | stmt | bran | cond | sub | pod | time | code | 
| 1 |  |  |  |  |  |  | # | 
| 2 |  |  |  |  |  |  | # $Id: NeighborAdvertisement.pm 45 2014-04-09 06:32:08Z gomor $ | 
| 3 |  |  |  |  |  |  | # | 
| 4 |  |  |  |  |  |  | package Net::Frame::Layer::ICMPv6::NeighborAdvertisement; | 
| 5 | 2 |  |  | 2 |  | 1886 | use strict; use warnings; | 
|  | 2 |  |  | 2 |  | 5 |  | 
|  | 2 |  |  |  |  | 122 |  | 
|  | 2 |  |  |  |  | 144 |  | 
|  | 2 |  |  |  |  | 8 |  | 
|  | 2 |  |  |  |  | 153 |  | 
| 6 |  |  |  |  |  |  |  | 
| 7 | 2 |  |  | 2 |  | 12 | use Net::Frame::Layer qw(:consts :subs); | 
|  | 2 |  |  |  |  | 3 |  | 
|  | 2 |  |  |  |  | 693 |  | 
| 8 |  |  |  |  |  |  | our @ISA = qw(Net::Frame::Layer); | 
| 9 |  |  |  |  |  |  |  | 
| 10 |  |  |  |  |  |  | our @AS = qw( | 
| 11 |  |  |  |  |  |  | flags | 
| 12 |  |  |  |  |  |  | reserved | 
| 13 |  |  |  |  |  |  | targetAddress | 
| 14 |  |  |  |  |  |  | ); | 
| 15 |  |  |  |  |  |  | our @AA = qw( | 
| 16 |  |  |  |  |  |  | options | 
| 17 |  |  |  |  |  |  | ); | 
| 18 |  |  |  |  |  |  | __PACKAGE__->cgBuildIndices; | 
| 19 |  |  |  |  |  |  | __PACKAGE__->cgBuildAccessorsScalar(\@AS); | 
| 20 |  |  |  |  |  |  | __PACKAGE__->cgBuildAccessorsArray (\@AA); | 
| 21 |  |  |  |  |  |  |  | 
| 22 | 2 |  |  | 2 |  | 12 | use Net::Frame::Layer::ICMPv6 qw(:consts); | 
|  | 2 |  |  |  |  | 4 |  | 
|  | 2 |  |  |  |  | 906 |  | 
| 23 | 2 |  |  | 2 |  | 14 | use Bit::Vector; | 
|  | 2 |  |  |  |  | 4 |  | 
|  | 2 |  |  |  |  | 74 |  | 
| 24 | 2 |  |  | 2 |  | 1798 | use Net::Frame::Layer::ICMPv6::Option; | 
|  | 2 |  |  |  |  | 6 |  | 
|  | 2 |  |  |  |  | 4127 |  | 
| 25 |  |  |  |  |  |  |  | 
| 26 |  |  |  |  |  |  | sub new { | 
| 27 |  |  |  |  |  |  | shift->SUPER::new( | 
| 28 | 1 |  |  | 1 | 1 | 24 | flags         => NF_ICMPv6_FLAG_SOLICITED, | 
| 29 |  |  |  |  |  |  | reserved      => 0, | 
| 30 |  |  |  |  |  |  | targetAddress => '::1', | 
| 31 |  |  |  |  |  |  | options       => [], | 
| 32 |  |  |  |  |  |  | @_, | 
| 33 |  |  |  |  |  |  | ); | 
| 34 |  |  |  |  |  |  | } | 
| 35 |  |  |  |  |  |  |  | 
| 36 |  |  |  |  |  |  | sub getOptionsLength { | 
| 37 | 0 |  |  | 0 | 1 | 0 | my $self = shift; | 
| 38 | 0 |  |  |  |  | 0 | my $len = 0; | 
| 39 | 0 |  |  |  |  | 0 | $len += $_->getLength for $self->options; | 
| 40 | 0 |  |  |  |  | 0 | return $len; | 
| 41 |  |  |  |  |  |  | } | 
| 42 |  |  |  |  |  |  |  | 
| 43 |  |  |  |  |  |  | sub getLength { | 
| 44 | 0 |  |  | 0 | 1 | 0 | my $self = shift; | 
| 45 | 0 |  |  |  |  | 0 | return 20 + $self->getOptionsLength; | 
| 46 |  |  |  |  |  |  | } | 
| 47 |  |  |  |  |  |  |  | 
| 48 |  |  |  |  |  |  | sub pack { | 
| 49 | 1 |  |  | 1 | 1 | 216 | my $self = shift; | 
| 50 |  |  |  |  |  |  |  | 
| 51 | 1 |  |  |  |  | 6 | my $flags    = Bit::Vector->new_Dec( 3, $self->flags); | 
| 52 | 1 |  |  |  |  | 62 | my $reserved = Bit::Vector->new_Dec(29, $self->reserved); | 
| 53 | 1 |  |  |  |  | 28 | my $v32      = $flags->Concat_List($reserved); | 
| 54 |  |  |  |  |  |  |  | 
| 55 | 1 | 50 |  |  |  | 26 | my $raw = $self->SUPER::pack('Na16', | 
| 56 |  |  |  |  |  |  | $v32->to_Dec, inet6Aton($self->targetAddress), | 
| 57 |  |  |  |  |  |  | ) or return; | 
| 58 |  |  |  |  |  |  |  | 
| 59 | 1 |  |  |  |  | 48 | for ($self->options) { | 
| 60 | 0 |  |  |  |  | 0 | $raw .= $_->pack; | 
| 61 |  |  |  |  |  |  | } | 
| 62 |  |  |  |  |  |  |  | 
| 63 | 1 |  |  |  |  | 31 | return $self->raw($raw); | 
| 64 |  |  |  |  |  |  | } | 
| 65 |  |  |  |  |  |  |  | 
| 66 |  |  |  |  |  |  | sub _unpackOptions { | 
| 67 | 0 |  |  | 0 |  | 0 | my $self = shift; | 
| 68 | 0 |  |  |  |  | 0 | my ($payload) = @_; | 
| 69 |  |  |  |  |  |  |  | 
| 70 | 0 |  |  |  |  | 0 | my @options = (); | 
| 71 | 0 |  | 0 |  |  | 0 | while (defined($payload) && length($payload)) { | 
| 72 | 0 |  |  |  |  | 0 | my $opt = Net::Frame::Layer::ICMPv6::Option->new(raw => $payload)->unpack; | 
| 73 | 0 |  |  |  |  | 0 | push @options, $opt; | 
| 74 | 0 |  |  |  |  | 0 | $payload = $opt->payload; | 
| 75 | 0 |  |  |  |  | 0 | $opt->payload(undef); | 
| 76 |  |  |  |  |  |  | } | 
| 77 | 0 |  |  |  |  | 0 | $self->options(\@options); | 
| 78 | 0 |  |  |  |  | 0 | return $payload; | 
| 79 |  |  |  |  |  |  | } | 
| 80 |  |  |  |  |  |  |  | 
| 81 |  |  |  |  |  |  | sub unpack { | 
| 82 | 1 |  |  | 1 | 1 | 20 | my $self = shift; | 
| 83 |  |  |  |  |  |  |  | 
| 84 | 1 | 50 |  |  |  | 4 | my ($flagsReserved, $targetAddress, $payload) = | 
| 85 |  |  |  |  |  |  | $self->SUPER::unpack('Na16 a*', $self->raw) | 
| 86 |  |  |  |  |  |  | or return undef; | 
| 87 |  |  |  |  |  |  |  | 
| 88 | 1 |  |  |  |  | 32 | my $v32 = Bit::Vector->new_Dec(32, $flagsReserved); | 
| 89 |  |  |  |  |  |  |  | 
| 90 | 1 |  |  |  |  | 12 | $self->reserved($v32->Chunk_Read(29,  0)); | 
| 91 | 1 |  |  |  |  | 21 | $self->flags   ($v32->Chunk_Read( 3, 29)); | 
| 92 | 1 |  |  |  |  | 13 | $self->targetAddress(inet6Ntoa($targetAddress)); | 
| 93 |  |  |  |  |  |  |  | 
| 94 | 1 | 50 | 33 |  |  | 31 | if (defined($payload) && length($payload)) { | 
| 95 | 0 |  |  |  |  | 0 | $payload = $self->_unpackOptions($payload); | 
| 96 |  |  |  |  |  |  | } | 
| 97 |  |  |  |  |  |  |  | 
| 98 | 1 |  |  |  |  | 8 | $self->payload($payload); | 
| 99 |  |  |  |  |  |  |  | 
| 100 | 1 |  |  |  |  | 24 | return $self; | 
| 101 |  |  |  |  |  |  | } | 
| 102 |  |  |  |  |  |  |  | 
| 103 |  |  |  |  |  |  | sub print { | 
| 104 | 0 |  |  | 0 | 1 |  | my $self = shift; | 
| 105 |  |  |  |  |  |  |  | 
| 106 | 0 |  |  |  |  |  | my $l = $self->layer; | 
| 107 | 0 |  |  |  |  |  | my $buf = sprintf "$l: flags:%02x  reserved:%d\n". | 
| 108 |  |  |  |  |  |  | "$l: targetAddress:%s", | 
| 109 |  |  |  |  |  |  | $self->flags, $self->reserved, $self->targetAddress; | 
| 110 |  |  |  |  |  |  |  | 
| 111 | 0 |  |  |  |  |  | for ($self->options) { | 
| 112 | 0 |  |  |  |  |  | $buf .= "\n".$_->print; | 
| 113 |  |  |  |  |  |  | } | 
| 114 |  |  |  |  |  |  |  | 
| 115 | 0 |  |  |  |  |  | return $buf; | 
| 116 |  |  |  |  |  |  | } | 
| 117 |  |  |  |  |  |  |  | 
| 118 |  |  |  |  |  |  | 1; | 
| 119 |  |  |  |  |  |  |  | 
| 120 |  |  |  |  |  |  | __END__ |