NetPacket::ARP(3)

πŸ’– NetPacket::ARP πŸ’–

okay so bestie, you know how when your computer's like "hey who has this IP address??" and someone's like "omg that's me, here's my MAC" β€” that whole little exchange? that's ARP, and this is the Perl module that lets you build those packets and take them apart. it's NetPacket::ARP, it lives in the User Contributed Perl Documentation section of your man pages, and honestly? it's giving packet-crafting main character energy. πŸŽ€


✨ NAME ✨

NetPacket::ARP β€” Assemble and disassemble ARP (Address Resolution Protocol) packets.

🌸 VERSION 🌸

version 1.8.0

πŸ¦‹ SYNOPSIS πŸ¦‹

use NetPacket::ARP;

$tcp_obj = NetPacket::ARP->decode($raw_pkt);
$tcp_pkt = NetPacket::ARP->encode(params...);   # Not implemented
ngl, yes, the variable names say tcp for an ARP module. that's just how it is in here. we don't fix it, we respect it. πŸ’€

πŸ’… DESCRIPTION πŸ’…

NetPacket::ARP hands you a little toolkit for assembling and disassembling packets that use ARP (Address Resolution Protocol). that's the whole vibe. 🫢

🧚 Methods

  • NetPacket::ARP->decode([RAW PACKET]) β€” Decode the raw packet data you give it and return an object stuffed with instance data. heads up bestie: this method will quite happily decode garbage input. like, it does not care. it will munch on literal nonsense and hand you back an object. so it is your responsibility as the programmer to make sure the packet data you pass in is actually valid. no cap.
  • NetPacket::ARP->encode(param => value) β€” Return an ARP packet encoded with the instance data you specify. Not implemented. 😭 (see the TODO section, she's aware)

πŸ“ Functions

  • NetPacket::ARP::strip([RAW PACKET]) β€” Return the encapsulated data (or payload) contained in the TCP packet. but here's the thing: no payload data is encapsulated in an ARP packet (it's only instance data), so this function returns undef. iconic of it, honestly.

πŸ‘‘ Instance data

the instance data for the NetPacket::ARP object is made up of these fields:

  • htype β€” Hardware type.
  • proto β€” Protocol type.
  • hlen β€” Header length.
  • plen β€” Protocol length.
  • opcode β€” One of the following constants:
    • ARP_OPCODE_REQUEST
    • ARP_OPCODE_REPLY
    • RARP_OPCODE_REQUEST
    • RARP_OPCODE_REPLY
  • sha Source hardware address.
  • spa Source protocol address.
  • tha Target hardware address.
  • tpa Target protocol address.

🌈 Exports

  • default β€” none
  • exportable β€” none
  • tags β€” the following tags group together related exportable items:
    • :ALL β€” All the above exportable items.

⭐ EXAMPLE ⭐

Print out arp requests on the local network. periodt. πŸ’–

#!/usr/bin/perl -w

use Net::PcapUtils;
use NetPacket::Ethernet qw(:types);
use NetPacket::ARP;

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

  my $eth_obj = NetPacket::Ethernet->decode($pkt);

  if ($eth_obj->{type} == ETH_TYPE_ARP) {
      my $arp_obj = NetPacket::ARP->decode($eth_obj->{data}, $eth_obj);
      print("source hw addr=$arp_obj->{sha}, " .
            "dest hw addr=$arp_obj->{tha}\n");
  }
}

Net::PcapUtils::loop(\&process_pkt);

πŸ™ˆ TODO πŸ™ˆ

the author's own to-do list, preserved in all her glory:

  • Implement encode() function
  • Does this work for protocols other than IP? Need to read RFC.
  • Example is a bit silly
"Example is a bit silly" β€” me @ my entire life tbh. πŸ’€

Copyright (c) 2001 Tim Potter.

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>


and that's the whole page, bestie! this one's from perl v5.42.0, dated 2026-02-05, so go forth and decode some ARP packets responsibly (remember: valid input is your job, not the module's 🫢✨).

πŸ“¦ where this page comes from