| Net-Packet documentation | Contained in the Net-Packet distribution. |
Net::Packet::PPPoE - PPP-over-Ethernet layer 3 object
use Net::Packet::Consts qw(:pppoe);
require Net::Packet::PPPoE;
# Build a layer
my $layer = Net::Packet::PPPoE->new(
version => 1,
type => 1,
code => 0,
sessionId => 1,
payloadLength => 0,
pppProtocol => NP_PPPoE_PPP_PROTOCOL_IPv4,
);
$layer->pack;
print 'RAW: '.unpack('H*', $layer->raw)."\n";
# Read a raw layer
my $layer = Net::Packet::PPPoE->new(raw => $raw);
print $layer->print."\n";
print 'PAYLOAD: '.unpack('H*', $layer->payload)."\n"
if $layer->payload;
This modules implements the encoding and decoding of the PPP-over-Ethernet layer.
See also Net::Packet::Layer and Net::Packet::Layer3 for other attributes and methods.
For this last attribute, we can note that it is included in the computation of payloadLength.
Object constructor. You can pass attributes that will overwrite default ones. Default values:
version: 1
type: 1
code: 0
sessionId: 1
payloadLength: 0
pppProtocol: NP_PPPoE_PPP_PROTOCOL_IPv4
Packs all attributes into a raw format, in order to inject to network. Returns 1 on success, undef otherwise.
Unpacks raw data from network and stores attributes into the object. Returns 1 on success, undef otherwise.
Load them: use Net::Packet::Consts qw(:pppoe);
PPPoE header length.
Various supported encapsulated PPP protocols.
Patrice <GomoR> Auffret
Copyright (c) 2004-2009, Patrice <GomoR> Auffret
You may distribute this module under the terms of the Artistic license. See LICENSE.Artistic file in the source distribution archive.
NetPacket, Net::RawIP, Net::RawSock
| Net-Packet documentation | Contained in the Net-Packet distribution. |
# # $Id: PPPoE.pm 1641 2009-11-09 18:01:24Z gomor $ # package Net::Packet::PPPoE; use strict; use warnings; require Net::Packet::Layer3; our @ISA = qw(Net::Packet::Layer3); use Net::Packet::Consts qw(:pppoe :layer); require Bit::Vector; our @AS = qw( version type code sessionId payloadLength pppProtocol ); __PACKAGE__->cgBuildIndices; __PACKAGE__->cgBuildAccessorsScalar(\@AS); no strict 'vars'; sub new { shift->SUPER::new( version => 1, type => 1, code => 0, sessionId => 1, payloadLength => 0, pppProtocol => NP_PPPoE_PPP_PROTOCOL_IPv4, @_, ); } sub getLength { NP_PPPoE_HDR_LEN } sub getPayloadLength { shift->[$__payloadLength] } sub pack { my $self = shift; my $version = Bit::Vector->new_Dec(4, $self->[$__version]); my $type = Bit::Vector->new_Dec(4, $self->[$__type]); my $v8 = $version->Concat_List($type); $self->[$__raw] = $self->SUPER::pack('CCnnna*', $v8->to_Dec, $self->[$__code], $self->[$__sessionId], $self->[$__payloadLength], $self->[$__pppProtocol], $self->[$__payload], ) or return undef; 1; } sub unpack { my $self = shift; my ($versionType, $code, $sessionId, $payloadLength, $pppProtocol, $payload) = $self->SUPER::unpack('CCnnn a*', $self->[$__raw]) or return undef; my $v8 = Bit::Vector->new_Dec(8, $versionType); $self->version($v8->Chunk_Read(4, 0)); $self->type($v8->Chunk_Read(4, 4)); $self->[$__code] = $code; $self->[$__sessionId] = $sessionId; $self->[$__payloadLength] = $payloadLength; $self->[$__pppProtocol] = $pppProtocol; $self->[$__payload] = $payload; 1; } sub encapsulate { my $types = { NP_PPPoE_PPP_PROTOCOL_IPv4() => NP_LAYER_IPv4(), NP_PPPoE_PPP_PROTOCOL_PPPLCP() => NP_LAYER_PPPLCP(), }; $types->{shift->[$__pppProtocol]} || NP_LAYER_UNKNOWN(); } sub print { my $self = shift; my $l = $self->layer; my $i = $self->is; sprintf "$l:+$i: version:%d type:%d code:0x%02x sessionId:0x%04x\n". "$l: $i: payloadLength:%d pppProtocol:0x%04x", $self->[$__version], $self->[$__type], $self->[$__code], $self->[$__sessionId], $self->[$__payloadLength], $self->[$__pppProtocol]; } 1; __END__