|
|||||||||
| 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.JStruct
org.jnetpcap.packet.JPacket.State
public static class JPacket.State
Class maintains the decoded packet state. The class is peered with
struct packet_state_t
typedef struct packet_state_t {
uint64_t pkt_header_map; // bit map of presence of headers
char *pkt_data; // packet data buffer
int32_t pkt_header_count; // total number of headers found
// Keep track of how many instances of each header we have
uint8_t pkt_instance_counts[MAX_ID_COUNT];
header_t pkt_headers[]; // One per header + 1 more for payload
} packet_t;
and struct header_t
typedef struct header_t {
int32_t hdr_id; // header ID
uint32_t hdr_offset; // offset into the packet_t->data buffer
int32_t hdr_length; // length of the header in packet_t->data buffer
} header_t;
The methods in this State provide 3 sets of functions.
Looking up global state of the packet found in packet_state_t structure,
looking up header information in struct header_t by header
ID retrieved from JRegistry and instance numbers, looking up header
information by direct indexes into native maps and arrays. Instance numbers
specify which instance of the header, if more than 1 exists in a packet.
For example if there is a packet with 2 Ip4 headers such as
Ethernet->Ip4->Snmp->Ip4 or Ethernet->Ip4->Ip4 (IP tunneled IP)the first Ip4 header is instance 0 and the second Ip4 header is instance 2. You can use the method
getInstanceCount(int) to learn how many
instance headers exists. That information is stored in the packet_state_t
structure for efficiency.
| Nested Class Summary |
|---|
| Nested classes/interfaces inherited from class org.jnetpcap.nio.JMemory |
|---|
JMemory.Type |
| Field Summary | |
|---|---|
static java.lang.String |
STRUCT_NAME
|
| Fields inherited from class org.jnetpcap.nio.JMemory |
|---|
JNETPCAP_LIBRARY_NAME |
| Constructor Summary | |
|---|---|
JPacket.State(int size)
|
|
JPacket.State(JMemory.Type type)
|
|
| Method Summary | |
|---|---|
void |
cleanup()
Called to clean up and release any allocated memory. |
int |
findHeaderIndex(int id)
|
int |
findHeaderIndex(int id,
int instance)
|
long |
get64BitHeaderMap(int index)
|
JAnalysis |
getAnalysis()
Retrieves the analysis object that is attached to this packet. |
JAnalysis |
getAnalysis(int index)
Retrieves the analysis object htat is attached to the header at index. |
JFlowKey |
getFlowKey()
|
long |
getFrameNumber()
The frame number is assigned by the scanner at the time of the scan. |
int |
getHeaderCount()
|
int |
getHeaderIdByIndex(int index)
|
int |
getInstanceCount(int id)
|
int |
peer(java.nio.ByteBuffer peer)
Peers the src structure with this instance. |
int |
peer(JBuffer peer)
|
int |
peer(JBuffer peer,
int offset,
int length)
|
int |
peer(JMemory memory,
int offset)
|
int |
peer(JMemoryPool.Block peer,
int offset,
int length)
|
int |
peer(JPacket.State peer)
|
int |
peerHeaderById(int id,
int instance,
JHeader.State dst)
|
int |
peerHeaderByIndex(int index,
JHeader.State dst)
|
int |
peerTo(JBuffer buffer,
int offset)
Peers this packet's state to buffer |
int |
peerTo(JBuffer buffer,
int offset,
int size)
Peers this packet's state to buffer |
int |
peerTo(JPacket.State state,
int offset)
|
void |
setAnalysis(JAnalysis analysis)
Sets the analysis object for this packet. |
static int |
sizeof(int count)
|
java.lang.String |
toDebugString()
Dump packet_state_t structure and its sub structures to textual debug output |
int |
transferTo(byte[] dst,
int dstOffset)
|
int |
transferTo(byte[] dst,
int srcOffset,
int length,
int dstOffset)
Copies data from memory to byte array |
int |
transferTo(JBuffer dst,
int srcOffset,
int length,
int dstOffset)
Transfers the contents of this memory to buffer. |
int |
transferTo(JPacket.State dst)
|
| Methods inherited from class org.jnetpcap.nio.JStruct |
|---|
getStructName, toString |
| Methods inherited from class org.jnetpcap.nio.JMemory |
|---|
check, finalize, isInitialized, isJMemoryBasedOwner, isOwner, peer, peer, setSize, size, toHexdump, toHexdump, totalActiveAllocated, totalAllocateCalls, totalAllocated, totalAllocatedSegments0To255Bytes, totalAllocatedSegments256OrAbove, totalDeAllocateCalls, totalDeAllocated, transferFrom, transferFrom, 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 |
| Field Detail |
|---|
public static final java.lang.String STRUCT_NAME
| Constructor Detail |
|---|
public JPacket.State(int size)
size - public JPacket.State(JMemory.Type type)
| Method Detail |
|---|
public static int sizeof(int count)
count - header counter, number of headers to calaculate in
public void cleanup()
JMemory
cleanup in class JMemorypublic int findHeaderIndex(int id)
public int findHeaderIndex(int id,
int instance)
public long get64BitHeaderMap(int index)
index - TODO: remove index, its no longer used natively
public JAnalysis getAnalysis()
public JAnalysis getAnalysis(int index)
index - index of the header within the packet state structure
public JFlowKey getFlowKey()
public long getFrameNumber()
public int getHeaderCount()
public int getHeaderIdByIndex(int index)
public int getInstanceCount(int id)
public int peer(java.nio.ByteBuffer peer)
throws PeeringException
JMemoryFurther more, since we are peering with a ByteBuffer, the actual memory that is peered is between ByteBuffer's position and limit properties. Those 2 properties determine which portion of the memory that will be peered. This allows a larger ByteBuffer to be peered with different objects providing rudimentary memory allocation mechanism.
Lastly care must be taken, to ensure that the lifespans do not conflict.
The memory that we are peering to must not be deallocated prior the
termination of the lifespan of this object or at minimum calling
JMemory.cleanup() method to ensure that this object no longer references
memory which may have been or become deallocated.
peer in class JMemorypeer - The ByteBuffer whose allocated native memory we want to peer with.
The ByteByffer must be if direct buffer type which can be checked
using ByteBuffer.isDirect() call.
PeeringExceptionByteBuffer.isDirect()public int peer(JBuffer peer)
public int peer(JBuffer peer,
int offset,
int length)
throws java.lang.IndexOutOfBoundsException
java.lang.IndexOutOfBoundsException
public int peer(JMemory memory,
int offset)
memory - offset -
public int peer(JMemoryPool.Block peer,
int offset,
int length)
throws java.lang.IndexOutOfBoundsException
java.lang.IndexOutOfBoundsExceptionpublic int peer(JPacket.State peer)
public int peerHeaderById(int id,
int instance,
JHeader.State dst)
public int peerHeaderByIndex(int index,
JHeader.State dst)
throws java.lang.IndexOutOfBoundsException
java.lang.IndexOutOfBoundsException
public int peerTo(JBuffer buffer,
int offset)
buffer - source bufferoffset - offset into the buffer
public int peerTo(JBuffer buffer,
int offset,
int size)
buffer - source bufferoffset - offset into the buffersize - specifies the number of bytes to peer
public int peerTo(JPacket.State state,
int offset)
state - offset - public void setAnalysis(JAnalysis analysis)
analysis - public java.lang.String toDebugString()
Explanation:
sizeof(packet_state_t)=16 sizeof(header_t)=8 and *4=32 pkt_header_map=0x1007 // bitmap, each bit represets a header pkt_header_count=4 // how many header found // per header information (4 header found in this example) pkt_headers[0]=<hdr_id=1 ETHERNET ,hdr_offset=0 ,hdr_length=14> pkt_headers[1]=<hdr_id=2 IP4 ,hdr_offset=14 ,hdr_length=60> pkt_headers[2]=<hdr_id=12 ICMP ,hdr_offset=74 ,hdr_length=2> pkt_headers[3]=<hdr_id=0 PAYLOAD ,hdr_offset=76 ,hdr_length=62> // hdr_id = numerical ID of the header, asssigned by JRegistry // hdr_offset = offset in bytes into the packet buffer // hdr_length = length in bytes of the entire headerPacket state is made up of 2 structures: packet_stat_t and an array of header_t, one per header. Total size in bytes is all of the header structures combined, that is 16 + 32 = 48 bytes. Each bit in the header_map represents the presence of that header type. The index of the bit is the numerical ID of the header. If 2 headers of the same type are present, they are both represented by a single bit in the bitmap. This way the implementation JPacket.hasHeader(int id) is a simple bit operation to test if the header is present or not.
toDebugString in class JMemory
public int transferTo(byte[] dst,
int dstOffset)
public int transferTo(byte[] dst,
int srcOffset,
int length,
int dstOffset)
JMemory
transferTo in class JMemorydst - destination buffersrcOffset - starting offset in memorylength - number of bytes to copydstOffset - starting offset in byte array
public int transferTo(JBuffer dst,
int srcOffset,
int length,
int dstOffset)
JMemory
transferTo in class JMemorydst - destination buffersrcOffset - offset in sourcelength - number of bytes to copydstOffset - offset in destination buffer
public int transferTo(JPacket.State dst)
|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||