| 1 | # | ||||||||||
| 2 | # $Id: PPP.pm,v 1.6 2006/12/06 21:19:40 gomor Exp $ | ||||||||||
| 3 | # | ||||||||||
| 4 | package Net::Frame::PPP; | ||||||||||
| 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_PPP_HDR_LEN | ||||||||||
| 15 | NP_PPP_PROTOCOL_USER | ||||||||||
| 16 | NP_PPP_PROTOCOL_IPv4 | ||||||||||
| 17 | NP_PPP_PROTOCOL_DDP | ||||||||||
| 18 | NP_PPP_PROTOCOL_IPX | ||||||||||
| 19 | NP_PPP_PROTOCOL_IPv6 | ||||||||||
| 20 | NP_PPP_PROTOCOL_CDP | ||||||||||
| 21 | NP_PPP_PROTOCOL_PPPLCP | ||||||||||
| 22 | )], | ||||||||||
| 23 | ); | ||||||||||
| 24 | our @EXPORT_OK = ( | ||||||||||
| 25 | 2 | @{$EXPORT_TAGS{consts}}, | |||||||||
| 26 | ); | ||||||||||
| 27 | |||||||||||
| 28 | 2 | ▶ | use constant NP_PPP_HDR_LEN => 4; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 29 | 2 | ▶ | use constant NP_PPP_PROTOCOL_USER => 0x0000; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 30 | 2 | ▶ | use constant NP_PPP_PROTOCOL_IPv4 => 0x0021; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 31 | 2 | ▶ | use constant NP_PPP_PROTOCOL_DDP => 0x0029; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 32 | 2 | ▶ | use constant NP_PPP_PROTOCOL_IPX => 0x002b; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 33 | 2 | ▶ | use constant NP_PPP_PROTOCOL_IPv6 => 0x0057; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 34 | 2 | ▶ | use constant NP_PPP_PROTOCOL_CDP => 0x0207; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 35 | 2 | ▶ | use constant NP_PPP_PROTOCOL_PPPLCP => 0xc021; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 36 | |||||||||||
| 37 | 2 | our @AS = qw( | |||||||||
| 38 | address | ||||||||||
| 39 | control | ||||||||||
| 40 | protocol | ||||||||||
| 41 | ); | ||||||||||
| 42 | 2 | __PACKAGE__->cgBuildIndices; | |||||||||
| 43 | 2 | __PACKAGE__->cgBuildAccessorsScalar(\@AS); | |||||||||
| 44 | |||||||||||
| 45 | 2 | ▶ | no strict 'vars'; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 46 | |||||||||||
| 47 | sub new { | ||||||||||
| 48 | shift->SUPER::new( | ||||||||||
| 49 | 1 | ▶ | address => 0xff, | ||||||||
|
Subroutine
new: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||
| 50 | control => 0x03, | ||||||||||
| 51 | protocol => NP_PPP_PROTOCOL_IPv4, | ||||||||||
| 52 | @_, | ||||||||||
| 53 | ); | ||||||||||
| 54 | } | ||||||||||
| 55 | |||||||||||
| 56 | 0 | ▶ | sub getLength { NP_PPP_HDR_LEN } | ||||||||
|
Subroutine
getLength: 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.1
Pod
documented
| |||||||||||
| 60 | |||||||||||
| 61 | 1 | ▶ | $self->[$__raw] = $self->SUPER::pack('CCn', $self->[$__address], | ||||||||
|
Branch: 1 branch
| |||||||||||
| 62 | $self->[$__control], $self->[$__protocol]) | ||||||||||
| 63 | or return undef; | ||||||||||
| 64 | |||||||||||
| 65 | 1 | $self->[$__raw]; | |||||||||
| 66 | } | ||||||||||
| 67 | |||||||||||
| 68 | sub unpack { | ||||||||||
| 69 | 1 | ▶ | my $self = shift; | ||||||||
|
Subroutine
unpack: called CC=2 SCAR=7.0
Pod
documented
| |||||||||||
| 70 | |||||||||||
| 71 | 1 | ▶ | my ($address, $control, $protocol, $payload) = | ||||||||
|
Branch: 1 branch
| |||||||||||
| 72 | $self->SUPER::unpack('CCn a*', $self->[$__raw]) | ||||||||||
| 73 | or return undef; | ||||||||||
| 74 | |||||||||||
| 75 | 1 | $self->[$__address] = $address; | |||||||||
| 76 | 1 | $self->[$__control] = $control; | |||||||||
| 77 | 1 | $self->[$__protocol] = $protocol; | |||||||||
| 78 | 1 | $self->[$__payload] = $payload; | |||||||||
| 79 | |||||||||||
| 80 | 1 | $self; | |||||||||
| 81 | } | ||||||||||
| 82 | |||||||||||
| 83 | sub encapsulate { | ||||||||||
| 84 | 1 | ▶ | my $types = { | ||||||||
|
Subroutine
encapsulate: called CC=2 SCAR=7.2
Pod
documented
| |||||||||||
| 85 | NP_PPP_PROTOCOL_IPv4() => 'IPv4', | ||||||||||
| 86 | NP_PPP_PROTOCOL_DDP() => 'DDP', | ||||||||||
| 87 | NP_PPP_PROTOCOL_IPX() => 'IPX', | ||||||||||
| 88 | NP_PPP_PROTOCOL_IPv6() => 'IPv6', | ||||||||||
| 89 | NP_PPP_PROTOCOL_CDP() => 'CDP', | ||||||||||
| 90 | NP_PPP_PROTOCOL_PPPLCP() => 'PPPLCP', | ||||||||||
| 91 | }; | ||||||||||
| 92 | |||||||||||
| 93 | 1 | ▶ | $types->{shift->[$__protocol]} || $self->[$__nextLayer]; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 94 | } | ||||||||||
| 95 | |||||||||||
| 96 | sub print { | ||||||||||
| 97 | 1 | ▶ | my $self = shift; | ||||||||
|
Subroutine
print: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||
| 98 | |||||||||||
| 99 | 1 | my $l = $self->layer; | |||||||||
| 100 | 1 | sprintf "$l: address:0x%02x control:0x%02x protocol:0x%04x", | |||||||||
| 101 | $self->[$__address], $self->[$__control], $self->[$__protocol]; | ||||||||||
| 102 | } | ||||||||||
| 103 | |||||||||||
| 104 | 2 | 1; | |||||||||
| 105 | |||||||||||
| 106 | __END__ | ||||||||||