net.sourceforge.jpcap.net
Class EthernetPacket

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

public class EthernetPacket
extends Packet

An ethernet packet.

Contains link-level information in 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.


Constructor Summary
EthernetPacket(int lLen, byte[] bytes, java.lang.String macSourceAddress, java.lang.String macDestinationAddress)
          Construct a new, unrecognized ethernet packet.
EthernetPacket(int lLen, byte[] bytes, java.lang.String macSourceAddress, java.lang.String macDestinationAddress, int typeCode)
          Construct a new, recognized ethernet packet.
 
Method Summary
 byte[] getData()
          Fetch data portion of the ethernet header.
 java.lang.String getDestinationHwAddress()
           
 byte[] getHeader()
          Fetch the ethernet header, excluding data payload.
 java.lang.String getSourceHwAddress()
           
 int getType()
          Fetch the code stored in the ethernet type field which indicates the type of datagram embedded in 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,
                      java.lang.String macSourceAddress,
                      java.lang.String macDestinationAddress)
Construct a new, unrecognized ethernet packet.

If the ethernet packet type is not recognized, the ethernet type field is populated with 'unknown'.


EthernetPacket

public EthernetPacket(int lLen,
                      byte[] bytes,
                      java.lang.String macSourceAddress,
                      java.lang.String macDestinationAddress,
                      int typeCode)
Construct a new, recognized ethernet packet.

When the type of the ethernet packet is known, it can be subclassified into a deriving class like IPPacket. The subclass then sets the ethernet type code to the appropriate and corresponding value.

Method Detail

getHeader

public byte[] getHeader()
Fetch the ethernet header, excluding data payload.

getData

public byte[] getData()
Fetch data portion of the ethernet header.

getSourceHwAddress

public java.lang.String getSourceHwAddress()

getDestinationHwAddress

public java.lang.String getDestinationHwAddress()

getType

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

toString

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