|
|||||||||
| 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 int |
FLAG_TRUNCATED
Flag which is set when the packet that was decoded was truncated and not the original length seen on the wire. |
static java.lang.String |
STRUCT_NAME
The Constant STRUCT_NAME. |
| Fields inherited from class org.jnetpcap.nio.JMemory |
|---|
JNETPCAP_LIBRARY_NAME, MAX_DIRECT_MEMORY_DEFAULT, POINTER |
| Constructor Summary | |
|---|---|
JPacket.State(int size)
Instantiates a new state. |
|
JPacket.State(JMemory.Type type)
Instantiates a new state. |
|
| Method Summary | |
|---|---|
void |
cleanup()
Cleanup. |
int |
findHeaderIndex(int id)
Find header index. |
int |
findHeaderIndex(int id,
int instance)
Find header index. |
long |
get64BitHeaderMap(int index)
Gets the 64 bit header map. |
int |
getFlags()
Gets the 32-bit counter that contains packet's flags in packet_state_t structure. |
JFlowKey |
getFlowKey()
Gets the flow key. |
long |
getFrameNumber()
The frame number is assigned by the scanner at the time of the scan. |
int |
getHeaderCount()
Gets the header count. |
int |
getHeaderIdByIndex(int index)
Gets the header id by index. |
int |
getHeaderLengthByIndex(int index)
A convenience method that gets the length in the packet buffer of the header at specified index. |
int |
getHeaderOffsetByIndex(int index)
A convenience method that gets the offset into the packet buffer of the header at specified index. |
int |
getInstanceCount(int id)
Gets the instance count. |
int |
getWirelen()
Gets the packet's wire length. |
int |
peer(java.nio.ByteBuffer peer)
Peer. |
int |
peer(JBuffer peer)
Peer. |
int |
peer(JBuffer peer,
int offset,
int length)
Peer. |
int |
peer(JMemory memory,
int offset)
Peer. |
int |
peer(JMemoryPool.Block peer,
int offset,
int length)
Peer. |
int |
peer(JPacket.State peer)
Peer. |
int |
peerHeaderById(int id,
int instance,
JHeader.State dst)
Peer header by id. |
int |
peerHeaderByIndex(int index,
JHeader.State dst)
Peer header by index. |
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)
Peer to. |
void |
setFlags(int flags)
Sets the 32-bit counter with packet flags. |
void |
setWirelen(int length)
Sets the packet's wire length. |
static int |
sizeof(int count)
Sizeof. |
java.lang.String |
toDebugString()
Dump packet_state_t structure and its sub structures to textual debug output |
int |
transferTo(byte[] dst,
int dstOffset)
Transfer to. |
int |
transferTo(byte[] dst,
int srcOffset,
int length,
int dstOffset)
Transfer to. |
int |
transferTo(JBuffer dst,
int srcOffset,
int length,
int dstOffset)
Transfer to. |
int |
transferTo(JPacket.State dst)
Transfer to. |
| Methods inherited from class org.jnetpcap.nio.JStruct |
|---|
getStructName, toString |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
| Field Detail |
|---|
public static final int FLAG_TRUNCATED
public static final java.lang.String STRUCT_NAME
| Constructor Detail |
|---|
public JPacket.State(int size)
size - the sizepublic JPacket.State(JMemory.Type type)
type - the type| Method Detail |
|---|
public static int sizeof(int count)
count - header counter, number of headers to calaculate in
public void cleanup()
cleanup in class JMemoryJMemory.cleanup()public int findHeaderIndex(int id)
id - the id
public int findHeaderIndex(int id,
int instance)
id - the idinstance - the instance
public long get64BitHeaderMap(int index)
index - TODO: remove index, its no longer used natively
public int getFlags()
public JFlowKey getFlowKey()
public long getFrameNumber()
public int getHeaderCount()
public int getHeaderIdByIndex(int index)
index - the index
public int getHeaderLengthByIndex(int index)
index - header index
public int getHeaderOffsetByIndex(int index)
index - header index
public int getInstanceCount(int id)
id - the id
public int getWirelen()
public int peer(java.nio.ByteBuffer peer)
throws PeeringException
peer in class JMemorypeer - the peer
PeeringException - the peering exceptionJMemory.peer(java.nio.ByteBuffer)public int peer(JBuffer peer)
peer - the peer
public int peer(JBuffer peer,
int offset,
int length)
throws java.lang.IndexOutOfBoundsException
peer - the peeroffset - the offsetlength - the length
java.lang.IndexOutOfBoundsException - the index out of bounds exception
public int peer(JMemory memory,
int offset)
memory - the memoryoffset - the offset
public int peer(JMemoryPool.Block peer,
int offset,
int length)
throws java.lang.IndexOutOfBoundsException
peer - the peeroffset - the offsetlength - the length
java.lang.IndexOutOfBoundsException - the index out of bounds exceptionpublic int peer(JPacket.State peer)
peer - the peer
public int peerHeaderById(int id,
int instance,
JHeader.State dst)
id - the idinstance - the instancedst - the dst
public int peerHeaderByIndex(int index,
JHeader.State dst)
throws java.lang.IndexOutOfBoundsException
index - the indexdst - the dst
java.lang.IndexOutOfBoundsException - the index out of bounds exception
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 - the stateoffset - the offset
public void setFlags(int flags)
flags - bit flags for this packetpublic void setWirelen(int length)
length - the original length of the packet before truncationpublic 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)
dst - the dstdstOffset - the dst offset
public int transferTo(byte[] dst,
int srcOffset,
int length,
int dstOffset)
transferTo in class JMemorydst - the dstsrcOffset - the src offsetlength - the lengthdstOffset - the dst offset
JMemory.transferTo(byte[], int, int, int)
public int transferTo(JBuffer dst,
int srcOffset,
int length,
int dstOffset)
transferTo in class JMemorydst - the dstsrcOffset - the src offsetlength - the lengthdstOffset - the dst offset
JMemory.transferTo(org.jnetpcap.nio.JBuffer, int,
int, int)public int transferTo(JPacket.State dst)
dst - the dst
|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||