net.sourceforge.jpcap.net
Class EthernetPacket

java.lang.Object
  |
  +--net.sourceforge.jpcap.net.Packet
        |
        +--net.sourceforge.jpcap.net.EthernetPacket
All Implemented Interfaces:
EthernetFields
Direct Known Subclasses:
ARPPacket, IPPacket

public class EthernetPacket
extends Packet
implements EthernetFields

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.


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 data portion of the ethernet header.
 java.lang.String getDestinationHwAddress()
          Fetch the hardware address of the target host.
 byte[] getHeader()
          Fetch the ethernet header, excluding data payload.
 int getProtocol()
          Fetch the code stored in the ethernet type field which indicates the type of datagram embedded in this packet.
 java.lang.String getSourceHwAddress()
          Fetch the hardware address from which the packet originated.
 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
 

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

getHeader

public byte[] getHeader()
Fetch the ethernet header, excluding data payload.
Overrides:
getHeader in class Packet

getData

public byte[] getData()
Fetch data portion of the ethernet header.
Overrides:
getData in class Packet

getSourceHwAddress

public java.lang.String getSourceHwAddress()
Fetch the hardware address from which the packet originated.

getDestinationHwAddress

public java.lang.String getDestinationHwAddress()
Fetch the hardware address of the target host.

getProtocol

public int getProtocol()
Fetch the code stored in the ethernet type field which indicates the type of datagram embedded in this packet. @see EthernetProtocols.

toString

public java.lang.String toString()
Convert this ethernet packet to a readable string.
Overrides:
toString in class java.lang.Object

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