SourceForge Jpcap

net.sourceforge.jpcap.net
Class ARPPacket

java.lang.Object
  extended by net.sourceforge.jpcap.net.Packet
      extended by net.sourceforge.jpcap.net.EthernetPacket
          extended by net.sourceforge.jpcap.net.ARPPacket
All Implemented Interfaces:
Serializable, ARPFields, EthernetFields

public class ARPPacket
extends EthernetPacket
implements ARPFields

An ARP protocol packet.

Extends EthernetPacket, adding ARP header information and an ARP data payload.

Now handles both ARP and RARP.

Version:
$Revision: 1.1 $
Author:
Patrick Charles, Jonas Lehmann, Esmond Pitt
See Also:
Serialized Form
Last modified by:
$Author: esmondpitt $
Last modified at:
$Date: 2008/08/21 02:58:16 $

Field Summary
 
Fields inherited from class net.sourceforge.jpcap.net.EthernetPacket
_byteBuffer, _bytes, _ethOffset, _timeval
 
Fields inherited from interface net.sourceforge.jpcap.net.ARPFields
ARP_ADDR_SIZE_LEN, ARP_ADDR_TYPE_LEN, ARP_ETH_ADDR_CODE, ARP_HEADER_LEN, ARP_HW_LEN_POS, ARP_HW_TYPE_POS, ARP_IP_ADDR_CODE, ARP_OP_LEN, ARP_OP_POS, ARP_OP_REP_CODE, ARP_OP_REQ_CODE, ARP_PR_LEN_POS, ARP_PR_TYPE_POS, ARP_S_HW_ADDR_POS, ARP_S_PR_ADDR_POS, ARP_T_HW_ADDR_POS, ARP_T_PR_ADDR_POS, RARP_OP_REP_CODE, RARP_OP_REQ_CODE
 
Fields inherited from interface net.sourceforge.jpcap.net.EthernetFields
ETH_CODE_LEN, ETH_CODE_POS, ETH_DST_POS, ETH_HEADER_LEN, ETH_SRC_POS
 
Constructor Summary
ARPPacket(int lLen, byte[] bytes)
          Create a new ARP packet.
ARPPacket(int lLen, byte[] bytes, Timeval tv)
          Create a new ARP packet.
ARPPacket(int lLen, ByteBuffer bb, Timeval tv)
          Create a new ARP packet.
 
Method Summary
 byte[] getARPData()
          Fetch data portion of the arp packet.
 byte[] getARPHeader()
          Fetch the arp header, excluding arp data payload.
 String getColor()
          Fetch ASCII escape sequence of the color associated with this packet type.
 byte[] getData()
          Fetch the data portion of the packet. This is overridden in derived classes to return successively smaller and smaller amounts of data. For example:
  • EthernetPacket.getData() returns the entire Ethernet payload excluding the Ethernet header
  • IP.Packet.getData() only returns the IP payload, i.e. excluding the IP header which is in the Ethernet payload
  • TCPPacket.getData() only returns the TCP payload, i.e. excluding the TCP header which is in the IP payload
 String getDestinationProtoAddress()
          Fetch the destination protocol address.
 byte[] getHeader()
          Fetch header portion of the packet. This is overridden in derived classes to return the header appropriate to the packet class. For example:
 int getHwAddressLength()
          Return the length of the hardware addresses in this packet, usually 6 for ARPFields.ARP_ETH_ADDR_CODE.
 int getHwAddressType()
          Return the hardware address type in this packet, usually ARPFields.ARP_ETH_ADDR_CODE.
 int getOperation()
          Fetch the ARP/RARP operation code.
 int getProtoAddressLength()
          Return the length of the protocol addresses in this packet, usually 4 for ARPFields.ARP_IP_ADDR_CODE.
 int getProtoAddressType()
          Return the type of the protocol addresses in this packet, usually ARPFields.ARP_IP_ADDR_CODE.
 String getSourceProtoAddress()
          Fetch the sender protocol address.
 void setDestinationMACAddress(MACAddress macAddress)
          Set the destination hardware address.
 void setDestinationProtoAddress(InetAddress address)
          Set the destination protocol address.
 void setOperation(int operation)
          Set the ARP operation code.
 void setSourceMACAddress(MACAddress macAddress)
          Set the source hardware address.
 void setSourceProtoAddress(InetAddress address)
          Set the source protocol address.
 String toColoredString(boolean colored)
          Generate string with contents describing this packet.
 
Methods inherited from class net.sourceforge.jpcap.net.EthernetPacket
equals, getDestinationHwAddress, getDestinationMACAddress, getEthernetCRC32, getEthernetData, getEthernetHeader, getEthernetHeaderLength, getEthernetProtocol, getHeaderLength, getPacketData, getPacketLength, getProtocol, getSourceHwAddress, getSourceMACAddress, getTimeval, hashCode, setChecksums, setEthernetProtocol, toByteArray, toString
 
