NetPack...Ethernet(3)

✨ NetPacket::Ethernet πŸ’–

okay bestie, so this is the manual page for NetPacket::Ethernet, living in the User Contributed Perl Documentation corner of the perl v5.42.0 manual set. it's giving packet girlie energy and honestly? we ate. πŸŽ€


🌸 NAME 🌸

NetPacket::Ethernet β€” assemble and disassemble ethernet packets. that's it, that's the whole vibe. πŸ¦‹


⭐ VERSION ⭐

version 1.8.0 β€” she's a lil vintage but she works, no cap. πŸ’…


πŸŽ€ SYNOPSIS πŸŽ€

use NetPacket::Ethernet;

$eth_obj = NetPacket::Ethernet->decode($raw_pkt);
$eth_pkt = NetPacket::Ethernet->encode(params...);   # Not implemented
$eth_data = NetPacket::Ethernet::strip($raw_pkt);

okay so like, you use it, you decode a raw packet, you could encode one except not implemented (we'll get there, we'll get there 😭), and strip just yoinks the payload right out. iconic behaviour fr fr. ✨


πŸ’œ DESCRIPTION πŸ’œ

NetPacket::Ethernet hands you a whole set of routines for assembling and disassembling packets using the Ethernet protocol. it's your lil bestie for talking to the wire. 🫢

πŸ¦‹ Methods πŸ¦‹

  • NetPacket::Ethernet->decode([RAW PACKET]) β€” decode the raw packet data you hand over and return an object stuffed with instance data. and listen, bestie: this method will quite happily decode garbage input. like, it does not care. it has no standards. it will chew up trash and hand you back an object. so it is 100% the programmer's responsibility to make sure the packet data passed to this method is actually valid. do not come for her when you fed her nonsense. πŸ’€
  • NetPacket::Ethernet->encode(param => value) β€” return an ethernet packet encoded with the instance data you specified. Not implemented. yeah. that's the whole thing. she's a dream deferred. 😭

🌈 Functions 🌈

  • NetPacket::Ethernet::strip([RAW PACKET]) β€” return the encapsulated data (or payload) that's sitting inside the ethernet packet. this data is suitable to be used as input for other NetPacket::* modules, so it's basically the handoff queen. πŸ‘‘

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

πŸ“ Instance data πŸ“

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

  • src_mac β€” the source MAC address for the ethernet packet, as a hex string.
  • dest_mac β€” the destination MAC address for the ethernet packet, as a hex string.
  • type β€” the protocol type for the ethernet packet.
  • data β€” the payload for the ethernet packet.

🧚 Exports 🧚

  • default β€” none. nothing. zero. the bare minimum. respect. πŸ™ˆ
  • exportable β€” ETH_TYPE_IP ETH_TYPE_ARP ETH_TYPE_APPLETALK ETH_TYPE_SNMP ETH_TYPE_IPv6 ETH_TYPE_PPP
  • tags β€” the following tags group together related exportable items:
    • :types β€” ETH_TYPE_IP ETH_TYPE_ARP ETH_TYPE_APPLETALK ETH_TYPE_SNMP ETH_TYPE_IPv6 ETH_TYPE_PPP
    • :strip β€” import the strip function eth_strip, which is an alias for NetPacket::Ethernet::strip
    • :ALL β€” all the above exportable items. the whole buffet. πŸ”₯

🌟 EXAMPLE 🌟

the following script dumps ethernet frames by mac address and protocol to standard output. she's a lil cutie, she just watches. πŸ‘€

#!/usr/bin/perl -w

use strict;
use Net::PcapUtils;
use NetPacket::Ethernet;

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

    my $eth_obj = NetPacket::Ethernet->decode($pkt);
    print("$eth_obj->{src_mac}:$eth_obj->{dest_mac} $eth_obj->{type}\n");
}

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

πŸ’… TODO πŸ’…

implement encode() function. yes. that's the todo. it's just that. the whole list. one item. we're manifesting it. ✨


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> β€” ty king, we appreciate you. 🫢


and that's the whole page bestie, no notes, go decode some packets πŸ’–

this lil legend ships as part of perl v5.42.0, dated 2026-02-05 β€” mwah, kiss the manual page goodnight. πŸŽ€πŸ’…βœ¨

πŸ“¦ where this page comes from