Net::F...r::IPv4(3pm)

πŸ“¦
version 1.21 Β· 2 versions
  • 1.21 Β· debian bookworm, debian trixie, ubuntu noble, ubuntu resolute, ubuntu stonking (latest)
  • 1.21 Β· ubuntu jammy
, in debian bookworm, debian trixie, ubuntu noble, ubuntu resolute, ubuntu stonking

πŸ’– 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 the length attribute varies from system to system, there's a subroutine inside this module that detects which byte order to use. Sometimes β€” like when you build Net::Frame::Layer::8021Q 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).

and these ones are inherited, so go ask Net::Frame::Layer for the full tea:

  • raw
  • payload
  • nextLayer

✨ METHODS ✨

  • new
  • new (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. 0 if 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:

  • layer
  • computeLengths
  • computeChecksums
  • pack
  • unpack
  • encapsulate
  • getLength
  • getPayloadLength
  • print
  • dump

✨ 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_ICMPv4
  • NF_IPv4_PROTOCOL_IGMP
  • NF_IPv4_PROTOCOL_IPIP
  • NF_IPv4_PROTOCOL_TCP
  • NF_IPv4_PROTOCOL_EGP
  • NF_IPv4_PROTOCOL_IGRP
  • NF_IPv4_PROTOCOL_CHAOS
  • NF_IPv4_PROTOCOL_UDP
  • NF_IPv4_PROTOCOL_IDP
  • NF_IPv4_PROTOCOL_DCCP
  • NF_IPv4_PROTOCOL_IPv6
  • NF_IPv4_PROTOCOL_IPv6ROUTING
  • NF_IPv4_PROTOCOL_IPv6FRAGMENT
  • NF_IPv4_PROTOCOL_IDRP
  • NF_IPv4_PROTOCOL_RSVP
  • NF_IPv4_PROTOCOL_GRE
  • NF_IPv4_PROTOCOL_ESP
  • NF_IPv4_PROTOCOL_AH
  • NF_IPv4_PROTOCOL_ICMPv6
  • NF_IPv4_PROTOCOL_EIGRP
  • NF_IPv4_PROTOCOL_OSPF
  • NF_IPv4_PROTOCOL_ETHERIP
  • NF_IPv4_PROTOCOL_PIM
  • NF_IPv4_PROTOCOL_VRRP
  • NF_IPv4_PROTOCOL_STP
  • NF_IPv4_PROTOCOL_SCTP
  • NF_IPv4_PROTOCOL_UDPLITE

πŸŽ€ flag constants

and the various possible flags:

  • NF_IPv4_MORE_FRAGMENT
  • NF_IPv4_DONT_FRAGMENT
  • NF_IPv4_RESERVED_FRAGMENT

✨ SEE ALSO ✨

  • Net::Frame::Layer

that's the one. go read it. 🫢


✨ AUTHOR ✨

Patrice <GomoR> Auffret. we stan. πŸ‘‘


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. πŸ¦‹βœ¨πŸŽ€