net.sourceforge.jpcap.net
Class EthernetPacket

java.lang.Object
  extended bynet.sourceforge.jpcap.net.Packet
      extended bynet.sourceforge.jpcap.net.EthernetPacket
All Implemented Interfaces:
EthernetFields, java.io.Serializable
Direct Known Subclasses:
ARPPacket, IPPacket

public class EthernetPacket
extends Packet
implements EthernetFields, java.io.Serializable

An ethernet packet.

Contains link-level header and data payload encapsulated by an ethernet packet.

There are currently two subclasses. IP and ARP protocols are supported. IPPacket extends with ip header and data information. ARPPacket extends with hardware and protocol addresses.

See Also:
Serialized Form

Field Summary
protected  byte[] _bytes
           
protected  int _ethOffset
           
 
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
EthernetPacket(int lLen, byte[] bytes)
          Construct a new ethernet packet.
 
Method Summary
 java.lang.String getColor()
          Fetch ascii escape sequence of the color associated with this packet type.
 byte[] getData()
          fetch the ethernet data as a byte array
 java.lang.String getDestinationHwAddress()
          fetch the IP address of the host where the packet originated from
 byte[] getEthernetData()
          fetch the ethernet data as a byte array
 byte[] getEthernetHeader()
          fetch the ethernet header as a byte array
 int getEthernetHeaderLength()
          fetch the ethernet header length in bytes
 int getEthernetProtocol()
          fetches ethernet protocol
 byte[] getHeader()
          fetch the ethernet header as a byte array
 int getHeaderLength()
          fetch the packet ethernet header length
 int getProtocol()
          fetches ethernet protocol
 java.lang.String getSourceHwAddress()
          fetch the IP address of the host where the packet originated from
 java.lang.String toColoredString(boolean colored)
          Generate string with contents describing this ethernet packet.
 java.lang.String toString()
          Convert this ethernet packet to a readable string.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

_bytes

protected byte[] _bytes

_ethOffset

protected int _ethOffset
Constructor Detail

EthernetPacket

public EthernetPacket(int lLen,
                      byte[] bytes)
Construct a new ethernet packet.

For the purpose of jpcap, when the type of ethernet packet is recognized as a protocol for which a class exists network library, then a more specific class like IPPacket or ARPPacket is instantiated. The subclass can always be cast into a more generic form.

Method Detail

getEthernetHeaderLength

public int getEthernetHeaderLength()
fetch the ethernet header length in bytes


getHeaderLength

public int getHeaderLength()
fetch the packet ethernet header length


getEthernetHeader

public byte[] getEthernetHeader()
fetch the ethernet header as a byte array


getHeader

public byte[] getHeader()
fetch the ethernet header as a byte array

Overrides:
getHeader in class Packet

getEthernetData

public byte[] getEthernetData()
fetch the ethernet data as a byte array


getData

public byte[] getData()
fetch the ethernet data as a byte array

Overrides:
getData in class Packet

getSourceHwAddress

public java.lang.String getSourceHwAddress()
fetch the IP address of the host where the packet originated from


getDestinationHwAddress

public java.lang.String getDestinationHwAddress()
fetch the IP address of the host where the packet originated from


getEthernetProtocol

public int getEthernetProtocol()
fetches ethernet protocol


getProtocol

public int getProtocol()
fetches ethernet protocol


toString

public java.lang.String toString()
Convert this ethernet packet to a readable string.


toColoredString

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

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

getColor

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

Overrides:
getColor in class Packet