org.jnetpcap.protocol.lan
Class Ethernet

java.lang.Object
  extended by org.jnetpcap.nio.JMemory
      extended by org.jnetpcap.nio.JBuffer
          extended by org.jnetpcap.packet.JHeader
              extended by org.jnetpcap.protocol.lan.Ethernet
All Implemented Interfaces:
JPayloadAccessor

@Header(length=14,
        dlt={EN10MB,FDDI},
        osi=DATALINK,
        characteristics=CSMA_CD,
        nicname="Eth",
        description="Ethernet",
        url="http://en.wikipedia.org/wiki/Ethernet")
public class Ethernet
extends JHeader

Ethernet2 definition. Datalink layer ethernet frame definition.

Author:
Mark Bednarczyk, Sly Technologies, Inc.

Nested Class Summary
static class Ethernet.EthernetType
          A table of EtherType values and their names.
 
Nested classes/interfaces inherited from class org.jnetpcap.packet.JHeader
JHeader.State
 
Nested classes/interfaces inherited from class org.jnetpcap.nio.JMemory
JMemory.Type
 
Field Summary
static int ADDRESS_IG_BIT
          The Constant ADDRESS_IG_BIT.
static int ADDRESS_LG_BIT
          The Constant ADDRESS_LG_BIT.
static int ID
          The Constant ID.
static int LENGTH
          The Constant LENGTH.
static java.lang.String ORG_IEEE
          The Constant ORG_IEEE.
 
Fields inherited from class org.jnetpcap.packet.JHeader
annotatedHeader, BYTE, EMPTY_HEADER_ARRAY, isSubHeader, packet, state
 
Fields inherited from class org.jnetpcap.nio.JMemory
JNETPCAP_LIBRARY_NAME, MAX_DIRECT_MEMORY_DEFAULT, POINTER
 
Constructor Summary
Ethernet()
           
 
Method Summary
 long calculateChecksum()
          Calculate checksum.
 long checksum()
          Retrieves the header's checksum.
 boolean checksum(long crc)
          Sets the checksum, Ethernet.FCS field in the last 4 bytes of the packet buffer, which is also the Ethernet trailer part or jNetPcap 'postfix'.
 boolean checksumCheck()
          Checks if FCS is available for this Ethernet frame.
 java.lang.String checksumDescription()
          Checksum description.
 int checksumOffset()
          Calculates the offset of the FCS field within the Ethernet frame.
 long destination_IG()
          Destination_ ig.
 long destination_LG()
          Destination_ lg.
 byte[] destination()
          Destination.
 void destination(byte[] array)
          Destination.
 byte[] destinationToByteArray(byte[] array)
          Destination to byte array.
 void formatHeader(java.util.List<JField> fields)
          Format header.
 long source_IG()
          Source_ ig.
 long source_LG()
          Source_ lg.
 byte[] source()
          Source.
 void source(byte[] array)
          Source.
 byte[] sourceToByteArray(byte[] array)
          Source to byte array.
 int type()
          Type.
 void type(int type)
          Type.
 java.lang.String typeDescription()
          Type description.
 Ethernet.EthernetType typeEnum()
          Type enum.
 
Methods inherited from class org.jnetpcap.packet.JHeader
decode, decodeHeader, getAnnotatedHeader, getDescription, getFields, getGap, getGapLength, getGapOffset, getHeader, getHeaderLength, getHeaderOffset, getId, getIndex, getLength, getName, getNextHeaderId, getNextHeaderOffset, getNicname, getOffset, getPacket, getParent, getPayload, getPayloadLength, getPayloadOffset, getPostfix, getPostfixLength, getPostfixOffset, getPrefix, getPrefixLength, getPrefixOffset, getPreviousHeaderId, getPreviousHeaderOffset, getState, getSubHeaders, hasDescription, hasGap, hasNextHeader, hasPayload, hasPostfix, hasPrefix, hasPreviousHeader, hasSubHeaders, isFragmented, isGapTruncated, isHeaderTruncated, isPayloadTruncated, isPostfixTruncated, isPrefixTruncated, peer, peer, peerPayloadTo, setPacket, setSubHeaders, sizeof, toString, transferPayloadTo, transferPayloadTo, transferPayloadTo, validateHeader
 
Methods inherited from class org.jnetpcap.nio.JBuffer
findUTF8String, getByte, getByteArray, getByteArray, getByteArray, getDouble, getFloat, getInt, getLong, getShort, getUByte, getUInt, getUShort, getUTF8Char, getUTF8String, getUTF8String, getUTF8String, getUTF8String, isReadonly, order, order, peer, peer, peer, peer, setByte, setByteArray, setByteBuffer, setDouble, setFloat, setInt, setLong, setShort, setShort0, setUByte, setUInt, setUShort, transferFrom, transferFrom, transferFrom, transferTo, transferTo, transferTo
 
