Class PcapHandle.Builder
java.lang.Object
org.pcap4j.core.PcapHandle.Builder
- Enclosing class:
PcapHandle
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 Summary
FieldsModifier and TypeFieldDescriptionprivate intprivate final Stringprivate PcapHandle.PcapDirectionprivate booleanprivate booleanprivate booleanprivate booleanprivate booleanprivate booleanprivate booleanprivate intprivate intprivate PcapHandle.TimestampPrecision -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionbufferSize(int bufferSize) build()direction(PcapHandle.PcapDirection direction) Set direction flag, which controls whether we accept only incoming packets, only outgoing packets, or both.immediateMode(boolean immediateMode) Set immediate mode, which allows programs to process packets as soon as they arrive.promiscuousMode(PcapNetworkInterface.PromiscuousMode promiscuousMode) rfmon(boolean rfmon) snaplen(int snaplen) timeoutMillis(int timeoutMillis) timestampPrecision(PcapHandle.TimestampPrecision timestampPrecision)
-
Field Details
-
deviceName
-
snaplen
private int snaplen -
isSnaplenSet
private boolean isSnaplenSet -
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
-
direction
-
immediateMode
private boolean immediateMode -
isImmediateModeSet
private boolean isImmediateModeSet
-
-
Constructor Details
-
Builder
- Parameters:
deviceName- A valuePcapNetworkInterface.getName()returns.
-
-
Method Details
-
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 atbuild().- Returns:
- this Builder object for method chaining.
-
promiscuousMode
- Parameters:
promiscuousMode- Promiscuous mode. If this method isn't called, the platform's default mode will be used atbuild().- Returns:
- this Builder object for method chaining.
-
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 atbuild(). If this method isn't called, the platform's default mode will be applied atbuild()(if supported).- Returns:
- this Builder object for method chaining.
-
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 atbuild().- Returns:
- this Builder object for method chaining.
-
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 atbuild().- Returns:
- this Builder object for method chaining.
-
timestampPrecision
- Parameters:
timestampPrecision- The timestamp precision. If this method isn't called, microsecond precision will be applied atbuild().- Returns:
- this Builder object for method chaining.
-
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
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 atbuild(). If this method isn't called, immediate mode will not be setbuild().- Returns:
- this Builder object for method chaining.
-
build
- Returns:
- a new PcapHandle object representing a live capture handle.
- Throws:
PcapNativeException- if an error occurs in the pcap native library.
-