| 1 | # | ||||||||||||
| 2 | # $Id: IPv4.pm,v 1.7 2006/12/06 21:19:00 gomor Exp $ | ||||||||||||
| 3 | # | ||||||||||||
| 4 | package Net::Frame::IPv4; | ||||||||||||
| 5 | 3 | ▶ | use strict; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 6 | 3 | ▶ | use warnings; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 7 | |||||||||||||
| 8 | 3 | ▶ | use Net::Frame::Layer qw(:consts); | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 9 | require Exporter; | ||||||||||||
| 10 | our @ISA = qw(Net::Frame::Layer Exporter); | ||||||||||||
| 11 | |||||||||||||
| 12 | our %EXPORT_TAGS = ( | ||||||||||||
| 13 | consts => [qw( | ||||||||||||
| 14 | NP_IPv4_HDR_LEN | ||||||||||||
| 15 | NP_IPv4_PROTOCOL_USER | ||||||||||||
| 16 | NP_IPv4_PROTOCOL_ICMPv4 | ||||||||||||
| 17 | NP_IPv4_PROTOCOL_IGMPv4 | ||||||||||||
| 18 | NP_IPv4_PROTOCOL_IPIP | ||||||||||||
| 19 | NP_IPv4_PROTOCOL_TCP | ||||||||||||
| 20 | NP_IPv4_PROTOCOL_EGP | ||||||||||||
| 21 | NP_IPv4_PROTOCOL_IGRP | ||||||||||||
| 22 | NP_IPv4_PROTOCOL_CHAOS | ||||||||||||
| 23 | NP_IPv4_PROTOCOL_UDP | ||||||||||||
| 24 | NP_IPv4_PROTOCOL_IDP | ||||||||||||
| 25 | NP_IPv4_PROTOCOL_DCCP | ||||||||||||
| 26 | NP_IPv4_PROTOCOL_IPv6 | ||||||||||||
| 27 | NP_IPv4_PROTOCOL_IPv6ROUTING | ||||||||||||
| 28 | NP_IPv4_PROTOCOL_IPv6FRAGMENT | ||||||||||||
| 29 | NP_IPv4_PROTOCOL_IDRP | ||||||||||||
| 30 | NP_IPv4_PROTOCOL_RSVP | ||||||||||||
| 31 | NP_IPv4_PROTOCOL_GRE | ||||||||||||
| 32 | NP_IPv4_PROTOCOL_ESP | ||||||||||||
| 33 | NP_IPv4_PROTOCOL_AH | ||||||||||||
| 34 | NP_IPv4_PROTOCOL_ICMPv6 | ||||||||||||
| 35 | NP_IPv4_PROTOCOL_EIGRP | ||||||||||||
| 36 | NP_IPv4_PROTOCOL_OSPF | ||||||||||||
| 37 | NP_IPv4_PROTOCOL_ETHERIP | ||||||||||||
| 38 | NP_IPv4_PROTOCOL_PIM | ||||||||||||
| 39 | NP_IPv4_PROTOCOL_VRRP | ||||||||||||
| 40 | NP_IPv4_PROTOCOL_STP | ||||||||||||
| 41 | NP_IPv4_PROTOCOL_SCTP | ||||||||||||
| 42 | NP_IPv4_MORE_FRAGMENT | ||||||||||||
| 43 | NP_IPv4_DONT_FRAGMENT | ||||||||||||
| 44 | NP_IPv4_RESERVED_FRAGMENT | ||||||||||||
| 45 | )], | ||||||||||||
| 46 | ); | ||||||||||||
| 47 | our @EXPORT_OK = ( | ||||||||||||
| 48 | @{$EXPORT_TAGS{consts}}, | ||||||||||||
| 49 | ); | ||||||||||||
| 50 | |||||||||||||
| 51 | 3 | ▶ | use constant NP_IPv4_HDR_LEN => 20; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 52 | 3 | ▶ | use constant NP_IPv4_PROTOCOL_USER => 0x00; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 53 | 3 | ▶ | use constant NP_IPv4_PROTOCOL_ICMPv4 => 0x01; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 54 | 3 | ▶ | use constant NP_IPv4_PROTOCOL_IGMPv4 => 0x02; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 55 | 3 | ▶ | use constant NP_IPv4_PROTOCOL_IPIP => 0x04; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 56 | 3 | ▶ | use constant NP_IPv4_PROTOCOL_TCP => 0x06; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 57 | 3 | ▶ | use constant NP_IPv4_PROTOCOL_EGP => 0x08; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 58 | 3 | ▶ | use constant NP_IPv4_PROTOCOL_IGRP => 0x09; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 59 | 3 | ▶ | use constant NP_IPv4_PROTOCOL_CHAOS => 0x10; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 60 | 3 | ▶ | use constant NP_IPv4_PROTOCOL_UDP => 0x11; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 61 | 3 | ▶ | use constant NP_IPv4_PROTOCOL_IDP => 0x16; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 62 | 3 | ▶ | use constant NP_IPv4_PROTOCOL_DCCP => 0x21; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 63 | 3 | ▶ | use constant NP_IPv4_PROTOCOL_IPv6 => 0x29; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 64 | 3 | ▶ | use constant NP_IPv4_PROTOCOL_IPv6ROUTING => 0x2b; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 65 | 3 | ▶ | use constant NP_IPv4_PROTOCOL_IPv6FRAGMENT => 0x2c; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 66 | 3 | ▶ | use constant NP_IPv4_PROTOCOL_IDRP => 0x2d; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 67 | 3 | ▶ | use constant NP_IPv4_PROTOCOL_RSVP => 0x2e; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 68 | 3 | ▶ | use constant NP_IPv4_PROTOCOL_GRE => 0x2f; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 69 | 3 | ▶ | use constant NP_IPv4_PROTOCOL_ESP => 0x32; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 70 | 3 | ▶ | use constant NP_IPv4_PROTOCOL_AH => 0x33; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 71 | 3 | ▶ | use constant NP_IPv4_PROTOCOL_ICMPv6 => 0x3a; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 72 | 3 | ▶ | use constant NP_IPv4_PROTOCOL_EIGRP => 0x58; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 73 | 3 | ▶ | use constant NP_IPv4_PROTOCOL_OSPF => 0x59; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 74 | 3 | ▶ | use constant NP_IPv4_PROTOCOL_ETHERIP => 0x61; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 75 | 3 | ▶ | use constant NP_IPv4_PROTOCOL_PIM => 0x67; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 76 | 3 | ▶ | use constant NP_IPv4_PROTOCOL_VRRP => 0x70; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 77 | 3 | ▶ | use constant NP_IPv4_PROTOCOL_STP => 0x76; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 78 | 3 | ▶ | use constant NP_IPv4_PROTOCOL_SCTP => 0x84; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 79 | 3 | ▶ | use constant NP_IPv4_MORE_FRAGMENT => 1; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 80 | 3 | ▶ | use constant NP_IPv4_DONT_FRAGMENT => 2; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 81 | 3 | ▶ | use constant NP_IPv4_RESERVED_FRAGMENT => 4; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 82 | |||||||||||||
| 83 | our @AS = qw( | ||||||||||||
| 84 | id | ||||||||||||
| 85 | ttl | ||||||||||||
| 86 | src | ||||||||||||
| 87 | dst | ||||||||||||
| 88 | protocol | ||||||||||||
| 89 | checksum | ||||||||||||
| 90 | flags | ||||||||||||
| 91 | offset | ||||||||||||
| 92 | version | ||||||||||||
| 93 | tos | ||||||||||||
| 94 | length | ||||||||||||
| 95 | hlen | ||||||||||||
| 96 | options | ||||||||||||
| 97 | noFixLen | ||||||||||||
| 98 | ); | ||||||||||||
| 99 | __PACKAGE__->cgBuildIndices; | ||||||||||||
| 100 | __PACKAGE__->cgBuildAccessorsScalar(\@AS); | ||||||||||||
| 101 | |||||||||||||
| 102 | BEGIN { | ||||||||||||
| 103 | 3 | ▶ | my $osname = { | ||||||||||
|
Subroutine
BEGIN: called CC=2 SCAR=7.2
| |||||||||||||
| 104 | freebsd => [ \&_fixLenBsd, ], | ||||||||||||
| 105 | netbsd => [ \&_fixLenBsd, ], | ||||||||||||
| 106 | }; | ||||||||||||
| 107 | |||||||||||||
| 108 | 3 | ▶ | *_fixLen = $osname->{$^O}->[0] || \&_fixLenOther; | ||||||||||
|
Condition50%1/2
$osname->{$^O}[0] || \&Net::Frame::IPv4::_fixLenOther
MC/DC0%0/1
$osname->{$^O}[0] || \&Net::Frame::IPv4::_fixLenOther
$osname->{$^O}[0]
Truth table50%1/2
A
A= $osname->{$^O}[0]
| |||||||||||||
| 109 | } | ||||||||||||
| 110 | |||||||||||||
| 111 | 3 | ▶ | no strict 'vars'; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 112 | |||||||||||||
| 113 | 3 | ▶ | use Carp; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 114 | 3 | ▶ | use Net::Frame::Utils qw(getRandom16bitsInt inetAton inetNtoa inetChecksum); | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=2.6
| |||||||||||||
| 115 | use Bit::Vector; | ||||||||||||
| 116 | |||||||||||||
| 117 | sub _fixLenBsd { pack('v', shift) } | ||||||||||||
| 118 | sub _fixLenOther { pack('n', shift) } | ||||||||||||
| 119 | |||||||||||||
| 120 | sub new { | ||||||||||||
| 121 | shift->SUPER::new( | ||||||||||||
| 122 | version => 4, | ||||||||||||
| 123 | tos => 0, | ||||||||||||
| 124 | id => getRandom16bitsInt(), | ||||||||||||
| 125 | length => NP_IPv4_HDR_LEN, | ||||||||||||
| 126 | hlen => 5, | ||||||||||||
| 127 | flags => 0, | ||||||||||||
| 128 | offset => 0, | ||||||||||||
| 129 | ttl => 128, | ||||||||||||
| 130 | protocol => NP_IPv4_PROTOCOL_TCP, | ||||||||||||
| 131 | checksum => 0, | ||||||||||||
| 132 | src => '127.0.0.1', | ||||||||||||
| 133 | dst => '127.0.0.1', | ||||||||||||
| 134 | options => '', | ||||||||||||
| 135 | noFixLen => 0, | ||||||||||||
| 136 | @_, | ||||||||||||
| 137 | ); | ||||||||||||
| 138 | } | ||||||||||||
| 139 | |||||||||||||
| 140 | sub pack { | ||||||||||||
| 141 | my $self = shift; | ||||||||||||
| 142 | |||||||||||||
| 143 | # Here, we pack in this order: version, hlen (4 bits each) | ||||||||||||
| 144 | my $version = Bit::Vector->new_Dec(4, $self->[$__version]); | ||||||||||||
| 145 | my $hlen = Bit::Vector->new_Dec(4, $self->[$__hlen]); | ||||||||||||
| 146 | my $v8 = $version->Concat_List($hlen); | ||||||||||||
| 147 | |||||||||||||
| 148 | # Here, we pack in this order: flags (3 bits), offset (13 bits) | ||||||||||||
| 149 | my $flags = Bit::Vector->new_Dec(3, $self->[$__flags]); | ||||||||||||
| 150 | my $offset = Bit::Vector->new_Dec(13, $self->[$__offset]); | ||||||||||||
| 151 | my $v16 = $flags->Concat_List($offset); | ||||||||||||
| 152 | |||||||||||||
| 153 | my $len = ($self->[$__noFixLen] ? _fixLenOther($self->[$__length]) | ||||||||||||
| 154 | : _fixLen($self->[$__length])); | ||||||||||||
| 155 | |||||||||||||
| 156 | $self->[$__raw] = $self->SUPER::pack('CCa*nnCCna4a4', | ||||||||||||
| 157 | $v8->to_Dec, | ||||||||||||
| 158 | $self->[$__tos], | ||||||||||||
| 159 | $len, | ||||||||||||
| 160 | $self->[$__id], | ||||||||||||
| 161 | $v16->to_Dec, | ||||||||||||
| 162 | $self->[$__ttl], | ||||||||||||
| 163 | $self->[$__protocol], | ||||||||||||
| 164 | $self->[$__checksum], | ||||||||||||
| 165 | inetAton($self->[$__src]), | ||||||||||||
| 166 | inetAton($self->[$__dst]), | ||||||||||||
| 167 | ) or return undef; | ||||||||||||
| 168 | |||||||||||||
| 169 | my $opt; | ||||||||||||
| 170 | if ($self->[$__options]) { | ||||||||||||
| 171 | $opt = $self->SUPER::pack('a*', $self->[$__options]) | ||||||||||||
| 172 | or return undef; | ||||||||||||
| 173 | $self->[$__raw] = $self->[$__raw].$opt; | ||||||||||||
| 174 | } | ||||||||||||
| 175 | |||||||||||||
| 176 | $self->[$__raw]; | ||||||||||||
| 177 | } | ||||||||||||
| 178 | |||||||||||||
| 179 | sub unpack { | ||||||||||||
| 180 | my $self = shift; | ||||||||||||
| 181 | |||||||||||||
| 182 | my ($verHlen, $tos, $len, $id, $flagsOffset, $ttl, $proto, $cksum, $src, | ||||||||||||
| 183 | $dst, $payload) = $self->SUPER::unpack('CCnnnCCna4a4 a*', $self->[$__raw]) | ||||||||||||
| 184 | or return undef; | ||||||||||||
| 185 | |||||||||||||
| 186 | my $v8 = Bit::Vector->new_Dec(8, $verHlen); | ||||||||||||
| 187 | my $v16 = Bit::Vector->new_Dec(16, $flagsOffset); | ||||||||||||
| 188 | |||||||||||||
| 189 | # Here, we unpack in this order: hlen, version (4 bits each) | ||||||||||||
| 190 | $self->[$__hlen] = $v8->Chunk_Read(4, 0); | ||||||||||||
| 191 | $self->[$__version] = $v8->Chunk_Read(4, 4); | ||||||||||||
| 192 | $self->[$__tos] = $tos; | ||||||||||||
| 193 | $self->[$__length] = $len; | ||||||||||||
| 194 | $self->[$__id] = $id; | ||||||||||||
| 195 | # Here, we unpack in this order: offset (13 bits), flags (3 bits) | ||||||||||||
| 196 | $self->[$__offset] = $v16->Chunk_Read(13, 0); | ||||||||||||
| 197 | $self->[$__flags] = $v16->Chunk_Read( 3, 13); | ||||||||||||
| 198 | $self->[$__ttl] = $ttl; | ||||||||||||
| 199 | $self->[$__protocol] = $proto; | ||||||||||||
| 200 | $self->[$__checksum] = $cksum; | ||||||||||||
| 201 | $self->[$__src] = inetNtoa($src); | ||||||||||||
| 202 | $self->[$__dst] = inetNtoa($dst); | ||||||||||||
| 203 | $self->[$__payload] = $payload; | ||||||||||||
| 204 | |||||||||||||
| 205 | my ($options, $payload2) = $self->SUPER::unpack( | ||||||||||||
| 206 | 'a'. $self->getOptionsLength. 'a*', $self->[$__payload] | ||||||||||||
| 207 | ) or return undef; | ||||||||||||
| 208 | |||||||||||||
| 209 | $self->[$__options] = $options; | ||||||||||||
| 210 | $self->[$__payload] = $payload2; | ||||||||||||
| 211 | |||||||||||||
| 212 | $self; | ||||||||||||
| 213 | } | ||||||||||||
| 214 | |||||||||||||
| 215 | sub getLength { | ||||||||||||
| 216 | my $self = shift; | ||||||||||||
| 217 | $self->[$__hlen] > 0 ? $self->[$__hlen] * 4 : 0; | ||||||||||||
| 218 | } | ||||||||||||
| 219 | |||||||||||||
| 220 | sub getPayloadLength { | ||||||||||||
| 221 | my $self = shift; | ||||||||||||
| 222 | my $gLen = $self->getLength; | ||||||||||||
| 223 | $self->[$__length] > $gLen ? $self->[$__length] - $gLen : 0; | ||||||||||||
| 224 | } | ||||||||||||
| 225 | |||||||||||||
| 226 | sub getOptionsLength { | ||||||||||||
| 227 | my $self = shift; | ||||||||||||
| 228 | my $gLen = $self->getLength; | ||||||||||||
| 229 | my $hLen = NP_IPv4_HDR_LEN; | ||||||||||||
| 230 | $gLen > $hLen ? $gLen - $hLen : 0; | ||||||||||||
| 231 | } | ||||||||||||
| 232 | |||||||||||||
| 233 | sub computeLengths { | ||||||||||||
| 234 | my $self = shift; | ||||||||||||
| 235 | my ($h) = @_; | ||||||||||||
| 236 | |||||||||||||
| 237 | my $hLen = NP_IPv4_HDR_LEN; | ||||||||||||
| 238 | $hLen += length($self->[$__options]) if $self->[$__options]; | ||||||||||||
| 239 | $self->[$__hlen] = $hLen / 4; | ||||||||||||
| 240 | |||||||||||||
| 241 | my $length = $self->getLength + $h->{payloadLength}; | ||||||||||||
| 242 | $self->[$__length] = $length; | ||||||||||||
| 243 | |||||||||||||
| 244 | 1; | ||||||||||||
| 245 | } | ||||||||||||
| 246 | |||||||||||||
| 247 | sub computeChecksums { | ||||||||||||
| 248 | my $self = shift; | ||||||||||||
| 249 | |||||||||||||
| 250 | # Reset the checksum if already filled by a previous pack | ||||||||||||
| 251 | if ($self->[$__checksum]) { | ||||||||||||
| 252 | $self->[$__checksum] = 0; | ||||||||||||
| 253 | } | ||||||||||||
| 254 | |||||||||||||
| 255 | $self->pack; | ||||||||||||
| 256 | $self->[$__checksum] = inetChecksum($self->[$__raw]); | ||||||||||||
| 257 | |||||||||||||
| 258 | 1; | ||||||||||||
| 259 | } | ||||||||||||
| 260 | |||||||||||||
| 261 | sub encapsulate { | ||||||||||||
| 262 | my $types = { | ||||||||||||
| 263 | NP_IPv4_PROTOCOL_ICMPv4() => 'ICMPv4', | ||||||||||||
| 264 | NP_IPv4_PROTOCOL_IGMPv4() => 'IGMPv4', | ||||||||||||
| 265 | NP_IPv4_PROTOCOL_IPIP() => 'IPIP', | ||||||||||||
| 266 | NP_IPv4_PROTOCOL_TCP() => 'TCP', | ||||||||||||
| 267 | NP_IPv4_PROTOCOL_EGP() => 'EGP', | ||||||||||||
| 268 | NP_IPv4_PROTOCOL_IGRP() => 'IGRP', | ||||||||||||
| 269 | NP_IPv4_PROTOCOL_CHAOS() => 'CHAOS', | ||||||||||||
| 270 | NP_IPv4_PROTOCOL_UDP() => 'UDP', | ||||||||||||
| 271 | NP_IPv4_PROTOCOL_IDP() => 'IDP', | ||||||||||||
| 272 | NP_IPv4_PROTOCOL_DCCP() => 'DCCP', | ||||||||||||
| 273 | NP_IPv4_PROTOCOL_IPv6() => 'IPv6', | ||||||||||||
| 274 | NP_IPv4_PROTOCOL_IPv6ROUTING() => 'IPv6Routing', | ||||||||||||
| 275 | NP_IPv4_PROTOCOL_IPv6FRAGMENT() => 'IPv6Fragment', | ||||||||||||
| 276 | NP_IPv4_PROTOCOL_IDRP() => 'IDRP', | ||||||||||||
| 277 | NP_IPv4_PROTOCOL_RSVP() => 'RSVP', | ||||||||||||
| 278 | NP_IPv4_PROTOCOL_GRE() => 'GRE', | ||||||||||||
| 279 | NP_IPv4_PROTOCOL_ESP() => 'ESP', | ||||||||||||
| 280 | NP_IPv4_PROTOCOL_AH() => 'AH', | ||||||||||||
| 281 | NP_IPv4_PROTOCOL_ICMPv6() => 'ICMPv6', | ||||||||||||
| 282 | NP_IPv4_PROTOCOL_EIGRP() => 'EIGRP', | ||||||||||||
| 283 | NP_IPv4_PROTOCOL_OSPF() => 'OSPF', | ||||||||||||
| 284 | NP_IPv4_PROTOCOL_ETHERIP() => 'ETHERIP', | ||||||||||||
| 285 | NP_IPv4_PROTOCOL_PIM() => 'PIM', | ||||||||||||
| 286 | NP_IPv4_PROTOCOL_VRRP() => 'VRRP', | ||||||||||||
| 287 | NP_IPv4_PROTOCOL_STP() => 'STP', | ||||||||||||
| 288 | NP_IPv4_PROTOCOL_SCTP() => 'SCTP', | ||||||||||||
| 289 | }; | ||||||||||||
| 290 | |||||||||||||
| 291 | $types->{shift->[$__protocol]} || $self->[$__nextLayer]; | ||||||||||||
| 292 | } | ||||||||||||
| 293 | |||||||||||||
| 294 | sub getKey { | ||||||||||||
| 295 | my $self = shift; | ||||||||||||
| 296 | $self->layer.':'.$self->[$__src].'-'.$self->[$__dst]; | ||||||||||||
| 297 | } | ||||||||||||
| 298 | |||||||||||||
| 299 | sub getKeyReverse { | ||||||||||||
| 300 | my $self = shift; | ||||||||||||
| 301 | $self->layer.':'.$self->[$__dst].'-'.$self->[$__src]; | ||||||||||||
| 302 | } | ||||||||||||
| 303 | |||||||||||||
| 304 | sub print { | ||||||||||||
| 305 | my $self = shift; | ||||||||||||
| 306 | |||||||||||||
| 307 | my $l = $self->layer; | ||||||||||||
| 308 | my $buf = sprintf | ||||||||||||
| 309 | "$l: version:%d hlen:%d tos:0x%02x length:%d id:%d\n". | ||||||||||||
| 310 | "$l: flags:0x%02x offset:%d ttl:%d protocol:0x%02x checksum:0x%04x\n". | ||||||||||||
| 311 | "$l: src:%s dst:%s", | ||||||||||||
| 312 | $self->[$__version], $self->[$__hlen], $self->[$__tos], | ||||||||||||
| 313 | $self->[$__length], $self->[$__id], $self->[$__flags], | ||||||||||||
| 314 | $self->[$__offset], $self->[$__ttl], $self->[$__protocol], | ||||||||||||
| 315 | $self->[$__checksum], $self->[$__src], $self->[$__dst]; | ||||||||||||
| 316 | |||||||||||||
| 317 | if ($self->[$__options]) { | ||||||||||||
| 318 | $buf .= sprintf "\n$l: $i: optionsLength:%d options:%s", | ||||||||||||
| 319 | $self->getOptionsLength, | ||||||||||||
| 320 | CORE::unpack('H*', $self->[$__options]); | ||||||||||||
| 321 | } | ||||||||||||
| 322 | |||||||||||||
| 323 | $buf; | ||||||||||||
| 324 | } | ||||||||||||
| 325 | |||||||||||||
| 326 | 1; | ||||||||||||
| 327 | |||||||||||||
| 328 | __END__ | ||||||||||||