NetPacket::IP(3)

πŸ’– NetPacket::IP πŸ’–

okay bestie, so this is the manual page for NetPacket::IP(3) β€” that's the User Contributed Perl Documentation section, iykyk. She's a Perl module that assembles and disassembles IP (Internet Protocol) packets, and honestly? she's iconic for it. no cap. 🌈


✨ VERSION ✨

version 1.8.0 β€” that's the vibe check and she passed πŸ’…


πŸŽ€ SYNOPSIS πŸŽ€

here's the whole look, copy it exactly bestie:

use NetPacket::IP;

$ip_obj = NetPacket::IP->decode($raw_pkt);
$ip_pkt = NetPacket::IP->encode($ip_obj);
$ip_data = NetPacket::IP::strip($raw_pkt);

like, that's it. that's the whole entrance. main character energy fr fr πŸ¦‹


πŸ’œ DESCRIPTION πŸ’œ

NetPacket::IP gives you a whole lil set of routines for assembling and disassembling packets using IP (Internet Protocol). she does the tedious bits so you don't have to, periodt.

🧚 Methods

  • NetPacket::IP->decode([RAW PACKET]) β€” decodes the raw packet data you hand her and hands back an object stuffed with instance data. and okay, listen: she will quite happily decode garbage input. like, no complaints, no side-eye. so it is 100% your responsibility as the programmer to make sure you're actually passing valid packet data in here. she trusts you. don't make it weird. 😭
  • NetPacket::IP->encode() β€” returns an IP packet encoded with whatever instance data you specified. she infers the total length of the packet automatically from the payload length, and she also adjusts the checksum for you. self-sufficient queen πŸ‘‘

🌸 Functions

  • NetPacket::IP::strip([RAW PACKET]) β€” returns the encapsulated data (a.k.a. the payload) that's chillin' inside the IP packet. this data is suitable to be used as input for other NetPacket::* modules, so it plays nice with the whole friend group 🫢

this function is equivalent to creating an object using the decode() constructor and then returning the data field of that object. same result, less typing. slay.

πŸ“ Instance data

the instance data on your NetPacket::IP object has these fields, and here's what each one is giving:

  • ver β€” the IP version number of this packet.
  • hlen β€” the IP header length of this packet.
  • flags β€” the IP header flags for this packet.
  • foffset β€” the IP fragment offset for this packet.
  • tos β€” the type-of-service for this IP packet.
  • len β€” the length (including length of header) in bytes for this packet.
  • id β€” the identification (sequence) number for this IP packet.
  • ttl β€” the time-to-live value for this packet.
  • proto β€” the IP protocol number for this packet.
  • cksum β€” the IP checksum value for this packet.
  • src_ip β€” the source IP address for this packet in dotted-quad notation.
  • dest_ip β€” the destination IP address for this packet in dotted-quad notation.
  • options β€” any IP options for this packet.
  • data β€” the encapsulated data (payload) for this IP packet.

πŸ’« Exports

  • default β€” none. yeah. nothing. we start from scratch around here πŸ™ˆ
  • exportable β€” IP_PROTO_IP IP_PROTO_ICMP IP_PROTO_IGMP IP_PROTO_IPIP IP_PROTO_TCP IP_PROTO_UDP IP_VERSION_IPv4
  • tags β€” the following tags group together related exportable items:
    • :protos β€” IP_PROTO_IP IP_PROTO_ICMP IP_PROTO_IGMP IP_PROTO_IPIP IP_PROTO_TCP IP_PROTO_UDP
    • :versions β€” IP_VERSION_IPv4
    • :strip β€” imports the strip function ip_strip.
    • :ALL β€” all the above exportable items. the whole menu, bestie 🍽️

πŸ”₯ EXAMPLE πŸ”₯

this script dumps IP frames by IP address and protocol straight to standard output. she ate:

#!/usr/bin/perl -w

use strict;
use Net::PcapUtils;
use NetPacket::Ethernet qw(:strip);
use NetPacket::IP;

sub process_pkt {
    my ($user, $hdr, $pkt) = @_;

    my $ip_obj = NetPacket::IP->decode(eth_strip($pkt));
    print("$ip_obj->{src_ip}:$ip_obj->{dest_ip} $ip_obj->{proto}\n");
}

Net::PcapUtils::loop(\&process_pkt, FILTER => 'ip');

🌈 TODO 🌈

the to-do list, aka the "we'll get to it" list, lowkey real of her to admit:

  • IP option decoding β€” currently stored in binary form.
  • Assembly of received fragments.

Copyright (c) 2001 Tim Potter and Stephanie Wehner.

Copyright (c) 1995,1996,1997,1998,1999 ANU and CSIRO on behalf of the participants in the CRC for Advanced Computational Systems ('ACSys').

This module is free software. You can redistribute it and/or modify it under the terms of the Artistic License 2.0.

This program is distributed in the hope that it will be useful, but without any warranty; without even the implied warranty of merchantability or fitness for a particular purpose.


πŸ’… AUTHOR πŸ’…

  • Tim Potter <tpot@samba.org>
  • Stephanie Wehner <atrak@itsx.com>

and that's the whole page, bestie!! πŸŽ€ this lil doc ships with perl v5.42.0 and it's dated 2026-02-05 β€” go forth and decode responsibly, mwah πŸ’–βœ¨πŸ¦‹

πŸ“¦ where this page comes from