Methods inherited from class net.sourceforge.jpcap.net.Packet
getChecksum, ipChecksum, isValidChecksum
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

ARPPacket

public ARPPacket(int lLen,
                 byte[] bytes)
Create a new ARP packet.

Parameters:
lLen - link-layer header length
bytes - Packet data

ARPPacket

public ARPPacket(int lLen,
                 byte[] bytes,
                 Timeval tv)
Create a new ARP packet.

Parameters:
lLen - link-layer header length
bytes - Packet data
tv - Timestamp

ARPPacket

public ARPPacket(int lLen,
                 ByteBuffer bb,
                 Timeval tv)
Create a new ARP packet.

Parameters:
lLen - link-layer header length
bb - Packet data wrapped in a ByteBuffer
tv - Timestamp
Since:
2.0.0
Method Detail

getHwAddressType

public int getHwAddressType()
Return the hardware address type in this packet, usually ARPFields.ARP_ETH_ADDR_CODE.

Returns:
the hardware address type in this packet.
Since:
2.0.0

getHwAddressLength

public int getHwAddressLength()
Return the length of the hardware addresses in this packet, usually 6 for ARPFields.ARP_ETH_ADDR_CODE.

Returns:
the length of the hardware addresses in this packet.
Since:
2.0.0

getProtoAddressType

public int getProtoAddressType()
Return the type of the protocol addresses in this packet, usually ARPFields.ARP_IP_ADDR_CODE.

Returns:
the type of the protocol addresses in this packet.
Since:
2.0.0

getProtoAddressLength

public int getProtoAddressLength()
Return the length of the protocol addresses in this packet, usually 4 for ARPFields.ARP_IP_ADDR_CODE.

Returns:
the length of the protocol addresses in this packet.
Since:
2.0.0

getOperation

public int getOperation()
Fetch the ARP/RARP operation code. Usually one of ARPFields.{ARP_OP_REQ_CODE, ARP_OP_REP_CODE, RARP_REQ_CODE, RARP_REP_CODE}.


setOperation

public void setOperation(int operation)
Set the ARP operation code. Usually one of ARPFields.{ARP_OP_REQ_CODE, ARP_OP_REP_CODE, RARP_REQ_CODE, RARP_REP_CODE}.

Parameters:
operation - New operation code: not checked for validity.
Since:
2.0.0

setSourceMACAddress

public void setSourceMACAddress(MACAddress macAddress)
Set the source hardware address.

This method also calls super.setSourceMACAddress() to set the corresponding field in the Ethernet header.

Overrides:
setSourceMACAddress in class EthernetPacket
Parameters:
macAddress - Source MAC address.
Since:
2.0.0

getSourceProtoAddress

public String getSourceProtoAddress()
Fetch the sender protocol address.


setSourceProtoAddress

public void setSourceProtoAddress(InetAddress address)
Set the source protocol address.

Parameters:
address - Source IP address.
Since:
2.0.0

setDestinationMACAddress

public void setDestinationMACAddress(MACAddress macAddress)
Set the destination hardware address.

This method also calls super.setDestinationMACAddress() to set the corresponding field in the Ethernet header.

Overrides:
setDestinationMACAddress in class EthernetPacket
Parameters:
macAddress - Destination MAC address.
Since:
2.0.0

getDestinationProtoAddress

public String getDestinationProtoAddress()
Fetch the destination protocol address.


setDestinationProtoAddress

public void setDestinationProtoAddress(InetAddress address)
Set the destination protocol address.

Parameters:
address - Destination IP address.
Since:
2.0.0

getARPHeader

public byte[] getARPHeader()
Fetch the arp header, excluding arp data payload.

Returns:
the ARP header

getARPData

public byte[] getARPData()
Fetch data portion of the arp packet.

Returns:
the ARP data

getHeader

public byte[] getHeader()
Fetch header portion of the packet. This is overridden in derived classes to return the header appropriate to the packet class. For example:

Overrides:
getHeader in class EthernetPacket

getData

public byte[] getData()
Fetch the data portion of the packet. This is overridden in derived classes to return successively smaller and smaller amounts of data. For example:

Overrides:
getData in class EthernetPacket

toColoredString

public String toColoredString(boolean colored)
Generate string with contents describing this packet.

Overrides:
toColoredString in class EthernetPacket
Parameters:
colored - whether or not the string should contain ansi color escape sequences.

getColor

public String getColor()
Fetch ASCII escape sequence of the color associated with this packet type.

Overrides:
getColor in class EthernetPacket
Returns:
ASCII escape sequence string

Copyright © Patrick Charles & Jonas Lehmann, 2001; Esmond Pitt, 2008.