NetPacket::ARP3pm
Assemble and disassemble arp (address resolution protocol) packets.
Usage
use NetPacket::ARP;$tcp_obj = NetPacket::ARP->decode($raw_pkt);$tcp_pkt = NetPacket::ARP->encode(params...); # Not implemented
Version
version 1.7.2
Overview
"NetPacket::ARP" provides a set of routines for assembling and disassembling packets using ARP (Address Resolution Protocol).
Methods
- "NetPacket::ARP->decode([RAW PACKET])"
-
Decode the raw packet data given and return an object containing instance data. This method will quite happily decode garbage input. It is the responsibility of the programmer to ensure valid packet data is passed to this method.
- "NetPacket::ARP->encode(param => value)"
-
Return a ARP packet encoded with the instance data specified. Not implemented.
Functions
- "NetPacket::ARP::strip([RAW PACKET])"
-
Return the encapsulated data (or payload) contained in the TCP packet. Since no payload data is encapulated in an ARP packet (only instance data), this function returns undef.
Instance data
The instance data for the "NetPacket::ARP" object consists of the following 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.
Examples
Print out arp requests on the local network.
#!/usr/bin/perl -wuse 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
- Implement
encode()function
- Does this work for protocols other than IP? Need to read RFC.
- Example is a bit silly
Releases
8 releases since Debian 6.0 (Squeeze); the text changed 6 times.