Net::Frame::Layer::PPP - Point-to-Point Protocol layer object


Net-Frame documentation Contained in the Net-Frame distribution.

Index


Code Index:

NAME

Top

Net::Frame::Layer::PPP - Point-to-Point Protocol layer object

SYNOPSIS

Top

   use Net::Frame::Layer::PPP qw(:consts);

   # Build a layer
   my $layer = Net::Frame::Layer::PPP->new(
      address  => 0xff,
      control  => 0x03,
      protocol => NF_PPP_PROTOCOL_IPv4,
   );
   $layer->pack;

   print 'RAW: '.$layer->dump."\n";

   # Read a raw layer
   my $layer = Net::Frame::Layer::PPP->new(raw => $raw);

   print $layer->print."\n";
   print 'PAYLOAD: '.unpack('H*', $layer->payload)."\n"
      if $layer->payload;

DESCRIPTION

Top

This modules implements the encoding and decoding of the Point-to-Point Protocol layer.

See also Net::Frame::Layer for other attributes and methods.

ATTRIBUTES

Top

address - 8 bits
control - 8 bits
protocol - 16 bits

The following are inherited attributes. See Net::Frame::Layer for more information.

raw
payload
nextLayer

METHODS

Top

new
new (hash)

Object constructor. You can pass attributes that will overwrite default ones. See SYNOPSIS for default values.

The following are inherited methods. Some of them may be overriden in this layer, and some others may not be meaningful in this layer. See Net::Frame::Layer for more information.

layer
computeLengths
computeChecksums
pack
unpack
encapsulate
getLength
getPayloadLength
print
dump

CONSTANTS

Top

Load them: use Net::Frame::Layer::PPP qw(:consts);

NF_PPP_PROTOCOL_IPv4
NF_PPP_PROTOCOL_DDP
NF_PPP_PROTOCOL_IPX
NF_PPP_PROTOCOL_IPv6
NF_PPP_PROTOCOL_CDP
NF_PPP_PROTOCOL_PPPLCP

Various supported encapsulated layer types.

SEE ALSO

Top

Net::Frame::Layer

AUTHOR

Top

Patrice <GomoR> Auffret

COPYRIGHT AND LICENSE

Top


Net-Frame documentation Contained in the Net-Frame distribution.

#
# $Id: PPP.pm 333 2011-02-16 10:47:33Z gomor $
#
package Net::Frame::Layer::PPP;
use strict;
use warnings;

use Net::Frame::Layer qw(:consts);
require Exporter;
our @ISA = qw(Net::Frame::Layer Exporter);

our %EXPORT_TAGS = (
   consts => [qw(
      NF_PPP_HDR_LEN
      NF_PPP_PROTOCOL_IPv4
      NF_PPP_PROTOCOL_DDP
      NF_PPP_PROTOCOL_IPX
      NF_PPP_PROTOCOL_IPv6
      NF_PPP_PROTOCOL_CDP
      NF_PPP_PROTOCOL_PPPLCP
   )],
);
our @EXPORT_OK = (
   @{$EXPORT_TAGS{consts}},
);

use constant NF_PPP_HDR_LEN         => 4;
use constant NF_PPP_PROTOCOL_IPv4   => 0x0021;
use constant NF_PPP_PROTOCOL_DDP    => 0x0029;
use constant NF_PPP_PROTOCOL_IPX    => 0x002b;
use constant NF_PPP_PROTOCOL_IPv6   => 0x0057;
use constant NF_PPP_PROTOCOL_CDP    => 0x0207;
use constant NF_PPP_PROTOCOL_PPPLCP => 0xc021;

our @AS = qw(
   address
   control
   protocol
);
__PACKAGE__->cgBuildIndices;
__PACKAGE__->cgBuildAccessorsScalar(\@AS);

no strict 'vars';

sub new {
   shift->SUPER::new(
      address  => 0xff,
      control  => 0x03,
      protocol => NF_PPP_PROTOCOL_IPv4,
      @_,
   );
}

sub getLength { NF_PPP_HDR_LEN }

sub pack {
   my $self = shift;

   $self->[$__raw] = $self->SUPER::pack('CCn', $self->[$__address],
      $self->[$__control], $self->[$__protocol])
         or return undef;

   $self->[$__raw];
}

sub unpack {
   my $self = shift;

   my ($address, $control, $protocol, $payload) =
      $self->SUPER::unpack('CCn a*', $self->[$__raw])
         or return undef;

   $self->[$__address]  = $address;
   $self->[$__control]  = $control;
   $self->[$__protocol] = $protocol;
   $self->[$__payload]  = $payload;

   $self;
}

our $Next = {
   NF_PPP_PROTOCOL_IPv4()   => 'IPv4',
   NF_PPP_PROTOCOL_DDP()    => 'DDP',
   NF_PPP_PROTOCOL_IPX()    => 'IPX',
   NF_PPP_PROTOCOL_IPv6()   => 'IPv6',
   NF_PPP_PROTOCOL_CDP()    => 'CDP',
   NF_PPP_PROTOCOL_PPPLCP() => 'PPPLCP',
};

sub encapsulate {
   my $self = shift;

   return $self->[$__nextLayer] if $self->[$__nextLayer];

   return $Next->{$self->[$__protocol]} || NF_LAYER_UNKNOWN;
}

sub print {
   my $self = shift;

   my $l = $self->layer;
   sprintf "$l: address:0x%02x  control:0x%02x  protocol:0x%04x",
      $self->[$__address], $self->[$__control], $self->[$__protocol];
}

1;

__END__