net.sourceforge.jpcap.net
Class EthernetEncoding

java.lang.Object
  |
  +--net.sourceforge.jpcap.net.EthernetEncoding

public class EthernetEncoding
extends java.lang.Object

Ethernet packet encoding.

Contains link-level information encoding information for an ethernet packet and methods for encoding and decoding ethernet headers.


Field Summary
static int CODE_LEN
          Width of the ethernet type code in bytes.
static int CODE_POS
          Position of the ethernet type field within the ethernet header.
static int HEADER_LEN
          Total length of an ethernet header in bytes.
static int MAC_DST_POS
          Position of the destination MAC address within the ethernet header.
static int MAC_SRC_POS
          Position of the source MAC address within the ethernet header.
 
Constructor Summary
EthernetEncoding()
           
 
Method Summary
static EthernetPacket create(int lLen, byte[] bytes)
          EthernetPacket factory.
static java.lang.String extractMACAddress(int lLen, boolean sourceFlag, byte[] packetBytes)
          Extract a MAC address from an ethernet header.
static int extractTypeCode(byte[] packetBytes)
          Extract the type field from packet data.
static byte[] generateRandomHeader()
          Generate a random ethernet header.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

CODE_LEN

public static final int CODE_LEN
Width of the ethernet type code in bytes.

MAC_DST_POS

public static final int MAC_DST_POS
Position of the destination MAC address within the ethernet header.

MAC_SRC_POS

public static final int MAC_SRC_POS
Position of the source MAC address within the ethernet header.

CODE_POS

public static final int CODE_POS
Position of the ethernet type field within the ethernet header.

HEADER_LEN

public static final int HEADER_LEN
Total length of an ethernet header in bytes.
Constructor Detail

EthernetEncoding

public EthernetEncoding()
Method Detail

create

public static EthernetPacket create(int lLen,
                                    byte[] bytes)
EthernetPacket factory. Convert raw packet data into a packet object.

generateRandomHeader

public static byte[] generateRandomHeader()
Generate a random ethernet header.

extractTypeCode

public static int extractTypeCode(byte[] packetBytes)
Extract the type field from packet data. The type field indicates what type of data is contained in the packet's data block.
Parameters:
packetBytes - packet bytes.
Returns:
the ethernet type code. i.e. 0x800 signifies IP datagram.

extractMACAddress

public static java.lang.String extractMACAddress(int lLen,
                                                 boolean sourceFlag,
                                                 byte[] packetBytes)
Extract a MAC address from an ethernet header.
Parameters:
sourceFlag - whether the extract query is for the source address.
packetBytes - packet bytes.