The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.

NAME

Net::Frame::Layer::ICMPv4 - Internet Control Message Protocol v4 layer object

SYNOPSIS

   use Net::Frame::Simple;
   use Net::Frame::Layer::ICMPv4 qw(:consts);

   my $icmp = Net::Frame::Layer::ICMPv4->new(
      type     => NF_ICMPv4_TYPE_ECHO_REQUEST,
      code     => NF_ICMPv4_CODE_ZERO,
      checksum => 0,
   );

   # Build an ICMPv4 echo-request
   use Net::Frame::Layer::ICMPv4::Echo;
   my $echo = Net::Frame::Layer::ICMPv4::Echo->new(
      payload => 'echo'
   );

   my $echoReq = Net::Frame::Simple->new(
      layers => [ $icmp, $echo ]
   );
   print $echoReq->print."\n";

   # Build an information-request
   use Net::Frame::Layer::ICMPv4::Information;
   my $info = Net::Frame::Layer::ICMPv4::Information->new(
      payload => 'info'
   );
   $icmp->type(NF_ICMPv4_TYPE_INFORMATION_REQUEST);

   my $infoReq = Net::Frame::Simple->new(
      layers => [ $icmp, $info ]
   );
   print $infoReq->print."\n";

   # Build an address-mask request
   use Net::Frame::Layer::ICMPv4::AddressMask;
   my $mask = Net::Frame::Layer::ICMPv4::AddressMask->new(
      payload => 'mask'
   );
   $icmp->type(NF_ICMPv4_TYPE_ADDRESS_MASK_REQUEST);

   my $maskReq = Net::Frame::Simple->new(
      layers => [ $icmp, $mask ]
   );
   print $maskReq->print."\n";

   # Build a timestamp request
   use Net::Frame::Layer::ICMPv4::Timestamp;
   my $timestamp = Net::Frame::Layer::ICMPv4::Timestamp->new(
      payload => 'time'
   );
   $icmp->type(NF_ICMPv4_TYPE_TIMESTAMP_REQUEST);

   my $timestampReq = Net::Frame::Simple->new(
      layers => [ $icmp, $timestamp ]
   );
   print $timestampReq->print."\n";

   #
   # Read a raw layer
   #

   my $layer = Net::Frame::Layer::ICMPv4->new(raw => $raw);

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

DESCRIPTION

This modules implements the encoding and decoding of the ICMPv4 layer.

RFC: ftp://ftp.rfc-editor.org/in-notes/rfc792.txt

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

ATTRIBUTES

type
code

Type and code fields. See CONSTANTS.

checksum

The checksum of ICMPv4 header.

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

raw
payload
nextLayer

METHODS

new
new (hash)

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

computeChecksums

Computes the ICMPv4 checksum.

getKey
getKeyReverse

These two methods are basically used to increase the speed when using recv method from Net::Frame::Simple. Usually, you write them when you need to write match method.

match (Net::Frame::Layer::ICMPv4 object)

This method is mostly used internally. You pass a Net::Frame::Layer::ICMPv4 layer as a parameter, and it returns true if this is a response corresponding for the request, or returns false if not.

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

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

NF_ICMPv4_CODE_ZERO

ICMP code zero, used by various ICMP messages.

NF_ICMPv4_TYPE_DESTUNREACH
NF_ICMPv4_CODE_NETWORK
NF_ICMPv4_CODE_HOST
NF_ICMPv4_CODE_PROTOCOL
NF_ICMPv4_CODE_PORT
NF_ICMPv4_CODE_FRAGMENTATION_NEEDED
NF_ICMPv4_CODE_SOURCE_ROUTE_FAILED

Destination unreachable type, with possible code numbers.

NF_ICMPv4_TYPE_REDIRECT
NF_ICMPv4_CODE_FOR_NETWORK
NF_ICMPv4_CODE_FOR_HOST
NF_ICMPv4_CODE_FOR_TOS_AND_NETWORK
NF_ICMPv4_CODE_FOR_TOS_AND_HOST

Redirect type message, with possible code numbers.

NF_ICMPv4_TYPE_TIMEEXCEED
NF_ICMPv4_CODE_TTL_IN_TRANSIT
NF_ICMPv4_CODE_FRAGMENT_REASSEMBLY

Time exceeded message, with possible code numbers.

NF_ICMPv4_TYPE_PARAMETERPROBLEM
NF_ICMPv4_CODE_POINTER

Parameter problem, with possible code numbers.

NF_ICMPv4_TYPE_SOURCEQUENCH

Source quench type.

NF_ICMPv4_TYPE_ECHO_REQUEST
NF_ICMPv4_TYPE_ECHO_REPLY
NF_ICMPv4_TYPE_TIMESTAMP_REQUEST
NF_ICMPv4_TYPE_TIMESTAMP_REPLY
NF_ICMPv4_TYPE_INFORMATION_REQUEST
NF_ICMPv4_TYPE_INFORMATION_REPLY
NF_ICMPv4_TYPE_ADDRESS_MASK_REQUEST
NF_ICMPv4_TYPE_ADDRESS_MASK_REPLY

Other request/reply ICMP messages types.

SEE ALSO

Net::Frame::Layer

AUTHOR

Patrice <GomoR> Auffret

COPYRIGHT AND LICENSE

Copyright (c) 2006-2012, Patrice <GomoR> Auffret

You may distribute this module under the terms of the Artistic license. See LICENSE.Artistic file in the source distribution archive.