org.jnetpcap
Class PcapHeader

java.lang.Object
  extended by org.jnetpcap.nio.JMemory
      extended by org.jnetpcap.nio.JStruct
          extended by org.jnetpcap.PcapHeader
All Implemented Interfaces:
JCaptureHeader

public class PcapHeader
extends JStruct
implements JCaptureHeader

 struct pkt_header {
  struct timeval ts; // ts.tv_sec, ts.tv_usec
  uint32 caplen;     // captured length
  uint32 len;        // original length
 }
 

Author:
Mark Bednarczyk, Sly Technologies, Inc.

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
PcapHeader()
           
PcapHeader(int caplen, int wirelen)
           
PcapHeader(JMemory.Type type)
           
 
Method Summary
 int caplen()
          Retrieves the length of the packet that was actually captured.
 void caplen(int caplen)
           
 int hdr_len()
           
 void hdr_len(int len)
           
 long hdr_sec()
           
 void hdr_sec(long ts)
           
 int hdr_usec()
           
 void hdr_usec(int ts)
           
 int hdr_wirelen()
           
 void hdr_wirelen(int len)
           
 void initFrom(JCaptureHeader captureHeader)
           
 long nanos()
          Fractional part of the second when the packet was captured.
 void nanos(long nanos)
           
 int peer(JBuffer memory, int offset)
           
 int peerTo(JBuffer buffer, int offset)
           
 int peerTo(PcapHeader header, int offset)
           
 long seconds()
          Capture timestamp in UNIX seconds
 void seconds(long seconds)
           
static int sizeof()
          Size of the pcap_pkthdr structure in bytes.
 long timestampInMicros()
           
 long timestampInMillis()
           
 long timestampInNanos()
           
 int transferTo(byte[] m, int offset)
           
 int transferTo(JBuffer m, int offset)
           
 int wirelen()
          Retrieves the length of the packet before any of it was truncated by the capture mechanism.
 void wirelen(int wirelen)
           
 
Methods inherited from class org.jnetpcap.nio.JStruct
getStructName, toString
 
Methods inherited from class org.jnetpcap.nio.JMemory
check, cleanup, finalize, isInitialized, isJMemoryBasedOwner, isOwner, peer, peer, peer, setSize, size, toDebugString, toHexdump, toHexdump, totalActiveAllocated, totalAllocateCalls, totalAllocated, totalAllocatedSegments0To255Bytes, totalAllocatedSegments256OrAbove, totalDeAllocateCalls, totalDeAllocated, transferFrom, transferFrom, transferFrom, transferFrom, transferFromDirect, transferOwnership, transferTo, transferTo, transferTo, transferTo, transferTo, transferTo, transferTo
 
Methods inherited from class java.lang.Object
clone, equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

STRUCT_NAME

public static final java.lang.String STRUCT_NAME
See Also:
Constant Field Values
Constructor Detail

PcapHeader

public PcapHeader()

PcapHeader

public PcapHeader(int caplen,
                  int wirelen)
Parameters:
caplen -
wirelen -

PcapHeader

public PcapHeader(JMemory.Type type)
Method Detail

sizeof

public static int sizeof()
Size of the pcap_pkthdr structure in bytes.

Returns:
size of structure

caplen

public int caplen()
Description copied from interface: JCaptureHeader
Retrieves the length of the packet that was actually captured. This could be only a portion of the original packet if snaplen filter was set during Pcap.openXXX call. If the packet was not trucated, this length should equal the length returned by JCaptureHeader.wirelen().

Specified by:
caplen in interface JCaptureHeader
Returns:
length in bytes

hdr_len

public int hdr_len()

hdr_len

public void hdr_len(int len)

hdr_sec

public long hdr_sec()

hdr_sec

public void hdr_sec(long ts)

hdr_usec

public int hdr_usec()

hdr_usec

public void hdr_usec(int ts)

hdr_wirelen

public int hdr_wirelen()

hdr_wirelen

public void hdr_wirelen(int len)

nanos

public long nanos()
Description copied from interface: JCaptureHeader
Fractional part of the second when the packet was captured. If the resolution of the original capture timestamp is lower than nano seconds, they are converted to nano seconds. For example of the capture timestamp is in micro seconds, then the micro seconds fraction is multiplied by a 1000 before being returned to conform to nano second return timestamp.

Specified by:
nanos in interface JCaptureHeader
Returns:
Number of nano seconds at the time of the packet capture. The valid value returned by this method is from 0 to 999,999,999.

peer

public int peer(JBuffer memory,
                int offset)

peerTo

public int peerTo(JBuffer buffer,
                  int offset)

peerTo

public int peerTo(PcapHeader header,
                  int offset)

seconds

public long seconds()
Description copied from interface: JCaptureHeader
Capture timestamp in UNIX seconds

Specified by:
seconds in interface JCaptureHeader
Returns:
timestamp in seconds since 1970

timestampInMillis

public long timestampInMillis()
Specified by:
timestampInMillis in interface JCaptureHeader

transferTo

public int transferTo(JBuffer m,
                      int offset)

transferTo

public int transferTo(byte[] m,
                      int offset)

wirelen

public int wirelen()
Description copied from interface: JCaptureHeader
Retrieves the length of the packet before any of it was truncated by the capture mechanism. This is the size of the orignal packet as it was send accross the network.

Specified by:
wirelen in interface JCaptureHeader
Returns:
length in bytes

caplen

public void caplen(int caplen)
Specified by:
caplen in interface JCaptureHeader

nanos

public void nanos(long nanos)
Specified by:
nanos in interface JCaptureHeader

seconds

public void seconds(long seconds)
Specified by:
seconds in interface JCaptureHeader

wirelen

public void wirelen(int wirelen)
Specified by:
wirelen in interface JCaptureHeader

initFrom

public void initFrom(JCaptureHeader captureHeader)
Specified by:
initFrom in interface JCaptureHeader

timestampInNanos

public long timestampInNanos()
Specified by:
timestampInNanos in interface JCaptureHeader

timestampInMicros

public long timestampInMicros()
Specified by:
timestampInMicros in interface JCaptureHeader