logo
Free, unlimited AI code reviews that run on commit
git-lrc git-lrc GitHub Install Now We'd appreciate a star git-lrc - Free, unlimited AI code reviews that run on commit | Product Hunt git-lrc - Free, unlimited AI code reviews that run on commit | Product Hunt

NetPacket::ARP - Assemble and disassemble ARP (Address Resolution Protocol) packets.

Author

       Tim Potter <tpot@samba.org>

perl v5.36.0                                       2022-11-19                                NetPacket::ARP(3pm)

Description

       "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.

   Instancedata
       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.

Example

       Print out arp requests on the local network.

         #!/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);

Name

       NetPacket::ARP - Assemble and disassemble ARP (Address Resolution Protocol) packets.

Synopsis

         use NetPacket::ARP;

         $tcp_obj = NetPacket::ARP->decode($raw_pkt);
         $tcp_pkt = NetPacket::ARP->encode(params...);   # Not implemented

Todo

       Implement encode() function
       Does this work for protocols other than IP?  Need to read RFC.
       Example is a bit silly

Version

       version 1.7.2

See Also