|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Objectorg.jnetpcap.nio.JMemory
org.jnetpcap.nio.JBuffer
org.jnetpcap.packet.JPacket
public abstract class JPacket
A native packet buffer object. This class references both packet data buffer and decoded native packet structure. JPacket class is a subclass of a more general JBuffer providing full access to raw packet buffer data. It also has a reference to JPacket.State object which is peered, associated with, a native packet state structure generated by the packet scanner, the JScanner.
The packet interface provides numerous methods for accessing the decoded
information. To check if any particular header is found within the packet's
data buffer at the time the packet was scanned, the user can use
hasHeader(int) methods. The method returns true if a particular header is
found within the packet data buffer, otherwise false. A convenience method
hasHeader(JHeader) exists that performs both an existance check and
initializes the header instace supplied to point at the header within the
packet.
There are also numerous peer and deep copy methods. The peering methods do not copy any buffers but simply re-orient the pointers to point at the source peer structures to destination peer. The deep copy methods do copy physical data out of buffers and entire structures using native copy functions, not in java space.
| Nested Class Summary | |
|---|---|
static class |
JPacket.State
Class maintains the decoded packet state. |
| Nested classes/interfaces inherited from class org.jnetpcap.nio.JMemory |
|---|
JMemory.Type |
| Field Summary | |
|---|---|
static int |
DEFAULT_STATE_HEADER_COUNT
Default number of headers used when calculating memory requirements for an empty packet state structure. |
protected static JScanner |
defaultScanner
Default scanner used to scan a packet per user request. |
protected JBuffer |
memory
The allocated memory buffer. |
protected static JMemoryPool |
pool
Packet's default memory pool out of which allocates memory for deep copies. |
protected JPacket.State |
state
Packet's state structure. |
| Fields inherited from class org.jnetpcap.nio.JMemory |
|---|
JNETPCAP_LIBRARY_NAME, MAX_DIRECT_MEMORY_DEFAULT, POINTER |
| Constructor Summary | |
|---|---|
JPacket(int size,
int state)
Allocates a memory block and peers both the state and data buffer with it. |
|
JPacket(JMemory.Type type)
A JPacket pointer. |
|
| Method Summary | ||
|---|---|---|
void |
allocate(int size)
Creates a new memory buffer of given size for internal usage. |
|
int |
getAllocatedMemorySize()
Gets the size of the current internal memory buffer. |
|
abstract JCaptureHeader |
getCaptureHeader()
Gets the capture header as generated by the native capture library. |
|
static JScanner |
getDefaultScanner()
Returns the default scanner for all packets |
|
static JFormatter |
getFormatter()
Gets the current internal packet formatter used in the toString()
method. |
|
long |
getFrameNumber()
Returns the frame number as assigned by either the packet scanner or analyzers. |
|
|
getHeader(T header)
Peers the supplied header with the native header state structure and packet data buffer. |
|
|
getHeader(T header,
int instance)
Peers the supplied header with the native header state structure and packet data buffer. |
|
|
getHeaderByIndex(int index,
T header)
Peers a header with specific index, not the numerical header ID assigned by JRegistry, of a header. |
|
int |
getHeaderCount()
Gets number of headers found within the packet header. |
|
int |
getHeaderIdByIndex(int index)
Gets the numerical ID of the header at specified index into header array as found by the packet scanner. |
|
int |
getHeaderInstanceCount(int id)
Gets number of headers with the same numerical ID as assigned by JRegistry within the same packet. |
|
protected JBuffer |
getMemoryBuffer(byte[] buffer)
Gets the memory buffer with the supplied byte array data copied into it. |
|
protected JBuffer |
getMemoryBuffer(java.nio.ByteBuffer buffer)
Gets the memory buffer with the supplied ByteBuffer data copied into it. |
|
protected JBuffer |
getMemoryBuffer(int minSize)
Retrieves a memory buffer, allocated if neccessary, at least minSize in bytes. |
|
protected JBuffer |
getMemoryBuffer(JBuffer buffer)
Gets the memory buffer with the supplied JBuffer data copied into it. |
|
static JMemoryPool |
getMemoryPool()
Gets the current memory allocation memory pool. |
|
int |
getPacketWirelen()
Gets the wire length of the packet. |
|
JScanner |
getScanner()
Deprecated. use static getDefaultScanner() instead |
|
JPacket.State |
getState()
Gets the peered packet state object |
|
abstract int |
getTotalSize()
Gets the total size of this packet. |
|
boolean |
hasHeader(int id)
Checks if header with specified numerical ID exists within the decoded packet. |
|
boolean |
hasHeader(int id,
int instance)
Check if requested instance of header with specified numerical ID exists within the decoded packet. |
|
|
hasHeader(T header)
Check if requested instance of header with specified numerical ID exists within the decoded packet and if found peers the supplied header with the located header within the decoded packet. |
|
|
hasHeader(T header,
int instance)
Check if requested instance of header with specified numerical ID exists within the decoded packet and if found peers the supplied header with the located header within the decoded packet. |
|
int |
remaining(int offset)
Calculates the number of bytes remaining within the packet given a specific offset. |
|
int |
remaining(int offset,
int length)
Calculates the remaining number of bytes within the packet buffer taking into account offset and length of a header supplied. |
|
void |
scan(int id)
Scan and decode the packet using current scanner. |
|
static void |
setFormatter(JFormatter out)
Replaced the default formatter for formatting output in the. |
|
static void |
setMemoryPool(JMemoryPool pool)
Replaces the default memory allocation mechanism with user supplied one. |
|
static void |
shutdown()
Shutdown. |
|
java.lang.String |
toHexdump()
Formats packet raw data as a hexdump output and marks header boundaries with special characters. |
|
java.lang.String |
toString()
Generates text formatted output using the default builtin formatter. |
|
| 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 java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
| Field Detail |
|---|
public static final int DEFAULT_STATE_HEADER_COUNT
protected static JScanner defaultScanner
protected static JMemoryPool pool
protected final JBuffer memory
protected final JPacket.State state
| Constructor Detail |
|---|
public JPacket(int size,
int state)
size - amount of memory to allocate for packet datastate - size of the statepublic JPacket(JMemory.Type type)
JPacket constists of 2 peers. The first and the main memory peering is with the packet_state_t structure which stores information about the decoded state of the packet, another words the result of the scanned packet data buffer. The second peer is to the actual packet data buffer which is a seperate pointer.
transferStateAndDataTo which will copy the packet state and/or
data buffer into another memory area, such as a direct ByteBuffer or
JBuffer.
type - the type| Method Detail |
|---|
public static JScanner getDefaultScanner()
public static void shutdown()
public static JFormatter getFormatter()
toString()
method.
public static JMemoryPool getMemoryPool()
public static void setFormatter(JFormatter out)
out - new formatter toString() method. The new formatter will be
used by default for all packets. The formatter should internally
build a string that will be returned with out.toString() method
call to get meaningfull output.public static void setMemoryPool(JMemoryPool pool)
pool - new memory pool to use.public void allocate(int size)
size - size in bytespublic int getAllocatedMemorySize()
public abstract JCaptureHeader getCaptureHeader()
public long getFrameNumber()
public <T extends JHeader> T getHeader(T header)
getHeader in interface JHeaderAccessorT - name of the headerheader - instance of a header object
public <T extends JHeader> T getHeader(T header,
int instance)
getHeader in interface JHeaderAccessorT - name of the headerheader - instance of a header objectinstance - instance number of the header since more than one header of the
same type can exist in the same packet buffer
public <T extends JHeader> T getHeaderByIndex(int index,
T header)
throws java.lang.IndexOutOfBoundsException
getHeaderByIndex in interface JHeaderAccessorT - name of the headerindex - index into the header array the scanner has foundheader - instance of a header object
java.lang.IndexOutOfBoundsException - the index out of bounds exceptionpublic int getHeaderCount()
getHeaderCount in interface JHeaderAccessorpublic int getHeaderIdByIndex(int index)
getHeaderIdByIndex in interface JHeaderAccessorindex - index into the header array
public int getHeaderInstanceCount(int id)
getHeaderInstanceCount in interface JHeaderAccessorid - numerical ID of the header to search for
protected JBuffer getMemoryBuffer(byte[] buffer)
buffer - source array buffer to copy data out of
protected JBuffer getMemoryBuffer(java.nio.ByteBuffer buffer)
throws PeeringException
buffer - source array buffer to copy data out of
PeeringException - the peering exceptionprotected JBuffer getMemoryBuffer(int minSize)
minSize - minimum number of bytes required for the buffer
protected JBuffer getMemoryBuffer(JBuffer buffer)
buffer - source array buffer to copy data out of
public int getPacketWirelen()
@Deprecated public JScanner getScanner()
getDefaultScanner() instead
public JPacket.State getState()
public abstract int getTotalSize()
public boolean hasHeader(int id)
hasHeader in interface JHeaderAccessorid - protocol header ID as assigned by JRegistry
public boolean hasHeader(int id,
int instance)
hasHeader in interface JHeaderAccessorid - protocol header ID as assigned by JRegistryinstance - instance number of the specific header within the packet
public <T extends JHeader> boolean hasHeader(T header)
hasHeader in interface JHeaderAccessorT - name of the header typeheader - protocol header object instance
public <T extends JHeader> boolean hasHeader(T header,
int instance)
hasHeader in interface JHeaderAccessorT - name of the header typeheader - protocol header object instanceinstance - instance number of the specific header within the packet
public int remaining(int offset)
offset - offset into the packet in bytes
public int remaining(int offset,
int length)
offset - offset of the header to take into accountlength - length of the header
public void scan(int id)
id - numerical ID as assigned by JRegistry of the first protocol header
to be found in the packet, the DLTpublic java.lang.String toHexdump()
toHexdump in class JMemorypublic java.lang.String toString()
toString in class java.lang.Object
|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||