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 int LENGTH
          Length of the libpcap pcap header in bytes.
static java.lang.String STRUCT_NAME
          Name of the native structure.
 
Fields inherited from class org.jnetpcap.nio.JMemory
JNETPCAP_LIBRARY_NAME, MAX_DIRECT_MEMORY_DEFAULT, POINTER
 
Constructor Summary
PcapHeader()
          Creates a header structure with allocated memory.
PcapHeader(int caplen, int wirelen)
          Creates a header structure with initial values.
PcapHeader(JMemory.Type type)
          Creates an empty pcap header suitable for peering.
 
Method Summary
 int caplen()
          Gets the caplen field from the structure.
 void caplen(int caplen)
          Unsupported operation.
 int hdr_len()
          Gets the hdr_len field from the structure.
 void hdr_len(int len)
          Sets the hdr_len field.
 long hdr_sec()
          Gets the hdr_sec field value.
 void hdr_sec(long ts)
          Sets the hdr_sec field.
 int hdr_usec()
          Gets the hdr_usec field.
 void hdr_usec(int ts)
          Sets the hdr_usec field.
 int hdr_wirelen()
          Gets the hdr_wirelen field.
 void hdr_wirelen(int len)
          Sets the hdr_wirelen field.
 void initFrom(JCaptureHeader captureHeader)
          Unsupported operation.
 long nanos()
          Converts hdr_usec field into nano seconds.
 void nanos(long nanos)
          Unsupported operation.
 int peer(JBuffer memory, int offset)
          Peers this header object with the supplied memory object.
 int peerTo(JBuffer buffer, int offset)
          Peers this header with the supplied buffer.
 int peerTo(PcapHeader header, int offset)
          Peers this header to the user supplied header.
 long seconds()
          Gets the hdr_sec field.
 void seconds(long seconds)
          Unsupported operation.
static int sizeof()
          Size of the pcap_pkthdr structure in bytes.
 long timestampInMicros()
          Converts the hdr_sec and hdr_usec fields into a micro second absolute timestamp.
 long timestampInMillis()
          Converts the hdr_sec and hdr_usec fields into a java style absolute timestamp suitable for usage with java's Date object.
 long timestampInNanos()
          Converts the hdr_sec and hdr_usec fields into a nano second absolute timestamp.
 int transferTo(byte[] m, int offset)
          Copies contents of this buffer into supplied byte array buffer.
 int transferTo(JBuffer m, int offset)
          Copies contents of this header to supplied buffer.
 int wirelen()
          Gets the value of hdr_wirelen field.
 void wirelen(int wirelen)
          Unsupported operation.
 
Methods inherited from class org.jnetpcap.nio.JStruct
getStructName, toString
 
Methods inherited from class org.jnetpcap.nio.JMemory
availableDirectMemory, check, cleanup, createReference, isInitialized, isJMemoryBasedOwner, isOwner, maxDirectMemory, peer, peer, peer, reservedDirectMemory, setSize, size, softDirectMemory, toDebugString, toHexdump, toHexdump, totalActiveAllocated, totalAllocateCalls, totalAllocated, totalAllocatedSegments0To255Bytes, totalAllocatedSegments256OrAbove, totalDeAllocateCalls, totalDeAllocated, transferFrom, transferFrom, transferFrom, transferFrom, transferFromDirect, transferOwnership, transferTo, transferTo, transferTo, transferTo, transferTo, transferTo, transferTo, transferTo0
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

STRUCT_NAME

public static final java.lang.String STRUCT_NAME
Name of the native structure.

See Also:
Constant Field Values

LENGTH

public static final int LENGTH
Length of the libpcap pcap header in bytes. This may differ from what sizeof() method returns due to native compiler padding for byte aligment.

See Also:
Constant Field Values
Constructor Detail

PcapHeader

public PcapHeader()
Creates a header structure with allocated memory. All fields are initialized to defaults.


PcapHeader

public PcapHeader(int caplen,
                  int wirelen)
Creates a header structure with initial values.

Parameters:
caplen - buffer size
wirelen - original packet length

PcapHeader

public PcapHeader(JMemory.Type type)
Creates an empty pcap header suitable for peering.

Parameters:
type - memory allocation model type
Method Detail

sizeof

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

Returns:
size of structure

caplen

public int caplen()
Gets the caplen field from the structure.

Specified by:
caplen in interface JCaptureHeader
Returns:
size of the capture packet data

hdr_len

public int hdr_len()
Gets the hdr_len field from the structure.

Returns:
value of the hdr_len field

hdr_len

public void hdr_len(int len)
Sets the hdr_len field.

Parameters:
len - new value for hdr_len field

hdr_sec

public long hdr_sec()
Gets the hdr_sec field value.

Returns:
value of the hdr_sec field

hdr_sec

public void hdr_sec(long ts)
Sets the hdr_sec field.

Parameters:
ts - new value for hdr_sec field

hdr_usec

public int hdr_usec()
Gets the hdr_usec field.

Returns:
value of the hdr_usec field

hdr_usec

public void hdr_usec(int ts)
Sets the hdr_usec field.

Parameters:
ts - new value for hdr_usec field

hdr_wirelen

public int hdr_wirelen()
Gets the hdr_wirelen field.

Returns:
value of the hdr_wirelen field

hdr_wirelen

public void hdr_wirelen(int len)
Sets the hdr_wirelen field.

Parameters:
len - new value for hdr_wirelen field

nanos

public long nanos()
Converts hdr_usec field into nano seconds.

Specified by:
nanos in interface JCaptureHeader
Returns:
converted value of the hdr_usec field

peer

public int peer(JBuffer memory,
                int offset)
Peers this header object with the supplied memory object.

Parameters:
memory - object to peer with this header
offset - offset into memory object
Returns:
number of bytes peered

peerTo

public int peerTo(JBuffer buffer,
                  int offset)
Peers this header with the supplied buffer.

Parameters:
buffer - buffer to peer with
offset - offset into the buffer
Returns:
number of bytes peered

peerTo

public int peerTo(PcapHeader header,
                  int offset)
Peers this header to the user supplied header.

Parameters:
header - header to peer with
offset - offset into the supplied header
Returns:
number of bytes peered

seconds

public long seconds()
Gets the hdr_sec field.

Specified by:
seconds in interface JCaptureHeader
Returns:
value of the hdr_sec field

timestampInMillis

public long timestampInMillis()
Converts the hdr_sec and hdr_usec fields into a java style absolute timestamp suitable for usage with java's Date object.

Specified by:
timestampInMillis in interface JCaptureHeader
Returns:
absolute capture timestamp in milli-seconds

transferTo

public int transferTo(JBuffer m,
                      int offset)
Copies contents of this header to supplied buffer.

Parameters:
m - buffer to copy to
offset - offset into the buffer
Returns:
number of bytes copied

transferTo

public int transferTo(byte[] m,
                      int offset)
Copies contents of this buffer into supplied byte array buffer.

Parameters:
m - buffer to copy to
offset - offset into the buffer
Returns:
number of bytes copied

wirelen

public int wirelen()
Gets the value of hdr_wirelen field.

Specified by:
wirelen in interface JCaptureHeader
Returns:
value of hdr_wirelen field

caplen

public void caplen(int caplen)
Unsupported operation.

Specified by:
caplen in interface JCaptureHeader
Parameters:
caplen - ignored

nanos

public void nanos(long nanos)
Unsupported operation.

Specified by:
nanos in interface JCaptureHeader
Parameters:
nanos - ignored

seconds

public void seconds(long seconds)
Unsupported operation.

Specified by:
seconds in interface JCaptureHeader
Parameters:
seconds - ignored

wirelen

public void wirelen(int wirelen)
Unsupported operation.

Specified by:
wirelen in interface JCaptureHeader
Parameters:
wirelen - ignored

initFrom

public void initFrom(JCaptureHeader captureHeader)
Unsupported operation.

Specified by:
initFrom in interface JCaptureHeader
Parameters:
captureHeader - ignored

timestampInNanos

public long timestampInNanos()
Converts the hdr_sec and hdr_usec fields into a nano second absolute timestamp. The timestamp still maintains micro-second resolution.

Specified by:
timestampInNanos in interface JCaptureHeader
Returns:
absolute timestamp in nano seconds

timestampInMicros

public long timestampInMicros()
Converts the hdr_sec and hdr_usec fields into a micro second absolute timestamp.

Specified by:
timestampInMicros in interface JCaptureHeader
Returns:
absolute timestamp in micro seconds