org.jnetpcap.packet
Class JHeader

java.lang.Object
  extended by org.jnetpcap.nio.JMemory
      extended by org.jnetpcap.nio.JBuffer
          extended by org.jnetpcap.packet.JHeader
All Implemented Interfaces:
JByteBuffer
Direct Known Subclasses:
Ethernet, Html, IEEE802dot1q, IEEE802dot2, IEEE802dot3, IEEESnap, Ip6, JHeaderMap, JMappedHeader, JSubHeader, L2TP, Payload, PPP, Tcp, Udp

public abstract class JHeader
extends JBuffer

A base class for all protocol header definitions.

Author:
Mark Bednarczyk, Sly Technologies, Inc.

Nested Class Summary
static class JHeader.State
          This class is peered state of a header a native state structure
 
Nested classes/interfaces inherited from class org.jnetpcap.nio.JMemory
JMemory.Type
 
Field Summary
protected  AnnotatedHeader annotatedHeader
           
protected static JHeader[] EMPTY_HEADER_ARRAY
           
protected  boolean isSubHeader
           
protected  JPacket packet
          A reference to the packet that this header is part of
protected  JHeader.State state
          Reference to header's native state structure
 
Fields inherited from class org.jnetpcap.nio.JMemory
JNETPCAP_LIBRARY_NAME
 
Constructor Summary
JHeader()
          Calls on the header defintion's static annotated \@HeaderLength method to get header's length.
JHeader(int id, JField[] fields, java.lang.String name)
          Constructs a header and initializes its static fields
JHeader(int id, JField[] fields, java.lang.String name, java.lang.String nicname)
          Constructs a header and initializes its static fields
JHeader(int id, java.lang.String name)
          Constructs a header.
JHeader(int id, java.lang.String name, java.lang.String nicname)
          Constructs a header.
JHeader(JHeader.State state, JField[] fields, java.lang.String name, java.lang.String nicname)
          Constructs a header and initializes its static fields
JHeader(JProtocol protocol)
           
 
Method Summary
 void addAnalysis(JAnalysis analysis)
           
 void decode()
          Method that gets called everytime a header is successfully peered with new buffer and/or state structure.
protected  void decodeHeader()
          Allows a header to decode its complex fields
<T extends JAnalysis>
T
getAnalysis(T analysis)
           
 java.lang.Iterable<JAnalysis> getAnalysisIterable()
           
 AnnotatedHeader getAnnotatedHeader()
           
 java.lang.String getDescription()
           
 JField[] getFields()
          Retrieves the fields at runtime, that this header has so that they may be used by a formatter
 int getId()
          Gets the numerical ID of this protocol header at runtime as assigned by the JRegistry
 int getLength()
          Length of this header within the buffer
 java.lang.String getName()
          Gets the comprehensive name for this header
 java.lang.String getNicname()
          Gets the short name for this header
 int getOffset()
          Offset into the packet buffer
 JPacket getPacket()
          Gets the packet that this header is associated with
 JHeader getParent()
           
 JHeader.State getState()
          Gets the reference to the current header's native state structure
 JHeader[] getSubHeaders()
          Gets an array of currently defined sub headers
 int getType()
           
 boolean hasAnalysis(java.lang.Class<? extends JAnalysis> analysis)
           
 boolean hasAnalysis(int type)
           
<T extends JAnalysis>
boolean
hasAnalysis(T analysis)
           
 boolean hasDescription()
           
 boolean hasSubHeaders()
           
 int peer(JBuffer buffer, int offset)
           
 int peer(JHeader header)
          Peers, associates a native packet buffer and scanner structure with this header.
 void setPacket(JPacket packet)
          Sets the packet that this header should be associated with
 void setSubHeaders(JHeader[] headers)
           
static int sizeof()
          Gets the size of the native header_t structure on this particular platform
 java.lang.String toString()
          Gets a string with summary information about the header.
protected  void validateHeader()
          Allows a header to validate its values
 
Methods inherited from class org.jnetpcap.nio.JBuffer
findUTF8String, getByte, 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, setUByte, setUInt, setUShort, transferFrom, transferFrom, transferFrom, transferTo, transferTo, transferTo
 
Methods inherited from class org.jnetpcap.nio.JMemory
check, cleanup, finalize, isInitialized, isJMemoryBasedOwner, isOwner, peer, setSize, size, toDebugString, toHexdump, toHexdump, totalActiveAllocated, totalAllocateCalls, totalAllocated, totalAllocatedSegments0To255Bytes, totalAllocatedSegments256OrAbove, totalDeAllocateCalls, totalDeAllocated, transferFrom, transferFrom, transferFromDirect, transferOwnership, transferTo, transferTo, transferTo, transferTo, transferTo
 
Methods inherited from class java.lang.Object
clone, equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface org.jnetpcap.nio.JByteBuffer
size
 

Field Detail

EMPTY_HEADER_ARRAY

protected static final JHeader[] EMPTY_HEADER_ARRAY

