| 1 | # | ||||||||||
| 2 | # $Id: PPPoES.pm 4 2010-06-03 13:02:31Z gomor $ | ||||||||||
| 3 | # | ||||||||||
| 4 | package Net::Frame::Layer::PPPoES; | ||||||||||
| 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 | our $VERSION = '1.01'; | |||||||||
| 9 | |||||||||||
| 10 | 3 | ▶ | use Net::Frame::Layer qw(:consts); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 11 | 3 | require Exporter; | |||||||||
| 12 | 3 | our @ISA = qw(Net::Frame::Layer Exporter); | |||||||||
| 13 | |||||||||||
| 14 | 3 | our %EXPORT_TAGS = ( | |||||||||
| 15 | consts => [qw( | ||||||||||
| 16 | NF_PPPoE_HDR_LEN | ||||||||||
| 17 | NF_PPPoE_PPP_PROTOCOL_IPv4 | ||||||||||
| 18 | NF_PPPoE_PPP_PROTOCOL_PPPLCP | ||||||||||
| 19 | )], | ||||||||||
| 20 | ); | ||||||||||
| 21 | our @EXPORT_OK = ( | ||||||||||
| 22 | 3 | @{$EXPORT_TAGS{consts}}, | |||||||||
| 23 | ); | ||||||||||
| 24 | |||||||||||
| 25 | 3 | ▶ | use constant NF_PPPoE_HDR_LEN => 8; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 26 | 3 | ▶ | use constant NF_PPPoE_PPP_PROTOCOL_IPv4 => 0x0021; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 27 | 3 | ▶ | use constant NF_PPPoE_PPP_PROTOCOL_PPPLCP => 0xc021; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 28 | |||||||||||
| 29 | 3 | our @AS = qw( | |||||||||
| 30 | version | ||||||||||
| 31 | type | ||||||||||
| 32 | code | ||||||||||
| 33 | sessionId | ||||||||||
| 34 | payloadLength | ||||||||||
| 35 | pppProtocol | ||||||||||
| 36 | ); | ||||||||||
| 37 | 3 | __PACKAGE__->cgBuildIndices; | |||||||||
| 38 | 3 | __PACKAGE__->cgBuildAccessorsScalar(\@AS); | |||||||||
| 39 | |||||||||||
| 40 | 3 | require Bit::Vector; | |||||||||
| 41 | |||||||||||
| 42 | sub new { | ||||||||||
| 43 | shift->SUPER::new( | ||||||||||
| 44 | 1 | ▶ | version => 1, | ||||||||
|
Subroutine
new: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||
| 45 | type => 1, | ||||||||||
| 46 | code => 0, | ||||||||||
| 47 | sessionId => 1, | ||||||||||
| 48 | payloadLength => 0, | ||||||||||
| 49 | pppProtocol => NF_PPPoE_PPP_PROTOCOL_IPv4, | ||||||||||
| 50 | @_, | ||||||||||
| 51 | ); | ||||||||||
| 52 | } | ||||||||||
| 53 | |||||||||||
| 54 | 0 | ▶ | sub getLength { NF_PPPoE_HDR_LEN } | ||||||||
|
Subroutine
getLength: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||
| 55 | |||||||||||
| 56 | 0 | ▶ | sub getPayloadLength { shift->payloadLength } | ||||||||
|
Subroutine
getPayloadLength: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||
| 57 | |||||||||||
| 58 | sub pack { | ||||||||||
| 59 | 1 | ▶ | my $self = shift; | ||||||||
|
Subroutine
pack: called CC=2 SCAR=7.0
Pod
documented
| |||||||||||
| 60 | |||||||||||
| 61 | 1 | my $version = Bit::Vector->new_Dec(4, $self->version); | |||||||||
| 62 | 1 | my $type = Bit::Vector->new_Dec(4, $self->type); | |||||||||
| 63 | 1 | my $v8 = $version->Concat_List($type); | |||||||||
| 64 | |||||||||||
| 65 | 1 | ▶ | $self->raw($self->SUPER::pack('CCnnn', | ||||||||
|
Branch: 1 branch
| |||||||||||
| 66 | $v8->to_Dec, | ||||||||||
| 67 | $self->code, | ||||||||||
| 68 | $self->sessionId, | ||||||||||
| 69 | $self->payloadLength, | ||||||||||
| 70 | $self->pppProtocol, | ||||||||||
| 71 | )) or return undef; | ||||||||||
| 72 | |||||||||||
| 73 | 1 | $self->raw; | |||||||||
| 74 | } | ||||||||||
| 75 | |||||||||||
| 76 | sub unpack { | ||||||||||
| 77 | 1 | ▶ | my $self = shift; | ||||||||
|
Subroutine
unpack: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||
| 78 | |||||||||||
| 79 | 1 | ▶ | my ($versionType, $code, $sessionId, $payloadLength, $pppProtocol, $payload) | ||||||||
|
Branch: 1 branch
| |||||||||||
| 80 | = $self->SUPER::unpack('CCnnn a*', $self->raw) | ||||||||||
| 81 | or return undef; | ||||||||||
| 82 | |||||||||||
| 83 | 1 | my $v8 = Bit::Vector->new_Dec(8, $versionType); | |||||||||
| 84 | 1 | $self->version($v8->Chunk_Read(4, 0)); | |||||||||
| 85 | 1 | $self->type($v8->Chunk_Read(4, 4)); | |||||||||
| 86 | |||||||||||
| 87 | 1 | $self->code($code); | |||||||||
| 88 | 1 | $self->sessionId($sessionId); | |||||||||
| 89 | 1 | $self->payloadLength($payloadLength); | |||||||||
| 90 | 1 | $self->pppProtocol($pppProtocol); | |||||||||
| 91 | |||||||||||
| 92 | 1 | $self->payload($payload); | |||||||||
| 93 | |||||||||||
| 94 | 1 | $self; | |||||||||
| 95 | } | ||||||||||
| 96 | |||||||||||
| 97 | sub encapsulate { | ||||||||||
| 98 | 0 | ▶ | my $self = shift; | ||||||||
|
Subroutine
encapsulate: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||
| 99 | |||||||||||
| 100 | 0 | ▶ | return $self->nextLayer if $self->nextLayer; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 101 | |||||||||||
| 102 | 0 | my $types = { | |||||||||
| 103 | NF_PPPoE_PPP_PROTOCOL_IPv4() => 'IPv4', | ||||||||||
| 104 | NF_PPPoE_PPP_PROTOCOL_PPPLCP() => 'PPPLCP', | ||||||||||
| 105 | }; | ||||||||||
| 106 | |||||||||||
| 107 | 0 | ▶ | $types->{$self->pppProtocol} || NF_LAYER_UNKNOWN; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 108 | } | ||||||||||
| 109 | |||||||||||
| 110 | sub print { | ||||||||||
| 111 | 0 | ▶ | my $self = shift; | ||||||||
|
Subroutine
print: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||
| 112 | |||||||||||
| 113 | 0 | my $l = $self->layer; | |||||||||
| 114 | 0 | sprintf "$l: version:%d type:%d code:0x%02x sessionId:0x%04x\n". | |||||||||
| 115 | "$l: payloadLength:%d pppProtocol:0x%04x", | ||||||||||
| 116 | $self->version, | ||||||||||
| 117 | $self->type, | ||||||||||
| 118 | $self->code, | ||||||||||
| 119 | $self->sessionId, | ||||||||||
| 120 | $self->payloadLength, | ||||||||||
| 121 | $self->pppProtocol, | ||||||||||
| 122 | ; | ||||||||||
| 123 | } | ||||||||||
| 124 | |||||||||||
| 125 | 3 | 1; | |||||||||
| 126 | |||||||||||
| 127 | __END__ | ||||||||||