Class PcapHandle.Builder

java.lang.Object
org.pcap4j.core.PcapHandle.Builder
Enclosing class:
PcapHandle

public static final class PcapHandle.Builder extends Object
This class is used to open (i.e. create and activate) a live capture handle as PcapNetworkInterface#openLive does but with more parameters.
Since:
pcap4j 1.2.0
  • Field Details

    • deviceName

      private final String deviceName
    • snaplen

      private int snaplen
    • isSnaplenSet

      private boolean isSnaplenSet
    • promiscuousMode

      private PcapNetworkInterface.PromiscuousMode promiscuousMode
    • rfmon

      private boolean rfmon
    • isRfmonSet

      private boolean isRfmonSet
    • timeoutMillis

      private int timeoutMillis
    • isTimeoutMillisSet

      private boolean isTimeoutMillisSet
    • bufferSize

      private int bufferSize
    • isBufferSizeSet

      private boolean isBufferSizeSet
    • timestampPrecision

      private PcapHandle.TimestampPrecision timestampPrecision
    • direction

      private PcapHandle.PcapDirection direction
    • immediateMode

      private boolean immediateMode
    • isImmediateModeSet

      private boolean isImmediateModeSet
  • Constructor Details

  • Method Details

    • snaplen

      public PcapHandle.Builder snaplen(int snaplen)
      Parameters:
      snaplen - Snapshot length, which is the number of bytes captured for each packet. If this method isn't called, the platform's default snaplen will be applied at build().
      Returns:
      this Builder object for method chaining.
    • promiscuousMode

      public PcapHandle.Builder promiscuousMode(PcapNetworkInterface.PromiscuousMode promiscuousMode)
      Parameters:
      promiscuousMode - Promiscuous mode. If this method isn't called, the platform's default mode will be used at build().
      Returns:
      this Builder object for method chaining.
    • rfmon

      public PcapHandle.Builder rfmon(boolean rfmon)
      Parameters:
      rfmon - Whether monitor mode should be set on a PcapHandle when it is built. If true, monitor mode will be set, otherwise it will not be set. Some platforms don't support setting monitor mode. Calling this method on such platforms may cause PcapNativeException at build(). If this method isn't called, the platform's default mode will be applied at build() (if supported).
      Returns:
      this Builder object for method chaining.
    • timeoutMillis

      public PcapHandle.Builder timeoutMillis(int timeoutMillis)
      Parameters:
      timeoutMillis - Read timeout. Most OSs buffer packets. The OSs pass the packets to Pcap4j after the buffer gets full or the read timeout expires. Must be non-negative. May be ignored by some OSs. 0 means disable buffering on Solaris. 0 means infinite on the other OSs. 1 through 9 means infinite on Solaris. If this method isn't called, the platform's default timeout will be applied at build().
      Returns:
      this Builder object for method chaining.
    • bufferSize

      public PcapHandle.Builder bufferSize(int bufferSize)
      Parameters:
      bufferSize - The buffer size, which is in units of bytes. If this method isn't called, the platform's default buffer size will be applied at build().
      Returns:
      this Builder object for method chaining.
    • timestampPrecision

      public PcapHandle.Builder timestampPrecision(PcapHandle.TimestampPrecision timestampPrecision)
      Parameters:
      timestampPrecision - The timestamp precision. If this method isn't called, microsecond precision will be applied at build().
      Returns:
      this Builder object for method chaining.
    • direction

      public PcapHandle.Builder direction(PcapHandle.PcapDirection direction)
      Set direction flag, which controls whether we accept only incoming packets, only outgoing packets, or both. Note that, depending on the platform, some or all direction arguments might not be supported.
      Parameters:
      direction - The direction of packets to capture. If this method isn't called, no packets will be filtered by their direction.
      Returns:
      this Builder object for method chaining.
    • immediateMode

      public PcapHandle.Builder immediateMode(boolean immediateMode)
      Set immediate mode, which allows programs to process packets as soon as they arrive.
      Parameters:
      immediateMode - Whether immediate mode should be set on a PcapHandle when it is built. If true, immediate mode will be set, otherwise it will not be set. Some platforms and library versions don't support setting immediate mode. Calling this method in such cases may cause PcapNativeException at build(). If this method isn't called, immediate mode will not be set build().
      Returns:
      this Builder object for method chaining.
    • build

      public PcapHandle build() throws PcapNativeException
      Returns:
      a new PcapHandle object representing a live capture handle.
      Throws:
      PcapNativeException - if an error occurs in the pcap native library.