annotatedHeader

protected AnnotatedHeader annotatedHeader

isSubHeader

protected boolean isSubHeader

packet

protected JPacket packet
A reference to the packet that this header is part of


state

protected final JHeader.State state
Reference to header's native state structure

Constructor Detail

JHeader

public JHeader()
Calls on the header defintion's static annotated \@HeaderLength method to get header's length. The method is given a buffer and offset as the start of the header. The method invoked must be defined in the header definition otherwise an exception will be thrown.


JHeader

public JHeader(int id,
               JField[] fields,
               java.lang.String name)
Constructs a header and initializes its static fields

Parameters:
id - numerical ID of the protocol
fields - fields usd by the formatter to reformat the packet for output
name - comprehensive name of the protocol

JHeader

public JHeader(int id,
               JField[] fields,
               java.lang.String name,
               java.lang.String nicname)
Constructs a header and initializes its static fields

Parameters:
id - numerical ID of the protocol
fields - fields usd by the formatter to reformat the packet for output
name - comprehensive name of the protocol
nicname - a short name for the protocol

JHeader

public JHeader(int id,
               java.lang.String name)
Constructs a header.

Parameters:
id - numerical ID of the protocol
name - comprehensive name of the protocol

JHeader

public JHeader(int id,
               java.lang.String name,
               java.lang.String nicname)
Constructs a header.

Parameters:
id - numerical ID of the protocol
name - comprehensive name of the protocol
nicname - a short name for the protocol

JHeader

public JHeader(JProtocol protocol)

JHeader

public JHeader(JHeader.State state,
               JField[] fields,
               java.lang.String name,
               java.lang.String nicname)
Constructs a header and initializes its static fields

Parameters:
state - the default header state object being referenced
fields - fields usd by the formatter to reformat the packet for output
name - comprehensive name of the protocol
nicname - a short name for the protocol
Method Detail

sizeof

public static int sizeof()
Gets the size of the native header_t structure on this particular platform

Returns:
length in bytes

decode

public final void decode()
Method that gets called everytime a header is successfully peered with new buffer and/or state structure. This method in JHeader is empty and is expected to be overriden by subclasses of JHeader that require special processing of the header such as decoding its structure at runtime when the header object is bound to new state.


decodeHeader

protected void decodeHeader()
Allows a header to decode its complex fields


addAnalysis

public void addAnalysis(JAnalysis analysis)

getAnalysis

public <T extends JAnalysis> T getAnalysis(T analysis)

getAnnotatedHeader

public AnnotatedHeader getAnnotatedHeader()
Returns:

getDescription

public java.lang.String getDescription()
Returns:

getFields

public JField[] getFields()
Retrieves the fields at runtime, that this header has so that they may be used by a formatter

Returns:
an array of fields that this header is made up of, as determined at runtime

getId

public final int getId()
Gets the numerical ID of this protocol header at runtime as assigned by the JRegistry

Returns:
unique numerical ID of this header

getLength

public int getLength()
Length of this header within the buffer

Returns:
length in bytes

getName

public final java.lang.String getName()
Gets the comprehensive name for this header

Returns:
the name full name of this header

getNicname

public final java.lang.String getNicname()
Gets the short name for this header

Returns:
the nicname for this header

getOffset

public int getOffset()
Offset into the packet buffer

Returns:
offset into the buffer in bytes

getPacket

public final JPacket getPacket()
Gets the packet that this header is associated with

Returns:
parent packet

getParent

public JHeader getParent()

getState

public JHeader.State getState()
Gets the reference to the current header's native state structure

Returns:
current state of the header

getSubHeaders

public JHeader[] getSubHeaders()
Gets an array of currently defined sub headers

Returns:
array of sub headers

getType

public int getType()

hasAnalysis

public boolean hasAnalysis(int type)

hasAnalysis

public boolean hasAnalysis(java.lang.Class<? extends JAnalysis> analysis)

hasAnalysis

public <T extends JAnalysis> boolean hasAnalysis(T analysis)

hasDescription

public boolean hasDescription()
Returns:

hasSubHeaders

public boolean hasSubHeaders()

peer

public int peer(JBuffer buffer,
                int offset)

peer

public int peer(JHeader header)
Peers, associates a native packet buffer and scanner structure with this header. This header is unchanged while the header being passed in is rereferenced to point at this headers buffer and state structure.

Parameters:
header - the header to peer with this header
Returns:
number of bytes total that were peered with the supplied header

setPacket

public final void setPacket(JPacket packet)
Sets the packet that this header should be associated with

Parameters:
packet - packet to associate with this header

setSubHeaders

public void setSubHeaders(JHeader[] headers)

toString

public java.lang.String toString()
Gets a string with summary information about the header.

Overrides:
toString in class java.lang.Object
Returns:
String with summary of the header

validateHeader

protected void validateHeader()
Allows a header to validate its values


getAnalysisIterable

public java.lang.Iterable<JAnalysis> getAnalysisIterable()
Returns: