java.lang.Object
org.jnetpcap.PcapHeader
A Pcap packet header also called a descriptor that precedes each packet. The
pcap header is supplied natively by libpcap library and
PcapHeader
can bind to native memory without copy to access its fields.
PcapHeader
supplies vital information about the captured packet.
These fields disclaim the length of the data capture and if a packet was
truncated with snaplen parameter on the Pcap
handle, the
packet length as originally seen on the wire. Additionally a timestamp of the
instant when the packet was captured.
- Author:
- Sly Technologies Inc, repos@slytechs.com
- See Also:
-
Constructor Summary
ConstructorDescriptionPcapHeader
(int tvSec, int tvUsec, int captureLength, int wireLength) Instantiates a new pcap header.PcapHeader
(MemorySegment mseg) Instantiates a new pcap header.PcapHeader
(MemorySegment mseg, boolean isSwapped) Instantiates a new pcap header.PcapHeader
(MemorySegment mseg, boolean isSwapped, boolean isCompactAbi) Instantiates a new pcap header.PcapHeader
(ByteBuffer headerBuffer) Instantiates a new pcap header. -
Method Summary
Modifier and TypeMethodDescriptionAs memory reference.As memory segment.int
Capture length.static int
captureLength
(MemorySegment headerSegment) Packet capture length for offline file capture.static int
captureLength
(MemorySegment headerSegment, boolean isSwapped) Packet capture length for offline file capture.static int
captureLength
(ByteBuffer headerBuffer) Packet capture length.static int
captureLength
(ByteBuffer headerBuffer, boolean isSwapped) Packet capture length for offline file capture.int
The length of this header.setNanoTimePrecision
(boolean nanoTime) Sets a flag if the timestamp for this header is calculated using nanosecond or the default microsecond precision.long
Timestamp with 32-bit seconds (MSB bits) and 32-bit usecs (LSB bits) from a base of January 1, 1970.long
timestamp
(boolean nanoTime) Timestamp in either nano or milli second precision.long
To epoch milli.long
toEpochMilli
(boolean nanoTime) To epoch milli.toString()
To string.long
tvSec()
Tv sec.long
tvUsec()
Tv usec.int
Wire length.static int
wireLength
(MemorySegment headerSegment) Packet wire length.static int
wireLength
(MemorySegment headerSegment, boolean isSwapped) Packet wire length for offline file capture.static int
wireLength
(ByteBuffer headerBuffer) Packet wire length .static int
wireLength
(ByteBuffer headerBuffer, boolean isSwapped) Packet wire length for offline file capture.
-
Constructor Details
-
PcapHeader
Instantiates a new pcap header.- Parameters:
headerBuffer
- the header buffer
-
PcapHeader
public PcapHeader(int tvSec, int tvUsec, int captureLength, int wireLength) Instantiates a new pcap header.- Parameters:
tvSec
- the tv sectvUsec
- the tv useccaptureLength
- the capture lengthwireLength
- the wire length
-
PcapHeader
Instantiates a new pcap header.- Parameters:
mseg
- thestruct pcap_pkthdr
memory address.
-
PcapHeader
Instantiates a new pcap header.- Parameters:
mseg
- thestruct pcap_pkthdr
memory address.isSwapped
- the flag indicates that the header is referencing memory for an offline capture and that the header field byte may be swapped, as recorded based on the original capture system architecture.
-
PcapHeader
Instantiates a new pcap header.- Parameters:
mseg
- thestruct pcap_pkthdr
memory address.isSwapped
- the flag indicates that the header is referencing memory for an offline capture and that the header field byte may be swapped, as recorded based on the original capture system architecture. *isCompactAbi
- if true, forces the pcap binary interface to use the compact form.- See Also:
-
-
Method Details
-
captureLength
public static int captureLength(ByteBuffer headerBuffer) throws PcapHeaderException.OutOfRangeException Packet capture length.- Parameters:
headerBuffer
- the buffer containing pcap header contents- Returns:
- the number of packet bytes captured
- Throws:
PcapHeaderException.OutOfRangeException
- the out of range exception, typically indicates invalid ABI (Application Binary Interface) setting which is platform and offline capture file dependent
-
captureLength
public static int captureLength(ByteBuffer headerBuffer, boolean isSwapped) throws PcapHeaderException.OutOfRangeException Packet capture length for offline file capture.- Parameters:
headerBuffer
- the buffer containing pcap header contentsisSwapped
- for offline files which were captured according to the capturing system ABI, the bytes written maybe swapped for this system's architecture.- Returns:
- the number of packet bytes captured
- Throws:
PcapHeaderException.OutOfRangeException
- the out of range exception, typically indicates invalid ABI (Application Binary Interface) setting which is platform and offline capture file dependent
-
captureLength
public static int captureLength(MemorySegment headerSegment) throws PcapHeaderException.OutOfRangeException Packet capture length for offline file capture.- Parameters:
headerSegment
- the memory segment containing pcap header contents- Returns:
- the number of packet bytes captured
- Throws:
PcapHeaderException.OutOfRangeException
- the out of range exception, typically indicates invalid ABI (Application Binary Interface) setting which is platform and offline capture file dependent
-
captureLength
public static int captureLength(MemorySegment headerSegment, boolean isSwapped) throws PcapHeaderException.OutOfRangeException Packet capture length for offline file capture.- Parameters:
headerSegment
- the memory segment containing pcap header contentsisSwapped
- for offline files which were captured according to the capturing system ABI, the bytes written maybe swapped for this system's architecture.- Returns:
- the number of packet bytes captured
- Throws:
PcapHeaderException.OutOfRangeException
- the out of range exception, typically indicates invalid ABI (Application Binary Interface) setting which is platform and offline capture file dependent
-
wireLength
public static int wireLength(ByteBuffer headerBuffer) throws PcapHeaderException.OutOfRangeException Packet wire length .- Parameters:
headerBuffer
- the buffer containing pcap header contents- Returns:
- the number of packet bytes originally seen on the network wire/wireless before truncation due to "snaplen" parameter if set.
- Throws:
PcapHeaderException.OutOfRangeException
- the out of range exception, typically indicates invalid ABI (Application Binary Interface) setting which is platform and offline capture file dependent
-
wireLength
public static int wireLength(ByteBuffer headerBuffer, boolean isSwapped) throws PcapHeaderException.OutOfRangeException Packet wire length for offline file capture.- Parameters:
headerBuffer
- the buffer containing pcap header contentsisSwapped
- for offline files which were captured according to the capturing system ABI, the bytes written maybe swapped for this system's architecture.- Returns:
- the number of packet bytes originally seen on the network wire/wireless before truncation due to "snaplen" parameter if set.
- Throws:
PcapHeaderException.OutOfRangeException
- the out of range exception, typically indicates invalid ABI (Application Binary Interface) setting which is platform and offline capture file dependent
-
wireLength
public static int wireLength(MemorySegment headerSegment) throws PcapHeaderException.OutOfRangeException Packet wire length.- Parameters:
headerSegment
- the memory segment containing pcap header contents- Returns:
- the number of packet bytes originally seen on the network wire/wireless before truncation due to "snaplen" parameter if set.
- Throws:
PcapHeaderException.OutOfRangeException
- the out of range exception, typically indicates invalid ABI (Application Binary Interface) setting which is platform and offline capture file dependent
-
wireLength
public static int wireLength(MemorySegment headerSegment, boolean isSwapped) throws PcapHeaderException.OutOfRangeException Packet wire length for offline file capture.- Parameters:
headerSegment
- the memory segment containing pcap header contentsisSwapped
- for offline files which were captured according to the capturing system ABI, the bytes written maybe swapped for this system's architecture.- Returns:
- the number of packet bytes originally seen on the network wire/wireless before truncation due to "snaplen" parameter if set.
- Throws:
PcapHeaderException.OutOfRangeException
- the out of range exception, typically indicates invalid ABI (Application Binary Interface) setting which is platform and offline capture file dependent
-
asMemoryReference
-
asMemorySegment
-
captureLength
Capture length.- Returns:
- the int
- Throws:
PcapHeaderException.OutOfRangeException
- the out of range exception
-
headerLength
public int headerLength()The length of this header.- Returns:
- the length of this header in bytes.
-
setNanoTimePrecision
Sets a flag if the timestamp for this header is calculated using nanosecond or the default microsecond precision.- Parameters:
nanoTime
- if true, a call totimestamp()
ortoEpochMilli()
will use nano second precision- Returns:
- this pcap header
-
timestamp
Timestamp with 32-bit seconds (MSB bits) and 32-bit usecs (LSB bits) from a base of January 1, 1970.- Returns:
- the long
- Throws:
PcapHeaderException
- the pcap header exception
-
timestamp
Timestamp in either nano or milli second precision.- Parameters:
nanoTime
- if true, timestamp is returned with nano second precision, otherwise millis is returned- Returns:
- the timestamp value as 64-bit long
- Throws:
PcapHeaderException
- the pcap header exception
-
toEpochMilli
To epoch milli.- Returns:
- the long
- Throws:
PcapHeaderException
- the pcap header exception
-
toEpochMilli
To epoch milli.- Parameters:
nanoTime
- the nano time- Returns:
- the long
- Throws:
PcapHeaderException
- the pcap header exception
-
toString
-
tvSec
Tv sec.- Returns:
- the int
- Throws:
PcapHeaderException
- the pcap header exception
-
tvUsec
Tv usec.- Returns:
- the int
- Throws:
PcapHeaderException
- the pcap header exception
-
wireLength
Wire length.- Returns:
- the int
- Throws:
PcapHeaderException
- the pcap header exception
-