| 1 | # | ||||||||||
| 2 | # $Id: NULL.pm,v 1.4 2006/12/06 21:19:27 gomor Exp $ | ||||||||||
| 3 | # | ||||||||||
| 4 | package Net::Frame::NULL; | ||||||||||
| 5 | 2 | ▶ | use strict; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 6 | 2 | ▶ | use warnings; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 7 | |||||||||||
| 8 | 2 | ▶ | use Net::Frame::Layer qw(:consts); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 9 | 2 | require Exporter; | |||||||||
| 10 | 2 | our @ISA = qw(Net::Frame::Layer Exporter); | |||||||||
| 11 | |||||||||||
| 12 | 2 | our %EXPORT_TAGS = ( | |||||||||
| 13 | consts => [qw( | ||||||||||
| 14 | NP_NULL_HDR_LEN | ||||||||||
| 15 | NP_NULL_TYPE_USER | ||||||||||
| 16 | NP_NULL_TYPE_IPv4 | ||||||||||
| 17 | NP_NULL_TYPE_IPv6 | ||||||||||
| 18 | )], | ||||||||||
| 19 | ); | ||||||||||
| 20 | our @EXPORT_OK = ( | ||||||||||
| 21 | 2 | @{$EXPORT_TAGS{consts}}, | |||||||||
| 22 | ); | ||||||||||
| 23 | |||||||||||
| 24 | 2 | ▶ | use constant NP_NULL_HDR_LEN => 4; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 25 | 2 | ▶ | use constant NP_NULL_TYPE_USER => 0x00000000; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 26 | 2 | ▶ | use constant NP_NULL_TYPE_IPv4 => 0x02000000; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 27 | 2 | ▶ | use constant NP_NULL_TYPE_IPv6 => 0x1c000000; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 28 | |||||||||||
| 29 | 2 | our @AS = qw( | |||||||||
| 30 | type | ||||||||||
| 31 | ); | ||||||||||
| 32 | 2 | __PACKAGE__->cgBuildIndices; | |||||||||
| 33 | 2 | __PACKAGE__->cgBuildAccessorsScalar(\@AS); | |||||||||
| 34 | |||||||||||
| 35 | 2 | ▶ | no strict 'vars'; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 36 | |||||||||||
| 37 | sub new { | ||||||||||
| 38 | shift->SUPER::new( | ||||||||||
| 39 | 1 | ▶ | type => NP_NULL_TYPE_IPv4, | ||||||||
|
Subroutine
new: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||
| 40 | @_, | ||||||||||
| 41 | ); | ||||||||||
| 42 | } | ||||||||||
| 43 | |||||||||||
| 44 | 0 | ▶ | sub getLength { NP_NULL_HDR_LEN } | ||||||||
|
Subroutine
getLength: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||
| 45 | |||||||||||
| 46 | sub pack { | ||||||||||
| 47 | 1 | ▶ | my $self = shift; | ||||||||
|
Subroutine
pack: called CC=2 SCAR=7.1
Pod
documented
| |||||||||||
| 48 | 1 | ▶ | $self->[$__raw] = $self->SUPER::pack('N', $self->[$__type]) | ||||||||
|
Branch: 1 branch
| |||||||||||
| 49 | or return undef; | ||||||||||
| 50 | 1 | $self->[$__raw]; | |||||||||
| 51 | } | ||||||||||
| 52 | |||||||||||
| 53 | sub unpack { | ||||||||||
| 54 | 1 | ▶ | my $self = shift; | ||||||||
|
Subroutine
unpack: called CC=2 SCAR=7.0
Pod
documented
| |||||||||||
| 55 | |||||||||||
| 56 | 1 | ▶ | my ($type, $payload) = $self->SUPER::unpack('N a*', $self->[$__raw]) | ||||||||
|
Branch: 1 branch
| |||||||||||
| 57 | or return undef; | ||||||||||
| 58 | |||||||||||
| 59 | 1 | $self->[$__type] = $type; | |||||||||
| 60 | 1 | $self->[$__payload] = $payload; | |||||||||
| 61 | |||||||||||
| 62 | 1 | $self; | |||||||||
| 63 | } | ||||||||||
| 64 | |||||||||||
| 65 | sub encapsulate { | ||||||||||
| 66 | 1 | ▶ | my $types = { | ||||||||
|
Subroutine
encapsulate: called CC=2 SCAR=7.2
Pod
documented
| |||||||||||
| 67 | NP_NULL_TYPE_IPv4() => 'IPv4', | ||||||||||
| 68 | NP_NULL_TYPE_IPv6() => 'IPv6', | ||||||||||
| 69 | }; | ||||||||||
| 70 | |||||||||||
| 71 | 1 | ▶ | $types->{shift->[$__type]} || $self->[$__nextLayer]; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 72 | } | ||||||||||
| 73 | |||||||||||
| 74 | sub print { | ||||||||||
| 75 | 1 | ▶ | my $self = shift; | ||||||||
|
Subroutine
print: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||
| 76 | |||||||||||
| 77 | 1 | my $l = $self->layer; | |||||||||
| 78 | 1 | sprintf "$l: type:0x%04x", $self->type; | |||||||||
| 79 | } | ||||||||||
| 80 | |||||||||||
| 81 | 2 | 1; | |||||||||
| 82 | |||||||||||
| 83 | __END__ | ||||||||||