Module org.jnetpcap

Record Class PcapPacketRef

java.lang.Object
java.lang.Record
org.jnetpcap.util.PcapPacketRef
Record Components:
abi - platform specific ABI (Abstract Binary Interface)
header - raw pcap header in a memory segment
data - raw packet data in a memory segment

public record PcapPacketRef(Object abi, MemorySegmentPREVIEW header, MemorySegmentPREVIEW data) extends Record
PcapPacketRef relies on preview features of the Java platform:
  • PcapPacketRef refers to one or more preview APIs: MemorySegment.
Programs can only use PcapPacketRef when preview features are enabled.
Preview features may be removed in a future release, or upgraded to permanent features of the Java platform.
A utility class which holds references to native pcap header and native pcap packet data. The scope of these addresses is libpcap packet scope and should be used with great care or VM crashes can occur.
Author:
Sly Technologies Inc, repos@slytechs.com
  • Constructor Details

    • PcapPacketRef

      public PcapPacketRef(Object abi, MemorySegmentPREVIEW header, MemorySegmentPREVIEW data)
      Creates an instance of a PcapPacketRef record class.
      Parameters:
      abi - the value for the abi record component
      header - the value for the header record component
      data - the value for the data record component
  • Method Details

    • toArray

      public byte[] toArray()
      Returns byte[] representation of the entire packet.
      Returns:
      the byte[] containing packet bytes
    • captureLength

      public int captureLength()
      Capture length of the packet.
      Returns:
      the capture length pcap header field value
    • wireLength

      public int wireLength()
      Wire length of the packet.
      Returns:
      the wire length pcap header field value
    • tvSec

      public long tvSec()
      The timestamp in seconds in epoch time.
      Returns:
      the epoch seconds since Jan 1st, 1970.
    • tvUsec

      public long tvUsec()
      The timestamp fraction of a second.
      Returns:
      fraction of a second in micros or nanos.
    • toArray

      public byte[] toArray(int offset, int length)
      Returns an array containing only the packet bytes starting at offset and offset + length.
      Parameters:
      offset - the offset offset into the packet
      length - number of bytes starting at the offset
      Returns:
      the byte[] containing the selected bytes
    • toString

      public final String toString()
      Returns a string representation of this record class. The representation contains the name of the class, followed by the name and value of each of the record components.
      Specified by:
      toString in class Record
      Returns:
      a string representation of this object
    • hashCode

      public final int hashCode()
      Returns a hash code value for this object. The value is derived from the hash code of each of the record components.
      Specified by:
      hashCode in class Record
      Returns:
      a hash code value for this object
    • equals

      public final boolean equals(Object o)
      Indicates whether some other object is "equal to" this one. The objects are equal if the other object is of the same class and if all the record components are equal. All components in this record class are compared with Objects::equals(Object,Object).
      Specified by:
      equals in class Record
      Parameters:
      o - the object with which to compare
      Returns:
      true if this object is the same as the o argument; false otherwise.
    • abi

      public Object abi()
      Returns the value of the abi record component.
      Returns:
      the value of the abi record component
    • header

      public MemorySegmentPREVIEW header()
      Returns the value of the header record component.
      Returns:
      the value of the header record component
    • data

      public MemorySegmentPREVIEW data()
      Returns the value of the data record component.
      Returns:
      the value of the data record component