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


NetPacket documentation Contained in the NetPacket distribution.

Index


Code Index:

NAME

Top

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

VERSION

Top

version 1.1.2

SYNOPSIS

Top

  use NetPacket::ARP;

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

DESCRIPTION

Top

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.

EXAMPLE

Top

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);

TODO

Top

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

COPYRIGHT

Top

AUTHOR

Top

Tim Potter <tpot@samba.org>


NetPacket documentation Contained in the NetPacket distribution.

package NetPacket::ARP;
BEGIN {
  $NetPacket::ARP::AUTHORITY = 'cpan:yanick';
}
BEGIN {
  $NetPacket::ARP::VERSION = '1.1.2';
}
# ABSTRACT: Assemble and disassemble ARP (Address Resolution Protocol) packets.

use strict;
use vars qw(@ISA @EXPORT @EXPORT_OK %EXPORT_TAGS);


BEGIN {
    @ISA = qw(Exporter NetPacket);

# Items to export into callers namespace by default
# (move infrequently used names to @EXPORT_OK below)

    @EXPORT = qw(
    );

# Other items we are prepared to export if requested

    @EXPORT_OK = qw(arp_strip
		    ARP_OPCODE_REQUEST ARP_OPCODE_REPLY RARP_OPCODE_REQUEST 
		    RARP_OPCODE_REPLY
    );

# Tags:

    %EXPORT_TAGS = (
    ALL         => [@EXPORT, @EXPORT_OK],
    opcodes     => [qw(ARP_OPCODE_REQUEST ARP_OPCODE_REPLY RARP_OPCODE_REQUEST 
		       RARP_OPCODE_REPLY)],
    strip       => [qw(arp_strip)],
);

}

# 
# List of opcode values
#

use constant ARP_OPCODE_REQUEST  => 1;
use constant ARP_OPCODE_REPLY    => 2;
use constant RARP_OPCODE_REQUEST => 3;
use constant RARP_OPCODE_REPLY   => 4;

#
# Decode the packet
#

sub decode {
    my $class = shift;
    my($pkt, $parent, @rest) = @_;
    my $self = {};

    # Class fields

    $self->{_parent} = $parent;
    $self->{_frame} = $pkt;

    # Decode ARP packet

    if (defined($pkt)) {

	($self->{htype}, $self->{proto}, $self->{hlen}, $self->{plen},
	 $self->{opcode}, $self->{sha}, $self->{spa}, $self->{tha},
	 $self->{tpa}) = 
	     unpack('nnCCnH12H8H12H8' , $pkt);

	$self->{data} = undef;
    }

    # Return a blessed object

    bless($self, $class);
    return $self;
}


#
# Strip header from packet and return the data contained in it.  ARP
# packets contain no encapsulated data.
#

undef &arp_strip;
*arp_strip = \&strip;

sub strip {
    return undef;
}

#
# Encode a packet
#

sub encode {
    die("Not implemented");
}

# Module return value

1;




__END__


# any real autoloaded methods go after this line