Class BaseNetPcap

java.lang.Object
com.slytechs.sdk.jnetpcap.api.BaseNetPcap
All Implemented Interfaces:
AutoCloseable
Direct Known Subclasses:
NetPcap

public abstract class BaseNetPcap extends Object implements AutoCloseable
Base class for NetPcap providing delegation to low-level Pcap bindings.

This class wraps a Pcap instance and provides pass-through access to all pcap operations. Fluent setter methods return BaseNetPcap to enable method chaining with covariant return type overrides in subclasses.

Author:
Mark Bednarczyk [mark@slytechs.com], Sly Technologies Inc.
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    protected final com.slytechs.sdk.jnetpcap.Pcap
     
  • Constructor Summary

    Constructors
    Modifier
    Constructor
    Description
    protected
    BaseNetPcap(com.slytechs.sdk.jnetpcap.Pcap pcapApi)
     
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    Activates a pcap handle created with create().
    void
    Forces a dispatch() or loop() call to return.
    boolean
    Checks whether monitor mode can be set on this capture handle.
    void
    Closes the capture handle and releases resources.
    com.slytechs.sdk.jnetpcap.BpFilter
    compile(String str, boolean optimize)
    Compiles a filter expression into a BPF program.
    com.slytechs.sdk.jnetpcap.BpFilter
    compile(String str, boolean optimize, int netmask)
    Compiles a filter expression with netmask.
    com.slytechs.sdk.jnetpcap.constant.PcapDlt
    Returns the link-layer header type.
    com.slytechs.sdk.jnetpcap.constant.PcapDlt
    Returns the link-layer header type with extended information.
    <U> int
    dispatch(int count, com.slytechs.sdk.jnetpcap.PcapDumper pcapDumper)
    Processes packets and writes them to a dump file.
    int
    dispatch(int count, com.slytechs.sdk.jnetpcap.PcapHandler.NativeCallback handler, MemorySegment user)
    Processes packets using a native callback.
    <U> int
    dispatch(int count, com.slytechs.sdk.jnetpcap.PcapHandler.OfArray<U> handler, U user)
    Processes packets using an array-based handler.
    <U> int
    dispatch(int count, com.slytechs.sdk.jnetpcap.PcapHandler.OfMemorySegment<U> handler, U user)
    Processes packets using a memory segment handler.
    com.slytechs.sdk.jnetpcap.PcapDumper
    Opens a dump file for writing packets.
    Returns the error message for the last pcap error.
    final String
    Returns the device name associated with this handle.
    boolean
    Returns the current non-blocking mode state.
    com.slytechs.sdk.jnetpcap.internal.PcapHeaderABI
    Returns the pcap header ABI information.
    com.slytechs.sdk.jnetpcap.constant.PcapTStampPrecision
    Returns the timestamp precision for this handle.
    final int
    inject(byte[] array)
    Transmits a packet, returning the number of bytes sent.
    final int
    inject(byte[] array, int offset, int length)
    Transmits a portion of a packet array.
    int
    inject(MemorySegment packet, int length)
    Transmits a packet from native memory.
    final int
    Transmits a packet from a ByteBuffer.
    boolean
    Checks if the capture file has different byte order.
    List<com.slytechs.sdk.jnetpcap.constant.PcapDlt>
    Returns the list of supported data link types.
    List<com.slytechs.sdk.jnetpcap.constant.PcapTstampType>
    Returns the list of supported timestamp types.
    <U> int
    loop(int count, com.slytechs.sdk.jnetpcap.PcapDumper pcapDumper)
    Processes packets in a loop and writes to a dump file.
    <U> int
    loop(int count, com.slytechs.sdk.jnetpcap.PcapHandler.NativeCallback handler, MemorySegment user)
    Processes packets in a loop using a native callback.
    <U> int
    loop(int count, com.slytechs.sdk.jnetpcap.PcapHandler.OfArray<U> handler, U user)
    Processes packets in a loop using an array handler.
    <U> int
    loop(int count, com.slytechs.sdk.jnetpcap.PcapHandler.OfMemorySegment<U> handler, U user)
    Processes packets in a loop using a memory segment handler.
    int
    Returns the major version of the pcap file format.
    int
    Returns the minor version of the pcap file format.
    abstract com.slytechs.sdk.protocol.core.Packet
    Retrieves the next packet.
    abstract com.slytechs.sdk.protocol.core.Packet
    Retrieves the next packet with extended status.
    final ByteOrder
    Returns the byte order of the capture file.
    perror(String prefix)
    Prints error message to stderr.
    final void
    sendPacket(byte[] buf)
    Sends a raw packet on the network.
    final void
    sendPacket(byte[] buf, int offset, int length)
    Sends a portion of a raw packet.
    void
    sendPacket(MemorySegment packet, int length)
    Sends a raw packet from native memory.
    final void
    Sends a raw packet from a ByteBuffer.
    setBufferSize(int bufferSize)
    Sets the kernel buffer size for the capture.
    setDatalink(int dlt)
    Sets the data link type for the capture.
    setDatalink(com.slytechs.sdk.jnetpcap.constant.PcapDlt dlt)
    Sets the data link type.
    setDatalink(Optional<com.slytechs.sdk.jnetpcap.constant.PcapDlt> dlt)
    Sets the data link type using an Optional.
    setDirection(int dir)
    Sets the capture direction.
    setDirection(com.slytechs.sdk.jnetpcap.constant.PcapDirection dir)
    Sets the capture direction.
    setDirection(Optional<com.slytechs.sdk.jnetpcap.constant.PcapDirection> dir)
    Sets the capture direction using an Optional.
    setFilter(com.slytechs.sdk.jnetpcap.BpFilter bpfProgram)
    Sets the BPF filter program.
    setFilter(Optional<com.slytechs.sdk.jnetpcap.BpFilter> bpfProgram)
    Sets the BPF filter using an Optional.
    setImmediateMode(boolean enable)
    Enables or disables immediate mode.
    setNonBlock(boolean nonBlock)
    Enables or disables non-blocking mode.
    setPromisc(boolean promiscuousMode)
    Enables or disables promiscuous mode.
    setRfmon(boolean rfMonitor)
    Enables or disables monitor mode (wireless).
    setSnaplen(int snaplen)
    Sets the snapshot length.
    setTimeout(int timeoutInMillis)
    Sets the read timeout in milliseconds.
    setTstampPrecision(com.slytechs.sdk.jnetpcap.constant.PcapTStampPrecision precision)
    Sets the timestamp precision.
    setTstampType(com.slytechs.sdk.jnetpcap.constant.PcapTstampType type)
    Sets the timestamp type.
    Sets the uncaught exception handler.
    setUncaughtExceptionHandler(Consumer<? super Throwable> exceptionHandler)
    Sets the uncaught exception handler using a Consumer.
    int
    Returns the snapshot length.
    com.slytechs.sdk.jnetpcap.PcapStat
    Returns capture statistics.

    Methods inherited from class Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • pcapApi

      protected final com.slytechs.sdk.jnetpcap.Pcap pcapApi
  • Constructor Details

    • BaseNetPcap

      protected BaseNetPcap(com.slytechs.sdk.jnetpcap.Pcap pcapApi)
  • Method Details

    • activate

      public void activate() throws com.slytechs.sdk.jnetpcap.PcapActivatedException, com.slytechs.sdk.jnetpcap.PcapException
      Activates a pcap handle created with create().
      Throws:
      com.slytechs.sdk.jnetpcap.PcapActivatedException - if handle is already activated
      com.slytechs.sdk.jnetpcap.PcapException - if activation fails
      See Also:
      • Pcap.activate()
    • breakloop

      public void breakloop()
      Forces a dispatch() or loop() call to return.
      See Also:
      • Pcap.breakloop()
    • canSetRfmon

      public boolean canSetRfmon() throws com.slytechs.sdk.jnetpcap.PcapException
      Checks whether monitor mode can be set on this capture handle.
      Returns:
      true if monitor mode can be set
      Throws:
      com.slytechs.sdk.jnetpcap.PcapException - if operation fails
      See Also:
      • Pcap.canSetRfmon()
    • close

      public void close()
      Closes the capture handle and releases resources.
      Specified by:
      close in interface AutoCloseable
      See Also:
      • Pcap.close()
    • compile

      public com.slytechs.sdk.jnetpcap.BpFilter compile(String str, boolean optimize) throws com.slytechs.sdk.jnetpcap.PcapException
      Compiles a filter expression into a BPF program.
      Parameters:
      str - the filter expression
      optimize - true to optimize the compiled code
      Returns:
      the compiled BPF program
      Throws:
      com.slytechs.sdk.jnetpcap.PcapException - if compilation fails
      See Also:
      • Pcap.compile(String, boolean)
    • compile

      public com.slytechs.sdk.jnetpcap.BpFilter compile(String str, boolean optimize, int netmask) throws com.slytechs.sdk.jnetpcap.PcapException
      Compiles a filter expression with netmask.
      Parameters:
      str - the filter expression
      optimize - true to optimize the compiled code
      netmask - the network mask
      Returns:
      the compiled BPF program
      Throws:
      com.slytechs.sdk.jnetpcap.PcapException - if compilation fails
      See Also:
      • Pcap.compile(String, boolean, int)
    • datalink

      public com.slytechs.sdk.jnetpcap.constant.PcapDlt datalink() throws com.slytechs.sdk.jnetpcap.PcapException
      Returns the link-layer header type.
      Returns:
      the data link type
      Throws:
      com.slytechs.sdk.jnetpcap.PcapException - if operation fails
      See Also:
      • Pcap.datalink()
    • dataLinkExt

      public com.slytechs.sdk.jnetpcap.constant.PcapDlt dataLinkExt() throws com.slytechs.sdk.jnetpcap.PcapException
      Returns the link-layer header type with extended information.
      Returns:
      the data link type
      Throws:
      com.slytechs.sdk.jnetpcap.PcapException - if operation fails
      See Also:
      • Pcap.dataLinkExt()
    • dispatch

      public int dispatch(int count, com.slytechs.sdk.jnetpcap.PcapHandler.NativeCallback handler, MemorySegment user)
      Processes packets using a native callback.
      Parameters:
      count - maximum packets to process
      handler - the native callback handler
      user - user data passed to callback
      Returns:
      number of packets processed
      See Also:
      • Pcap.dispatch(int, NativeCallback, MemorySegment)
    • dispatch

      public <U> int dispatch(int count, com.slytechs.sdk.jnetpcap.PcapHandler.OfArray<U> handler, U user) throws com.slytechs.sdk.jnetpcap.PcapException
      Processes packets using an array-based handler.
      Type Parameters:
      U - the user data type
      Parameters:
      count - maximum packets to process
      handler - the array handler
      user - user data passed to handler
      Returns:
      number of packets processed
      Throws:
      com.slytechs.sdk.jnetpcap.PcapException - if operation fails
      See Also:
      • Pcap.dispatch(int, OfArray, Object)
    • dispatch

      public <U> int dispatch(int count, com.slytechs.sdk.jnetpcap.PcapHandler.OfMemorySegment<U> handler, U user) throws com.slytechs.sdk.jnetpcap.PcapException
      Processes packets using a memory segment handler.
      Type Parameters:
      U - the user data type
      Parameters:
      count - maximum packets to process
      handler - the memory segment handler
      user - user data passed to handler
      Returns:
      number of packets processed
      Throws:
      com.slytechs.sdk.jnetpcap.PcapException - if operation fails
      See Also:
      • Pcap.dispatch(int, OfMemorySegment, Object)
    • dispatch

      public <U> int dispatch(int count, com.slytechs.sdk.jnetpcap.PcapDumper pcapDumper) throws com.slytechs.sdk.jnetpcap.PcapException
      Processes packets and writes them to a dump file.
      Type Parameters:
      U - the user data type
      Parameters:
      count - maximum packets to process
      pcapDumper - the dump file handle
      Returns:
      number of packets processed
      Throws:
      com.slytechs.sdk.jnetpcap.PcapException - if operation fails
      See Also:
      • Pcap.dispatch(int, PcapDumper)
    • dumpOpen

      public com.slytechs.sdk.jnetpcap.PcapDumper dumpOpen(String fname) throws com.slytechs.sdk.jnetpcap.PcapException
      Opens a dump file for writing packets.
      Parameters:
      fname - the output filename
      Returns:
      a PcapDumper for writing packets
      Throws:
      com.slytechs.sdk.jnetpcap.PcapException - if file cannot be opened
      See Also:
      • Pcap.dumpOpen(String)
    • geterr

      public String geterr()
      Returns the error message for the last pcap error.
      Returns:
      the error message string
      See Also:
      • Pcap.geterr()
    • getName

      public final String getName()
      Returns the device name associated with this handle.
      Returns:
      the device name
      See Also:
      • Pcap.getName()
    • getNonBlock

      public boolean getNonBlock() throws com.slytechs.sdk.jnetpcap.PcapException
      Returns the current non-blocking mode state.
      Returns:
      true if in non-blocking mode
      Throws:
      com.slytechs.sdk.jnetpcap.PcapException - if operation fails
      See Also:
      • Pcap.getNonBlock()
    • getPcapHeaderABI

      public com.slytechs.sdk.jnetpcap.internal.PcapHeaderABI getPcapHeaderABI()
      Returns the pcap header ABI information.
      Returns:
      the header ABI
      See Also:
      • Pcap.getPcapHeaderABI()
    • getTstampPrecision

      public com.slytechs.sdk.jnetpcap.constant.PcapTStampPrecision getTstampPrecision() throws com.slytechs.sdk.jnetpcap.PcapException
      Returns the timestamp precision for this handle.
      Returns:
      the timestamp precision
      Throws:
      com.slytechs.sdk.jnetpcap.PcapException - if operation fails
      See Also:
      • Pcap.getTstampPrecision()
    • inject

      public final int inject(byte[] array) throws com.slytechs.sdk.jnetpcap.PcapException
      Transmits a packet, returning the number of bytes sent.
      Parameters:
      array - the packet data
      Returns:
      number of bytes sent
      Throws:
      com.slytechs.sdk.jnetpcap.PcapException - if transmission fails
      See Also:
      • Pcap.inject(byte[])
    • inject

      public final int inject(byte[] array, int offset, int length) throws com.slytechs.sdk.jnetpcap.PcapException
      Transmits a portion of a packet array.
      Parameters:
      array - the packet data
      offset - starting offset
      length - number of bytes to send
      Returns:
      number of bytes sent
      Throws:
      com.slytechs.sdk.jnetpcap.PcapException - if transmission fails
      See Also:
      • Pcap.inject(byte[], int, int)
    • inject

      public final int inject(ByteBuffer buf) throws com.slytechs.sdk.jnetpcap.PcapException
      Transmits a packet from a ByteBuffer.
      Parameters:
      buf - the packet data
      Returns:
      number of bytes sent
      Throws:
      com.slytechs.sdk.jnetpcap.PcapException - if transmission fails
      See Also:
      • Pcap.inject(ByteBuffer)
    • inject

      public int inject(MemorySegment packet, int length) throws com.slytechs.sdk.jnetpcap.PcapException
      Transmits a packet from native memory.
      Parameters:
      packet - the packet data
      length - number of bytes to send
      Returns:
      number of bytes sent
      Throws:
      com.slytechs.sdk.jnetpcap.PcapException - if transmission fails
      See Also:
      • Pcap.inject(MemorySegment, int)
    • isSwapped

      public boolean isSwapped() throws com.slytechs.sdk.jnetpcap.PcapException
      Checks if the capture file has different byte order.
      Returns:
      true if byte-swapped
      Throws:
      com.slytechs.sdk.jnetpcap.PcapException - if operation fails
      See Also:
      • Pcap.isSwapped()
    • listDataLinks

      public List<com.slytechs.sdk.jnetpcap.constant.PcapDlt> listDataLinks() throws com.slytechs.sdk.jnetpcap.PcapException
      Returns the list of supported data link types.
      Returns:
      list of supported link types
      Throws:
      com.slytechs.sdk.jnetpcap.PcapException - if operation fails
      See Also:
      • Pcap.listDataLinks()
    • listTstampTypes

      public List<com.slytechs.sdk.jnetpcap.constant.PcapTstampType> listTstampTypes() throws com.slytechs.sdk.jnetpcap.PcapException
      Returns the list of supported timestamp types.
      Returns:
      list of supported timestamp types
      Throws:
      com.slytechs.sdk.jnetpcap.PcapException - if operation fails
      See Also:
      • Pcap.listTstampTypes()
    • loop

      public <U> int loop(int count, com.slytechs.sdk.jnetpcap.PcapHandler.NativeCallback handler, MemorySegment user)
      Processes packets in a loop using a native callback.
      Type Parameters:
      U - the user data type
      Parameters:
      count - packets to process (-1 for infinite)
      handler - the native callback
      user - user data
      Returns:
      number of packets processed
      See Also:
      • Pcap.loop(int, NativeCallback, MemorySegment)
    • loop

      public <U> int loop(int count, com.slytechs.sdk.jnetpcap.PcapHandler.OfArray<U> handler, U user) throws com.slytechs.sdk.jnetpcap.PcapException
      Processes packets in a loop using an array handler.
      Type Parameters:
      U - the user data type
      Parameters:
      count - packets to process (-1 for infinite)
      handler - the array handler
      user - user data
      Returns:
      number of packets processed
      Throws:
      com.slytechs.sdk.jnetpcap.PcapException - if operation fails
      See Also:
      • Pcap.loop(int, OfArray, Object)
    • loop

      public <U> int loop(int count, com.slytechs.sdk.jnetpcap.PcapHandler.OfMemorySegment<U> handler, U user)
      Processes packets in a loop using a memory segment handler.
      Type Parameters:
      U - the user data type
      Parameters:
      count - packets to process (-1 for infinite)
      handler - the memory segment handler
      user - user data
      Returns:
      number of packets processed
      See Also:
      • Pcap.loop(int, OfMemorySegment, Object)
    • loop

      public <U> int loop(int count, com.slytechs.sdk.jnetpcap.PcapDumper pcapDumper) throws com.slytechs.sdk.jnetpcap.PcapException
      Processes packets in a loop and writes to a dump file.
      Type Parameters:
      U - the user data type
      Parameters:
      count - packets to process (-1 for infinite)
      pcapDumper - the dump file handle
      Returns:
      number of packets processed
      Throws:
      com.slytechs.sdk.jnetpcap.PcapException - if operation fails
      See Also:
      • Pcap.loop(int, PcapDumper)
    • majorVersion

      public int majorVersion() throws com.slytechs.sdk.jnetpcap.PcapException
      Returns the major version of the pcap file format.
      Returns:
      the major version number
      Throws:
      com.slytechs.sdk.jnetpcap.PcapException - if operation fails
      See Also:
      • Pcap.majorVersion()
    • minorVersion

      public int minorVersion() throws com.slytechs.sdk.jnetpcap.PcapException
      Returns the minor version of the pcap file format.
      Returns:
      the minor version number
      Throws:
      com.slytechs.sdk.jnetpcap.PcapException - if operation fails
      See Also:
      • Pcap.minorVersion()
    • next

      public abstract com.slytechs.sdk.protocol.core.Packet next() throws com.slytechs.sdk.jnetpcap.PcapException
      Retrieves the next packet.
      Returns:
      the next packet, or null if none available
      Throws:
      com.slytechs.sdk.jnetpcap.PcapException - if operation fails
      See Also:
      • Pcap.next()
    • nextEx

      public abstract com.slytechs.sdk.protocol.core.Packet nextEx() throws com.slytechs.sdk.jnetpcap.PcapException, TimeoutException
      Retrieves the next packet with extended status.
      Returns:
      the next packet
      Throws:
      com.slytechs.sdk.jnetpcap.PcapException - if operation fails or EOF reached
      TimeoutException - if read timeout expires
      See Also:
      • Pcap.nextEx()
    • order

      public final ByteOrder order() throws com.slytechs.sdk.jnetpcap.PcapException
      Returns the byte order of the capture file.
      Returns:
      the byte order
      Throws:
      com.slytechs.sdk.jnetpcap.PcapException - if operation fails
      See Also:
      • Pcap.order()
    • perror

      public BaseNetPcap perror(String prefix)
      Prints error message to stderr.
      Parameters:
      prefix - prefix for the error message
      Returns:
      this instance for method chaining
      See Also:
      • Pcap.perror(String)
    • sendPacket

      public final void sendPacket(byte[] buf) throws com.slytechs.sdk.jnetpcap.PcapException
      Sends a raw packet on the network.
      Parameters:
      buf - the packet data
      Throws:
      com.slytechs.sdk.jnetpcap.PcapException - if transmission fails
      See Also:
      • Pcap.sendPacket(byte[])
    • sendPacket

      public final void sendPacket(byte[] buf, int offset, int length) throws com.slytechs.sdk.jnetpcap.PcapException
      Sends a portion of a raw packet.
      Parameters:
      buf - the packet data
      offset - starting offset
      length - number of bytes to send
      Throws:
      com.slytechs.sdk.jnetpcap.PcapException - if transmission fails
      See Also:
      • Pcap.sendPacket(byte[], int, int)
    • sendPacket

      public final void sendPacket(ByteBuffer buf) throws com.slytechs.sdk.jnetpcap.PcapException
      Sends a raw packet from a ByteBuffer.
      Parameters:
      buf - the packet data
      Throws:
      com.slytechs.sdk.jnetpcap.PcapException - if transmission fails
      See Also:
      • Pcap.sendPacket(ByteBuffer)
    • sendPacket

      public void sendPacket(MemorySegment packet, int length) throws com.slytechs.sdk.jnetpcap.PcapException
      Sends a raw packet from native memory.
      Parameters:
      packet - the packet data
      length - number of bytes to send
      Throws:
      com.slytechs.sdk.jnetpcap.PcapException - if transmission fails
      See Also:
      • Pcap.sendPacket(MemorySegment, int)
    • setBufferSize

      public BaseNetPcap setBufferSize(int bufferSize) throws com.slytechs.sdk.jnetpcap.PcapException
      Sets the kernel buffer size for the capture.
      Parameters:
      bufferSize - the buffer size in bytes
      Returns:
      this instance for method chaining
      Throws:
      com.slytechs.sdk.jnetpcap.PcapException - if operation fails
      See Also:
      • Pcap.setBufferSize(int)
    • setDatalink

      public BaseNetPcap setDatalink(int dlt) throws com.slytechs.sdk.jnetpcap.PcapException
      Sets the data link type for the capture.
      Parameters:
      dlt - the data link type value
      Returns:
      this instance for method chaining
      Throws:
      com.slytechs.sdk.jnetpcap.PcapException - if operation fails
      See Also:
      • Pcap.setDatalink(int)
    • setDatalink

      public BaseNetPcap setDatalink(Optional<com.slytechs.sdk.jnetpcap.constant.PcapDlt> dlt) throws com.slytechs.sdk.jnetpcap.PcapException
      Sets the data link type using an Optional.
      Parameters:
      dlt - the optional data link type
      Returns:
      this instance for method chaining
      Throws:
      com.slytechs.sdk.jnetpcap.PcapException - if operation fails
      See Also:
      • Pcap.setDatalink(Optional)
    • setDatalink

      public BaseNetPcap setDatalink(com.slytechs.sdk.jnetpcap.constant.PcapDlt dlt) throws com.slytechs.sdk.jnetpcap.PcapException
      Sets the data link type.
      Parameters:
      dlt - the data link type
      Returns:
      this instance for method chaining
      Throws:
      com.slytechs.sdk.jnetpcap.PcapException - if operation fails
      See Also:
      • Pcap.setDatalink(PcapDlt)
    • setDirection

      public BaseNetPcap setDirection(int dir) throws com.slytechs.sdk.jnetpcap.PcapException
      Sets the capture direction.
      Parameters:
      dir - the direction value
      Returns:
      this instance for method chaining
      Throws:
      com.slytechs.sdk.jnetpcap.PcapException - if operation fails
      See Also:
      • Pcap.setDirection(int)
    • setDirection

      public BaseNetPcap setDirection(Optional<com.slytechs.sdk.jnetpcap.constant.PcapDirection> dir) throws com.slytechs.sdk.jnetpcap.PcapException
      Sets the capture direction using an Optional.
      Parameters:
      dir - the optional direction
      Returns:
      this instance for method chaining
      Throws:
      com.slytechs.sdk.jnetpcap.PcapException - if operation fails
      See Also:
      • Pcap.setDirection(Optional)
    • setDirection

      public BaseNetPcap setDirection(com.slytechs.sdk.jnetpcap.constant.PcapDirection dir) throws com.slytechs.sdk.jnetpcap.PcapException
      Sets the capture direction.
      Parameters:
      dir - the direction
      Returns:
      this instance for method chaining
      Throws:
      com.slytechs.sdk.jnetpcap.PcapException - if operation fails
      See Also:
      • Pcap.setDirection(PcapDirection)
    • setFilter

      public BaseNetPcap setFilter(com.slytechs.sdk.jnetpcap.BpFilter bpfProgram) throws com.slytechs.sdk.jnetpcap.PcapException
      Sets the BPF filter program.
      Parameters:
      bpfProgram - the compiled filter program
      Returns:
      this instance for method chaining
      Throws:
      com.slytechs.sdk.jnetpcap.PcapException - if operation fails
      See Also:
      • Pcap.setFilter(BpFilter)
    • setFilter

      public BaseNetPcap setFilter(Optional<com.slytechs.sdk.jnetpcap.BpFilter> bpfProgram) throws com.slytechs.sdk.jnetpcap.PcapException
      Sets the BPF filter using an Optional.
      Parameters:
      bpfProgram - the optional filter program
      Returns:
      this instance for method chaining
      Throws:
      com.slytechs.sdk.jnetpcap.PcapException - if operation fails
      See Also:
      • Pcap.setFilter(Optional)
    • setImmediateMode

      public BaseNetPcap setImmediateMode(boolean enable) throws com.slytechs.sdk.jnetpcap.PcapException
      Enables or disables immediate mode.
      Parameters:
      enable - true to enable immediate mode
      Returns:
      this instance for method chaining
      Throws:
      com.slytechs.sdk.jnetpcap.PcapException - if operation fails
      See Also:
      • Pcap.setImmediateMode(boolean)
    • setNonBlock

      public BaseNetPcap setNonBlock(boolean nonBlock) throws com.slytechs.sdk.jnetpcap.PcapException
      Enables or disables non-blocking mode.
      Parameters:
      nonBlock - true for non-blocking mode
      Returns:
      this instance for method chaining
      Throws:
      com.slytechs.sdk.jnetpcap.PcapException - if operation fails
      See Also:
      • Pcap.setNonBlock(boolean)
    • setPromisc

      public BaseNetPcap setPromisc(boolean promiscuousMode) throws com.slytechs.sdk.jnetpcap.PcapException
      Enables or disables promiscuous mode.
      Parameters:
      promiscuousMode - true for promiscuous mode
      Returns:
      this instance for method chaining
      Throws:
      com.slytechs.sdk.jnetpcap.PcapException - if operation fails
      See Also:
      • Pcap.setPromisc(boolean)
    • setRfmon

      public BaseNetPcap setRfmon(boolean rfMonitor) throws com.slytechs.sdk.jnetpcap.PcapException
      Enables or disables monitor mode (wireless).
      Parameters:
      rfMonitor - true to enable monitor mode
      Returns:
      this instance for method chaining
      Throws:
      com.slytechs.sdk.jnetpcap.PcapException - if operation fails
      See Also:
      • Pcap.setRfmon(boolean)
    • setSnaplen

      public BaseNetPcap setSnaplen(int snaplen) throws com.slytechs.sdk.jnetpcap.PcapException
      Sets the snapshot length.
      Parameters:
      snaplen - maximum bytes to capture per packet
      Returns:
      this instance for method chaining
      Throws:
      com.slytechs.sdk.jnetpcap.PcapException - if operation fails
      See Also:
      • Pcap.setSnaplen(int)
    • setTimeout

      public BaseNetPcap setTimeout(int timeoutInMillis) throws com.slytechs.sdk.jnetpcap.PcapException
      Sets the read timeout in milliseconds.
      Parameters:
      timeoutInMillis - timeout in milliseconds
      Returns:
      this instance for method chaining
      Throws:
      com.slytechs.sdk.jnetpcap.PcapException - if operation fails
      See Also:
      • Pcap.setTimeout(int)
    • setTstampPrecision

      public BaseNetPcap setTstampPrecision(com.slytechs.sdk.jnetpcap.constant.PcapTStampPrecision precision) throws com.slytechs.sdk.jnetpcap.PcapException
      Sets the timestamp precision.
      Parameters:
      precision - the timestamp precision
      Returns:
      this instance for method chaining
      Throws:
      com.slytechs.sdk.jnetpcap.PcapException - if operation fails
      See Also:
      • Pcap.setTstampPrecision(PcapTStampPrecision)
    • setTstampType

      public BaseNetPcap setTstampType(com.slytechs.sdk.jnetpcap.constant.PcapTstampType type) throws com.slytechs.sdk.jnetpcap.PcapException
      Sets the timestamp type.
      Parameters:
      type - the timestamp type
      Returns:
      this instance for method chaining
      Throws:
      com.slytechs.sdk.jnetpcap.PcapException - if operation fails
      See Also:
      • Pcap.setTstampType(PcapTstampType)
    • setUncaughtExceptionHandler

      public BaseNetPcap setUncaughtExceptionHandler(Consumer<? super Throwable> exceptionHandler)
      Sets the uncaught exception handler using a Consumer.
      Parameters:
      exceptionHandler - the exception handler
      Returns:
      this instance for method chaining
      See Also:
      • Pcap.setUncaughtExceptionHandler(Consumer)
    • setUncaughtExceptionHandler

      public BaseNetPcap setUncaughtExceptionHandler(Thread.UncaughtExceptionHandler exceptionHandler)
      Sets the uncaught exception handler.
      Parameters:
      exceptionHandler - the exception handler
      Returns:
      this instance for method chaining
      See Also:
      • Pcap.setUncaughtExceptionHandler(UncaughtExceptionHandler)
    • snapshot

      public int snapshot() throws com.slytechs.sdk.jnetpcap.PcapException
      Returns the snapshot length.
      Returns:
      the snapshot length
      Throws:
      com.slytechs.sdk.jnetpcap.PcapException - if operation fails
      See Also:
      • Pcap.snapshot()
    • stats

      public com.slytechs.sdk.jnetpcap.PcapStat stats() throws com.slytechs.sdk.jnetpcap.PcapException
      Returns capture statistics.
      Returns:
      the capture statistics
      Throws:
      com.slytechs.sdk.jnetpcap.PcapException - if operation fails
      See Also:
      • Pcap.stats()