Net::Packet::Desc - base class for all desc modules


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

Index


Code Index:

NAME

Top

Net::Packet::Desc - base class for all desc modules

DESCRIPTION

Top

This is the base class for Net::Packet::DescL2, Net::Packet::DescL3 and Net::Packet::DescL4 modules.

It just provides those layers with inheritable attributes and methods.

A descriptor is required when you want to send frames over network.

ATTRIBUTES

Top

dev

Network device to use to send frames. Default to use dev set in default $Env object.

ip

Same as above for IP. This is the source IP address to use.

ip6

Same as above for IPv6. This is the source IPv6 address to use.

mac

Same as above for MAC. This is the source MAC address to use.

gatewayIp

Same as above, for gateway IP address.

gatewayMac

Same as above, for gateway MAC address. It is not automatically set here. It is automatically set only under Windows, when using a Net::Packet::DescL3 object.

target

Used to create a Net::Packet::DescL3 and Net::Packet::DescL4. At these layers, one MUST specifiy the target IP address to tell kernel where to send frames.

targetMac

Used to automatically build layer 2 when using a Net::Packet::DescL3 object under Windows.

protocol

This is the transport protocol to use (TCP, UDP, ...). Used in Net::Packet::DescL4 objects. Default to TCP.

family

Same as abose, to tell which network protocol to use (IPv4, IPv6).

METHODS

Top

send (scalar)

Send the raw data passed as a parameter.

close

Close the descriptor.

isDescL2
isDescL3
isDescL4

Returns true if Desc is of specified type, false otherwise.

CONSTANTS

Top

Load them: use Net::Packet::Consts qw(:desc);

NP_DESC_IPPROTO_IP
NP_DESC_IPPROTO_IPv6
NP_DESC_IPPROTO_RAW
NP_DESC_IPPROTO_TCP
NP_DESC_IPPROTO_UDP
NP_DESC_IPPROTO_ICMPv4
NP_DESC_IP_HDRINCL
NP_DESC_L2
NP_DESC_L3
NP_DESC_L4

AUTHOR

Top

Patrice <GomoR> Auffret

COPYRIGHT AND LICENSE

Top

RELATED MODULES

Top


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

#
# $Id: Desc.pm 1640 2009-11-09 17:58:27Z gomor $
#
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__