Net::F...r::IPv4(3pm)
π Net::Frame::Layer::IPv4 β the perl doc, but make it cute π
okay so bestie, you've stumbled into the manual page for Net::Frame::Layer::IPv4 (Net::F...r::IPv4(3pm), from the User Contributed Perl Documentation, no less). It's the Internet Protocol v4 layer object, and it is lowkey iconic. Let's get into it. π¦
β¨ NAME β¨
Net::Frame::Layer::IPv4 β the Internet Protocol v4 layer object. yes that's the whole name. short, sweet, slays.
β¨ SYNOPSIS β¨
here's the vibe. building a layer from scratch:
use Net::Frame::Layer::IPv4 qw(:consts);
# Build a layer
my $layer = Net::Frame::Layer::IPv4->new(
version => 4,
tos => 0,
id => getRandom16bitsInt(),
length => NF_IPv4_HDR_LEN,
hlen => 5,
flags => 0,
offset => 0,
ttl => 128,
protocol => NF_IPv4_PROTOCOL_TCP,
checksum => 0,
src => '127.0.0.1',
dst => '127.0.0.1',
options => '',
noFixLen => 0,
);
$layer->pack;
print 'RAW: '.$layer->dump."\n";
and reading a raw layer back, because we love a round trip:
# Read a raw layer
my $layer = Net::Frame::Layer::IPv4->new(raw => $raw);
print $layer->print."\n";
print 'PAYLOAD: '.unpack('H*', $layer->payload)."\n"
if $layer->payload;
no cap, that's the whole flow. π
β¨ DESCRIPTION β¨
this module is the one that implements the encoding and decoding of the IPv4 layer. that's its whole job and it does it flawlessly, obviously.
RFC reference so you can go read the source material, nerd (affectionate):
ftp://ftp.rfc-editor.org/in-notes/rfc791.txt
also peep Net::Frame::Layer for other attributes and methods β the lore runs deep, iykyk.
β¨ ATTRIBUTES β¨
the whole cast of characters. every single one. let's go:
idβ IP ID of the datagram.ttlβ Time to live.src,dstβ Source and destination IP addresses. the duo. the main characters.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. like, literally 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). math is math.hlenβ Header length in number of words, including IP options.optionsβ IP options, as a hexadecimal string.noFixLenβ okay so listen: since the byte ordering of thelengthattribute varies from system to system, there's a subroutine inside this module that detects which byte order to use. Sometimes β like when you buildNet::Frame::Layer::8021Qlayers β you may have the need to avoid this. So set it to1in order to avoid fixing. Default is0(that is to fix).
and these ones are inherited, so go ask Net::Frame::Layer for the full tea:
rawpayloadnextLayer
β¨ METHODS β¨
newnew (hash)β Object constructor. You can pass attributes that will overwrite default ones. See SYNOPSIS for default values. (the synopsis ate, go look at it.)getHeaderLengthβ Returns the header length in bytes, not including IP options.getOptionsLengthβ Returns the length in bytes of IP options.0if none.computeLengths ({ payloadLength => VALUE })β In order to compute lengths attributes within IPv4 header, you need to pass via a hashref the number of bytes contained in IPv4 payload (that is, the sum of all layers after the IPv4 one).computeChecksumsβ Computes the IPv4 checksum.
and the following are inherited methods. Some of them may be overridden in this layer, and some others may not be meaningful in this layer. See Net::Frame::Layer for more information:
layercomputeLengthscomputeChecksumspackunpackencapsulategetLengthgetPayloadLengthprintdump
β¨ CONSTANTS β¨
load them like this, bestie:
use Net::Frame::Layer::IPv4 qw(:consts);
π protocol type constants
all the various protocol type constants, every last one, no skips:
NF_IPv4_PROTOCOL_ICMPv4NF_IPv4_PROTOCOL_IGMPNF_IPv4_PROTOCOL_IPIPNF_IPv4_PROTOCOL_TCPNF_IPv4_PROTOCOL_EGPNF_IPv4_PROTOCOL_IGRPNF_IPv4_PROTOCOL_CHAOSNF_IPv4_PROTOCOL_UDPNF_IPv4_PROTOCOL_IDPNF_IPv4_PROTOCOL_DCCPNF_IPv4_PROTOCOL_IPv6NF_IPv4_PROTOCOL_IPv6ROUTINGNF_IPv4_PROTOCOL_IPv6FRAGMENTNF_IPv4_PROTOCOL_IDRPNF_IPv4_PROTOCOL_RSVPNF_IPv4_PROTOCOL_GRENF_IPv4_PROTOCOL_ESPNF_IPv4_PROTOCOL_AHNF_IPv4_PROTOCOL_ICMPv6NF_IPv4_PROTOCOL_EIGRPNF_IPv4_PROTOCOL_OSPFNF_IPv4_PROTOCOL_ETHERIPNF_IPv4_PROTOCOL_PIMNF_IPv4_PROTOCOL_VRRPNF_IPv4_PROTOCOL_STPNF_IPv4_PROTOCOL_SCTPNF_IPv4_PROTOCOL_UDPLITE
π flag constants
and the various possible flags:
NF_IPv4_MORE_FRAGMENTNF_IPv4_DONT_FRAGMENTNF_IPv4_RESERVED_FRAGMENT
β¨ SEE ALSO β¨
Net::Frame::Layer
that's the one. go read it. π«Ά
β¨ AUTHOR β¨
Patrice <GomoR> Auffret. we stan. π
β¨ COPYRIGHT AND LICENSE β¨
Copyright (c) 2006-2019, Patrice <GomoR> Auffret
You may distribute this module under the terms of the Artistic license. See LICENSE.Artistic file in the source distribution archive.
fr fr, read the license before you redistribute, bestie. it's giving "respect the author." π
and that's the whole page!! mwah π this was perl v5.36.0, dated 2022-12-04, straight from Net::F...r::IPv4(3pm). go forth and packet-encode, you absolute legend. π¦β¨π
π¦ where this page comes from
- debian bookworm: libnet-frame-perl 1.21-2 Β· Artistic-1.0-Perl
- debian trixie: libnet-frame-perl 1.21-2 Β· Artistic-1.0-Perl
- ubuntu noble: libnet-frame-perl 1.21-2 Β· Artistic-1.0-Perl
- ubuntu resolute: libnet-frame-perl 1.21-2 Β· Artistic-1.0-Perl
- ubuntu stonking: libnet-frame-perl 1.21-2 Β· Artistic-1.0-Perl
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms