# # $Id: Desc.pm,v 1.3.2.11 2006/11/12 20:28:34 gomor Exp $ # package Net::Packet::Desc; use strict; use warnings; require Exporter; require Class::Gomor::Array; our @ISA = qw(Exporter Class::Gomor::Array); use Net::Packet::Env qw($Env); use Net::Packet::Consts qw(:desc); our @AS = qw( dev ip ip6 mac gatewayIp gatewayMac target targetMac protocol family _io _sockaddr ); __PACKAGE__->cgBuildIndices; __PACKAGE__->cgBuildAccessorsScalar(\@AS); sub new { my $self = shift->SUPER::new( dev => $Env->dev, ip => $Env->ip, ip6 => $Env->ip6, mac => $Env->mac, gatewayIp => $Env->gatewayIp, @_, ); $self->cgDebugPrint(1, "dev: [@{[$self->dev]}]\n". "ip: [@{[$self->ip]}]\n". "mac: [@{[$self->mac]}]"); $self->cgDebugPrint(1, "ip6: [@{[$self->ip6]}]") if $self->ip6; $self->cgDebugPrint(1, "gatewayIp: [@{[$self->gatewayIp]}]") if $self->gatewayIp; $Env->desc($self) unless $Env->noDescAutoSet; $self; } sub send { shift->_io->send(shift()) } sub close { shift->_io->close } # # Helpers # sub _isDesc { ref(shift) =~ /@{[shift()]}/ } sub isDescL2 { shift->_isDesc(NP_DESC_L2) } sub isDescL3 { shift->_isDesc(NP_DESC_L3) } sub isDescL4 { shift->_isDesc(NP_DESC_L4) } 1; __END__ =head1 NAME Net::Packet::Desc - base class for all desc modules =head1 DESCRIPTION This is the base class for B, B and B modules. It just provides those layers with inheritable attributes and methods. A descriptor is required when you want to send frames over network. =head1 ATTRIBUTES =over 4 =item B Network device to use to send frames. Default to use B set in default B<$Env> object. =item B Same as above for IP. This is the source IP address to use. =item B Same as above for IPv6. This is the source IPv6 address to use. =item B Same as above for MAC. This is the source MAC address to use. =item B Same as above, for gateway IP address. =item B Same as above, for gateway MAC address. It is not automatically set here. It is automatically set only under Windows, when using a B object. =item B Used to create a B and B. At these layers, one MUST specifiy the target IP address to tell kernel where to send frames. =item B Used to automatically build layer 2 when using a B object under Windows. =item B This is the transport protocol to use (TCP, UDP, ...). Used in B objects. Default to TCP. =item B Same as abose, to tell which network protocol to use (IPv4, IPv6). =back =head1 METHODS =over 4 =item B (scalar) Send the raw data passed as a parameter. =item B Close the descriptor. =item B =item B =item B Returns true if Desc is of specified type, false otherwise. =back =head1 CONSTANTS Load them: use Net::Packet::Consts qw(:desc); =over 4 =item B =item B =item B =item B =item B =item B =item B =item B =item B =item B =back =head1 AUTHOR Patrice EGomoRE Auffret =head1 COPYRIGHT AND LICENSE Copyright (c) 2004-2006, Patrice EGomoRE Auffret You may distribute this module under the terms of the Artistic license. See LICENSE.Artistic file in the source distribution archive. =head1 RELATED MODULES L, L, L =cut