NAME

Net::Packet::ICMPv4 - Internet Control Message Protocol v4 layer 4 object

SYNOPSIS

use Net::Packet::Consts qw(:icmpv4);
require Net::Packet::ICMPv4;

# Build echo-request header
my $echo = Net::Packet::ICMPv4->new(data => '0123456789');

# Build information-request header
my $info = Net::Packet::ICMPv4->new(
   type => NP_ICMPv4_TYPE_INFORMATION_REQUEST,
   data => '0123456789',
);

# Build address-mask request header
my $mask = Net::Packet::ICMPv4->new(
   type => NP_ICMPv4_TYPE_ADDRESS_MASK_REQUEST,
   data => '0123456789',
);

# Build timestamp request header
my $timestamp = Net::Packet::ICMPv4->new(
   type => NP_ICMPv4_TYPE_TIMESTAMP_REQUEST,
   data => '0123456789',
);
$timestamp->pack;

print 'RAW: '.unpack('H*', $timestamp->raw)."\n";

# Read a raw layer
my $layer = Net::Packet::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::Packet::Layer and Net::Packet::Layer4 for other attributes a nd methods.

ATTRIBUTES

type
code

Type and code fields. See CONSTANTS.

checksum

The checksum of ICMPv4 header.

identifier

Identification number.

sequenceNumber

Sequence number.

originateTimestamp
receiveTimestamp
transmitTimestamp

Three timestamps used by the NP_ICMPv4_TYPE_TIMESTAMP_REQUEST message.

addressMask

Used by the NP_ICMPv4_TYPE_ADDRESS_MASK_REQUEST message.

gateway

Used by the NP_ICMPv4_TYPE_REDIRECT message.

unused

Zero value field used in various ICMP messages.

error

A pointer to a Net::Packet::Frame object, usually set when an ICMP error message has been returned.

data

Additionnal data can be added to an ICMP message, traditionnaly used in NP_ICMPv4_TYPE_ECHO_REQUEST.

METHODS

new

Object constructor. You can pass attributes that will overwrite default ones. Default values:

type: NP_ICMPv4_TYPE_ECHO_REQUEST

code: NP_ICMPv4_CODE_ZERO

checksum: 0

identifier: getRandom16bitsInt()

sequenceNumber: getRandom16bitsInt()

originateTimestamp: time()

receiveTimestamp: 0

transmitTimestamp: 0

addressMask: 0

gateway: "127.0.0.1"

unused: 0

data: ""

recv

Will search for a matching replies in framesSorted or frames from a Net::Packet::Dump object.

getDataLength

Returns the length in bytes of data attribute.

pack

Packs all attributes into a raw format, in order to inject to network. Returns 1 on success, undef otherwise.

unpack

Unpacks raw data from network and stores attributes into the object. Returns 1 on success, undef otherwise.

isTypeEchoRequest
isTypeEchoReply
isTypeTimestampRequest
isTypeTimestampReply
isTypeInformationRequest
isTypeInformationReply
isTypeAddressMaskRequest
isTypeAddressMaskReply
isTypeDestinationUnreachable

Returns 1 if the type attribute is of specified type.

CONSTANTS

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

NP_ICMPv4_CODE_ZERO

ICMP code zero, used by various ICMP messages.

NP_ICMPv4_TYPE_DESTINATION_UNREACHABLE
NP_ICMPv4_CODE_NETWORK
NP_ICMPv4_CODE_HOST
NP_ICMPv4_CODE_PROTOCOL
NP_ICMPv4_CODE_PORT
NP_ICMPv4_CODE_FRAGMENTATION_NEEDED
NP_ICMPv4_CODE_SOURCE_ROUTE_FAILED

Destination unreachable type, with possible code numbers.

NP_ICMPv4_TYPE_REDIRECT
NP_ICMPv4_CODE_FOR_NETWORK
NP_ICMPv4_CODE_FOR_HOST
NP_ICMPv4_CODE_FOR_TOS_AND_NETWORK
NP_ICMPv4_CODE_FOR_TOS_AND_HOST

Redirect type message, with possible code numbers.

NP_ICMPv4_TYPE_TIME_EXCEEDED
NP_ICMPv4_CODE_TTL_IN_TRANSIT
NP_ICMPv4_CODE_FRAGMENT_REASSEMBLY

Time exceeded message, with possible code numbers.

NP_ICMPv4_TYPE_ECHO_REQUEST
NP_ICMPv4_TYPE_ECHO_REPLY
NP_ICMPv4_TYPE_TIMESTAMP_REQUEST
NP_ICMPv4_TYPE_TIMESTAMP_REPLY
NP_ICMPv4_TYPE_INFORMATION_REQUEST
NP_ICMPv4_TYPE_INFORMATION_REPLY
NP_ICMPv4_TYPE_ADDRESS_MASK_REQUEST
NP_ICMPv4_TYPE_ADDRESS_MASK_REPLY

Other request/reply ICMP messages types.

AUTHOR

Patrice <GomoR> Auffret

COPYRIGHT AND LICENSE

Copyright (c) 2004-2015, Patrice <GomoR> Auffret

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

RELATED MODULES

NetPacket, Net::RawIP, Net::RawSock