Methods inherited from class org.jnetpcap.nio.JMemory
availableDirectMemory, check, cleanup, createReference, isInitialized, isJMemoryBasedOwner, isOwner, maxDirectMemory, peer, reservedDirectMemory, setSize, size, softDirectMemory, toDebugString, toHexdump, toHexdump, totalActiveAllocated, totalAllocateCalls, totalAllocated, totalAllocatedSegments0To255Bytes, totalAllocatedSegments256OrAbove, totalDeAllocateCalls, totalDeAllocated, transferFrom, transferFrom, transferFromDirect, transferOwnership, transferTo, transferTo, transferTo, transferTo, transferTo, transferTo0
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

ADDRESS_IG_BIT

public static final int ADDRESS_IG_BIT
The Constant ADDRESS_IG_BIT.

See Also:
Constant Field Values

ADDRESS_LG_BIT

public static final int ADDRESS_LG_BIT
The Constant ADDRESS_LG_BIT.

See Also:
Constant Field Values

ID

public static final int ID
The Constant ID.

See Also:
Constant Field Values

LENGTH

public static final int LENGTH
The Constant LENGTH.

See Also:
Constant Field Values

ORG_IEEE

public static final java.lang.String ORG_IEEE
The Constant ORG_IEEE.

See Also:
Constant Field Values
Constructor Detail

Ethernet

public Ethernet()
Method Detail

destination

@Field(offset=0,
       length=48,
       format="#mac#",
       mask=281470681743360L)
public byte[] destination()
Destination.

Returns:
the byte[]

destination_IG

@Field(parent="destination",
       offset=40,
       length=1,
       display="IG bit")
@FlowKey(index=0)
public long destination_IG()
Destination_ ig.

Returns:
the long

destination_LG

@Field(parent="destination",
       offset=41,
       length=1,
       display="LG bit")
public long destination_LG()
Destination_ lg.

Returns:
the long

destination

public void destination(byte[] array)
Destination.

Parameters:
array - the array

destinationToByteArray

public byte[] destinationToByteArray(byte[] array)
Destination to byte array.

Parameters:
array - the array
Returns:
the byte[]

source

@Field(offset=48,
       length=48,
       format="#mac#",
       mask=281470681743360L)
@FlowKey(index=0)
public byte[] source()
Source.

Returns:
the byte[]

source_IG

@Field(parent="source",
       offset=40,
       length=1,
       display="IG bit")
public long source_IG()
Source_ ig.

Returns:
the long

source_LG

@Field(parent="source",
       offset=41,
       length=1,
       display="LG bit")
public long source_LG()
Source_ lg.

Returns:
the long

source

public void source(byte[] array)
Source.

Parameters:
array - the array

sourceToByteArray

public byte[] sourceToByteArray(byte[] array)
Source to byte array.

Parameters:
array - the array
Returns:
the byte[]

type

@Field(offset=96,
       length=16,
       format="%x")
@FlowKey(index=1)
public int type()
Type.

Returns:
the int

type

public void type(int type)
Type.

Parameters:
type - the type

typeDescription

@Dynamic(value=DESCRIPTION)
public java.lang.String typeDescription()
Type description.

Returns:
the string

formatHeader

public void formatHeader(java.util.List<JField> fields)
Format header.

Parameters:
fields - the fields

typeEnum

public Ethernet.EthernetType typeEnum()
Type enum.

Returns:
the ethernet type

checksumCheck

@Dynamic(field="checksum",
         value=CHECK)
public boolean checksumCheck()
Checks if FCS is available for this Ethernet frame. FCS is typically stripped by the OS and not provided to Libpcap/jNetPcap on most platforms.

Returns:
true if FCS is present, otherwise false

checksumOffset

@Dynamic(value=OFFSET)
public int checksumOffset()
Calculates the offset of the FCS field within the Ethernet frame.

Returns:
offset, in bits, from the start of the packet buffer

checksumDescription

@Dynamic(value=DESCRIPTION)
public java.lang.String checksumDescription()
Checksum description.

Returns:
the string

checksum

@Field(length=32,
       format="%x",
       display="FCS")
public long checksum()
Retrieves the header's checksum.

Returns:
header's stored checksum

checksum

public boolean checksum(long crc)
Sets the checksum, Ethernet.FCS field in the last 4 bytes of the packet buffer, which is also the Ethernet trailer part or jNetPcap 'postfix'. The method checks if last 4 bytes are actually part of physical Ethernet trailer. If not, the method returns without an error, but FCS is not set.

Parameters:
crc - the crc
Returns:
true if checksum was set, otherwise if Ethernet trailer part or Ethernet postfix part is less then 4 bytes long, returns false

calculateChecksum

public long calculateChecksum()
Calculate checksum.

Returns:
the long