NAME
Net::Packet::IPv4 - Internet Protocol v4 layer 3 object
SYNOPSIS
use Net::Packet::IPv4;
use Net::Packet::Consts qw(:ipv4);
# Build layer to inject to network
my $ip = Net::Packet::IPv4->new(
flags => NP_IPv4_DONT_FRAGMENT,
dst => "192.168.0.1",
);
# Decode from network to create the object
# Usually, you do not use this, it is used by Net::Packet::Frame
my $ip2 = Net::Packet::IPv4->new(raw => $rawFromNetwork);
print $ip->print, "\n";
DESCRIPTION
This modules implements the encoding and decoding of the IPv4 layer.
RFC: ftp://ftp.rfc-editor.org/in-notes/rfc791.txt
See also Net::Packet::Layer and Net::Packet::Layer3 for other attributes and methods.
ATTRIBUTES
- id
-
IP ID of the datagram.
- ttl
-
Time to live.
- src
- dst
-
Source and destination IP addresses.
- protocol
-
Of which type the layer 4 is.
- checksum
-
IP checksum.
- flags
-
IP Flags.
- offset
-
IP fragment offset.
- version
-
IP version, here it is 4.
- tos
-
Type of service flag.
- length
-
Total length in bytes of the packet, including IP headers (that is, layer 3 + layer 4 + layer 7).
- hlen
-
Header length in number of words, including IP options.
- options
-
IP options, as a hexadecimal string.
- noFixLen
-
Since the byte ordering of length attribute varies from system to system, a subroutine inside this module detects which byte order to use. Sometimes, like when you build Net::Packet::VLAN layers, you may have the need to avoid this. So set it to 1 in order to avoid fixing. Default is 0 (that is to fix).
- doChecksum
-
Usually the IP checksum is done by the system. But if you inject some frames into network somewhere (well, err...), this checksum could be not computed. So, you can enable it by setting this attribute to 1. Default 0, to let the system compute it.
METHODS
- new
-
Object constructor. You can pass attributes that will overwrite default ones. Default values:
version: 4
tos: 0
id: getRandom16bitsInt()
length: 0
hlen: 0
flags: 0
offset: 0
ttl: 128
protocol: NP_IPv4_PROTOCOL_TCP
checksum: 0
src: $Env->ip
dst: "127.0.0.1"
options: ""
noFixLen: 0
doChecksum: 0
- 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.
- getHeaderLength
-
Returns the header length in bytes, not including IP options.
- getPayloadLength
-
Returns the length in bytes of encapsulated layers (that is, layer 4 + layer 7).
- getOptionsLength
-
Returns the length in bytes of IP options.
- haveFlagDf
- haveFlagMf
- haveFlagRf
-
Returns 1 if the specified flag is set in flags attribute, 0 otherwise.
- isProtocolTcp
- isProtocolUdp
- isProtocolIcmpv4
-
Returns 1 if the specified protocol is used at layer 4, 0 otherwise.
CONSTANTS
Load them: use Net::Packet::Consts qw(:ipv4);
- NP_IPv4_PROTOCOL_TCP
- NP_IPv4_PROTOCOL_UDP
- NP_IPv4_PROTOCOL_ICMPv4
-
Various protocol type constants.
- NP_IPv4_MORE_FRAGMENT
- NP_IPv4_DONT_FRAGMENT
- NP_IPv4_RESERVED_FRAGMENT
-
Various possible flags.
AUTHOR
Patrice <GomoR> Auffret
COPYRIGHT AND LICENSE
Copyright (c) 2004-2006, 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
1 POD Error
The following errors were encountered while parsing the POD:
- Around line 277:
Non-ASCII character seen before =encoding in '# Build'. Assuming CP1252