java.lang.Object
org.jnetpcap.PcapHeader
PcapHeader
relies on preview features of the Java platform:
PcapHeader
refers to one or more preview APIs:MemorySegment
.
Preview features may be removed in a future release, or upgraded to permanent features of the Java platform.
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.Instantiates a new pcap header.PcapHeader
(MemorySegmentPREVIEW mseg, boolean isSwapped) Instantiates a new pcap header.PcapHeader
(MemorySegmentPREVIEW 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
(MemorySegmentPREVIEW headerSegment) Packet capture length for offline file capture.static int
captureLength
(MemorySegmentPREVIEW 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
(MemorySegmentPREVIEW headerSegment) Packet wire length.static int
wireLength
(MemorySegmentPREVIEW 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(MemorySegmentPREVIEW 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(MemorySegmentPREVIEW 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(MemorySegmentPREVIEW 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(MemorySegmentPREVIEW 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
As memory reference.- Returns:
- the memory address
-
asMemorySegment
As memory segment.- Returns:
- the memory segment
-
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
To string. -
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
-
PcapHeader
when preview features are enabled.