- All Implemented Interfaces:
CaptureStatistics,AutoCloseable
IPF Modes
The pro pcap API provides support for IP fragment reassembly and tracking. When enabled, the user packet handler will receive fully reassembled IP datagrams instead of individual fragments along with any other type of packets selected by the packet filter applied.
To enable IPF mode, use the fluent method enableIpf(boolean) before the
pcap handle is activated. Once enabled, numerous defaults are used and can be
changed by the use of the pcap handle. By default, IPF tracking and
reassembly are both enabled. Further more, IPF reassembly can be configured to attach IPF
reassembled buffer to the last IP fragment and/or inserted as a new IP
data-gram into the dispatcher's packet stream. This way the user packet
handler will receive fully reassembled IP datagrams as packets. The default
is to not forward individual IP fragments, but deliver the fully reassembled
IP data-gram as a new packet, containing all of the IP fragment data
combined.
- Author:
- Sly Technologies Inc, repos@slytechs.com
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic final classContext structure for the PcapPro class and its numerous processors.Nested classes/interfaces inherited from class org.jnetpcap.Pcap
org.jnetpcap.Pcap.LibraryPolicy, org.jnetpcap.Pcap.Linux, org.jnetpcap.Pcap.Unix -
Field Summary
Fields inherited from class org.jnetpcap.Pcap
VERSION -
Method Summary
Modifier and TypeMethodDescriptionvoidactivate()Activate the pcap-pro handle and all its resources.voidclose()Close.static NetPcapCreate a live capture handle.static NetPcapcreate(org.jnetpcap.PcapIf device) Create a live capture handle.<U> intdispatch(int count, PcapProHandler.OfPacket<U> handler, U user) Process packets from a live capture or savefile.intdispatch(int count, PcapProHandler.OfPacketConsumer packetConsumer) Dispatch which uses a simple packet consumer.intdispatch(PcapProHandler.OfPacketConsumer packetConsumer) Dispatch which uses a simple packet consumer.<T extends PcapProConfigurator.PostRxProcessor>
NetPcapenableIpf(boolean b) Install factory.<T extends PcapProConfigurator.PostRxProcessor>
NetPcapEnable ipf if.enablePacketFormatter(boolean b) Enable "pretty print" packet formatter.Gets the context.longGets the dropped caplen count.longGets the dropped packet count.longGets the dropped wirelen count.Gets the pcap type.longGets the received caplen count.longGets the received packet count.longGets the received wirelen count.Gets any uncaught exceptions.<T extends PcapProConfigurator.PostRxProcessor>
Tinstall(T postProcessor) Install.<T extends PcapProConfigurator.PostRxProcessor>
TinstallPost(PcapProConfigurator.PostRxProcessorFactory<T> postProcessorSupplier) Install factory.<T extends PcapProConfigurator.PreRxProcessor>
TinstallPre(PcapProConfigurator.PreRxProcessorFactory<T> preProcessorSupplier) Install factory.<U> intloop(int count, PcapProHandler.OfPacket<U> handler, U user) Process packets from a live capture or savefile.intloop(int count, PcapProHandler.OfPacketConsumer packetConsumer) Process packets from a live capture or savefile.intloop(PcapProHandler.OfPacketConsumer packetConsumer) Process packets from a live capture or savefile.org.jnetpcap.util.PcapPacketRefPREVIEWnext()Next.org.jnetpcap.util.PcapPacketRefPREVIEWnextEx()Next ex.com.slytechs.jnet.protocol.PacketRead the next packet from a pcap handle.com.slytechs.jnet.protocol.Packetread the next packet from a handle.com.slytechs.jnet.protocol.RegistrationOn close.static NetPcapopenDead(org.jnetpcap.constant.PcapDlt linktype, int snaplen) Open a fake pcap_t for compiling filters or opening a capture for output.static NetPcapopenDeadWithTstampPrecision(org.jnetpcap.constant.PcapDlt linktype, int snaplen, org.jnetpcap.constant.PcapTStampPrecision precision) Open a fake pcap_t for compiling filters or opening a capture for output.static NetPcapOpen a device for capturing.static NetPcapOpen a device for capturing.static NetPcapopenOffline(File file) Open a saved capture file for reading.static NetPcapopenOffline(String fname) Open a saved capture file for reading.setBufferSize(long size, com.slytechs.jnet.jnetruntime.util.MemoryUnit unit) Sets the buffer size for a not-yet- activated capture handle.setDescriptorType(com.slytechs.jnet.protocol.core.constants.PacketDescriptorType type) Sets the descriptor type.setFrameNumber(com.slytechs.jnet.protocol.Frame.FrameNumber frameNumberAssigner) Sets the frame number.setFrameStartingNumber(long startingNo) Sets the frame starting number.setPacketFormatter(com.slytechs.jnet.protocol.meta.PacketFormat formatter) Sets the packet formatter.setPortNumber(int portNo) Sets the port number.setTimestampUnit(com.slytechs.jnet.jnetruntime.time.TimestampUnit unit) Sets the timestamp unit which specifies the timestamp used by this pcap handle.final NetPcapsetUncaughtExceptionHandler(Thread.UncaughtExceptionHandler exceptionHandler) Sets the uncaught exception handler.final NetPcapsetUncaughtExceptionHandler(Consumer<? super Throwable> exceptionHandler) Sets the uncaught exception handler.<T extends PcapProConfigurator<T>>
NetPcapuninstall(PcapProConfigurator<T> processor) Uninstall a specific processor instance (either pre or post), if installed.<T extends PcapProConfigurator<?>>
NetPcapUninstall a specific processor (either pre or post) by its type.uninstAll(boolean preProcessors, boolean postProcessors) Uninstall selectively all pre or post packet processors.Uninstall all pre and post packet processors.Methods inherited from class org.jnetpcap.Pcap1_10
isSupportedMethods inherited from class org.jnetpcap.Pcap1_5
getTstampPrecision, setImmediateMode, setTstampPrecisionMethods inherited from class org.jnetpcap.Pcap1_2
listTstampTypes, setTstampTypeMethods inherited from class org.jnetpcap.Pcap1_0
canSetRfmon, dataLinkExt, init, offlineFilter, setBufferSize, setPromisc, setPromisc, setRfmon, setRfmon, setSnaplen, setTimeout, statusToStrMethods inherited from class org.jnetpcap.Pcap0_9
inject, setDirectionMethods inherited from class org.jnetpcap.Pcap0_8
breakloop, datalinkNameToVal, dataLinkValToDescription, dataLinkValToName, libVersion, listDataLinks, sendPacket, setDatalinkMethods inherited from class org.jnetpcap.Pcap0_7
findAllDevs, getNonBlock, setNonBlockMethods inherited from class org.jnetpcap.Pcap0_5
compileNoPcapMethods inherited from class org.jnetpcap.Pcap0_4
compile, datalink, datalinkGetAsInt, dispatch, dispatch, dispatch, dispatch, dumpOpen, file, fileno, geterr, isInitialized, isSwapped, lookupDev, lookupNet, loop, loop, loop, loop, majorVersion, minorVersion, perror, setFilter, snapshot, stats, strerrorMethods inherited from class org.jnetpcap.Pcap
checkPcapVersion, compile, datalinkValToDescription, datalinkValToName, findAllDevsEx, getName, getPcapHeaderABI, init, inject, inject, inject, loadNativePcapLibrary, lookupNet, order, sendPacket, sendPacket, sendPacket, setDatalink, setDatalink, setDirection, setDirection, setFilter, statusToStr, toString
-
Method Details
-
create
Create a live capture handle.createis used to create a packet capture handle to look at packets on the network. source is a string that specifies the network device to open; on Linux systems with 2.2 or later kernels, a source argument of "any" or NULL can be used to capture packets from all interfaces. The returned handle must be activated with pcap_activate() before pack' ets can be captured with it; options for the capture, such as promiscu' ous mode, can be set on the handle before activating it.- Parameters:
device- pcap network interface that specifies the network device to open.- Returns:
- a new pcap object that needs to be activated using
activate()call - Throws:
org.jnetpcap.PcapException- the pcap exception- Since:
- libpcap 1.0
-
create
Create a live capture handle.createis used to create a packet capture handle to look at packets on the network. source is a string that specifies the network device to open; on Linux systems with 2.2 or later kernels, a source argument of "any" or NULL can be used to capture packets from all interfaces. The returned handle must be activated with pcap_activate() before pack' ets can be captured with it; options for the capture, such as promiscu' ous mode, can be set on the handle before activating it.- Parameters:
device- a string that specifies the network device to open; on Linux systems with 2.2 or later kernels, a source argument of "any" or NULL can be used to capture packets from all interfaces.- Returns:
- a new pcap object that needs to be activated using
activate()call - Throws:
org.jnetpcap.PcapException- the pcap exception- Since:
- libpcap 1.0
-
openDead
public static NetPcap openDead(org.jnetpcap.constant.PcapDlt linktype, int snaplen) throws org.jnetpcap.PcapException Open a fake pcap_t for compiling filters or opening a capture for output.openDead(org.jnetpcap.constant.PcapDlt, int)and pcap_open_dead_with_tstamp_precision() are used for creating a pcap_t structure to use when calling the other functions in libpcap. It is typically used when just using libpcap for compiling BPF full; it can also be used if using pcap_dump_open(3PCAP), pcap_dump(3PCAP), and pcap_dump_close(3PCAP) to write a savefile if there is no pcap_t that supplies the packets to be written.When pcap_open_dead_with_tstamp_precision(), is used to create a pcap_t for use with pcap_dump_open(), precision specifies the time stamp precision for packets; PCAP_TSTAMP_PRECISION_MICRO should be specified if the packets to be written have time stamps in seconds and microseconds, and PCAP_TSTAMP_PRECISION_NANO should be specified if the packets to be written have time stamps in seconds and nanoseconds. Its value does not affect pcap_compile(3PCAP).
- Parameters:
linktype- specifies the link-layer type for the pcap handlesnaplen- specifies the snapshot length for the pcap handle- Returns:
- A dead pcap handle
- Throws:
org.jnetpcap.PcapException- any errors- Since:
- libpcap 0.6
-
openDeadWithTstampPrecision
public static NetPcap openDeadWithTstampPrecision(org.jnetpcap.constant.PcapDlt linktype, int snaplen, org.jnetpcap.constant.PcapTStampPrecision precision) throws org.jnetpcap.PcapException Open a fake pcap_t for compiling filters or opening a capture for output.openDead(PcapDlt, int)andopenDeadWithTstampPrecision(PcapDlt, int, PcapTStampPrecision)are used for creating a pcap_t structure to use when calling the other functions in libpcap. It is typically used when just using libpcap for compiling BPF full; it can also be used if using#dumpOpen(String),PcapDumper.dump(MemorySegment, MemorySegment), andPcapDumper.close()to write a savefile if there is no pcap_t that supplies the packets to be written.When
openDeadWithTstampPrecision(PcapDlt, int, PcapTStampPrecision), is used to create aPcaphandle for use withPcap0_4.dumpOpen(String), precision specifies the time stamp precision for packets; PCAP_TSTAMP_PRECISION_MICRO should be specified if the packets to be written have time stamps in seconds and microseconds, and PCAP_TSTAMP_PRECISION_NANO should be specified if the packets to be written have time stamps in seconds and nanoseconds. Its value does not affect pcap_compile(3PCAP).- Parameters:
linktype- specifies the link-layer type for the pcap handlesnaplen- specifies the snapshot length for the pcap handleprecision- the requested timestamp precision- Returns:
- A dead pcap handle
- Throws:
org.jnetpcap.PcapException- any errors- Since:
- libpcap 1.5.1
-
openLive
public static NetPcap openLive(org.jnetpcap.PcapIf device, int snaplen, boolean promisc, long timeout, TimeUnit unit) throws org.jnetpcap.PcapException Open a device for capturing.openLiveis used to obtain a packet capture handle to look at packets on the network. device is a string that specifies the network device to open; on Linux systems with 2.2 or later kernels, a device argument of "any" or NULL can be used to capture packets from all interfaces.- Parameters:
device- the device namesnaplen- specifies the snapshot length to be set on the handlepromisc- specifies whether the interface is to be put into promiscuous mode. If promisc is non-zero, promiscuous mode will be set, otherwise it will not be settimeout- the packet buffer timeout, as a non-negative value, in unitsunit- time timeout unit- Returns:
- the pcap handle
- Throws:
org.jnetpcap.PcapException- any errors- Since:
- libpcap 0.4
-
openLive
public static NetPcap openLive(String device, int snaplen, boolean promisc, long timeout, TimeUnit unit) throws org.jnetpcap.PcapException Open a device for capturing.openLiveis used to obtain a packet capture handle to look at packets on the network. device is a string that specifies the network device to open; on Linux systems with 2.2 or later kernels, a device argument of "any" or NULL can be used to capture packets from all interfaces.- Parameters:
device- the device namesnaplen- specifies the snapshot length to be set on the handlepromisc- specifies whether the interface is to be put into promiscuous mode. If promisc is non-zero, promiscuous mode will be set, otherwise it will not be settimeout- the packet buffer timeout, as a non-negative value, in unitsunit- time timeout unit- Returns:
- the pcap handle
- Throws:
org.jnetpcap.PcapException- any errors- Since:
- libpcap 0.4
-
openOffline
Open a saved capture file for reading.pcap_open_offline() and pcap_open_offline_with_tstamp_precision() are called to open a ``savefile'' for reading.
- Parameters:
file- the offline capture file- Returns:
- the pcap handle
- Throws:
org.jnetpcap.PcapException- any errors- Since:
- libpcap 0.4
-
openOffline
Open a saved capture file for reading.pcap_open_offline() and pcap_open_offline_with_tstamp_precision() are called to open a ``savefile'' for reading.
- Parameters:
fname- specifies the name of the file to open. The file can have the pcap file format as described in pcap-savefile(5), which is the file format used by, among other programs, tcpdump(1) and tcpslice(1), or can have the pcapng file format, although not all pcapng files can be read- Returns:
- the pcap handle
- Throws:
org.jnetpcap.PcapException- any errors- Since:
- libpcap 0.4
-
activate
public void activate() throws org.jnetpcap.PcapActivatedException, org.jnetpcap.PcapExceptionActivate the pcap-pro handle and all its resources. If the underlying basic pcap handle also requires activation, it will also be activated. The pcap-pro activation will allocated any required related resources such as packet processors, allocate requested memory buffers and configure pro filters and packet buffer dissectors.It is always required to call this
activate()method on a pcap-pro handle, even if the underlying pcap handle does not require it such as for dead or offline handles.- Overrides:
activatein classorg.jnetpcap.Pcap1_0- Throws:
org.jnetpcap.PcapActivatedException- thrown if pcap-pro handle has already been activated, however underlying base pcap handle even for dead, openLive or already otherwise uneccessary activations, are not thrown, as per this pcap-pro extension of this methodorg.jnetpcap.PcapException- any pcap exceptions during activation process- See Also:
-
close
public void close()Close.- Specified by:
closein interfaceAutoCloseable- Overrides:
closein classorg.jnetpcap.Pcap0_4- See Also:
-
dispatch
Dispatch which uses a simple packet consumer.- Parameters:
count- A value of -1 or 0 for count is equivalent to infinity, so that packets are processed until another ending condition occurspacketConsumer- the packet consumer- Returns:
- returns 0 if count is exhausted or if, when reading from a ``savefile'', no more packets are available. It returns PCAP_ERROR_BREAK if the loop terminated due to a call to pcap_breakloop() before any packets were processed
-
dispatch
Process packets from a live capture or savefile.pcap_loop() processes packets from a live capture or ``savefile'' until cnt packets are processed, the end of the ``savefile'' is reached when reading from a ``savefile'', pcap_breakloop(3PCAP) is called, or an error occurs. It does not return when live packet buffer timeouts occur. A value of -1 or 0 for cnt is equivalent to infinity, so that packets are processed until another ending condition occurs.
Note that, when doing a live capture on some platforms, if the read timeout expires when there are no packets available, pcap_dispatch() will return 0, even when not in non-blocking mode, as there are no packets to process. Applications should be prepared for this to happen, but must not rely on it happening.
callback specifies a pcap_handler routine to be called with three arguments: a u_char pointer which is passed in the user argument to pcap_loop() or pcap_dispatch(), a const struct pcap_pkthdr pointer pointing to the packet time stamp and lengths, and a const u_char pointer to the first caplen (as given in the struct pcap_pkthdr a pointer to which is passed to the callback routine) bytes of data from the packet. The struct pcap_pkthdr and the packet data are not to be freed by the callback routine, and are not guaranteed to be valid after the callback routine returns; if the full needs them to be valid after the callback, it must make a copy of them.
The bytes of data from the packet begin with a link-layer header. The format of the link-layer header is indicated by the return value of the pcap_datalink(3PCAP) routine when handed the pcap_t value also passed to pcap_loop() or pcap_dispatch(). https://www.tcpdump.org/linktypes.html lists the values pcap_datalink() can return and describes the packet formats that correspond to those values. The value it returns will be valid for all packets received unless and until pcap_set_datalink(3PCAP) is called; after a successful call to pcap_set_datalink(), all subsequent packets will have a link-layer header of the type specified by the link-layer header type value passed to pcap_set_datalink().
Do NOT assume that the packets for a given capture or ``savefile`` will have any given link-layer header type, such as DLT_EN10MB for Ethernet. For example, the "any" device on Linux will have a link-layer header type of DLT_LINUX_SLL or DLT_LINUX_SLL2 even if all devices on the system at the time the "any" device is opened have some other data link type, such as DLT_EN10MB for Ethernet.
- Type Parameters:
U- the generic type- Parameters:
count- A value of -1 or 0 for count is equivalent to infinity, so that packets are processed until another ending condition occurshandler- array handler which will receive packetsuser- the user- Returns:
- returns 0 if count is exhausted or if, when reading from a ``savefile'', no more packets are available. It returns PCAP_ERROR_BREAK if the loop terminated due to a call to pcap_breakloop() before any packets were processed
- Since:
- libpcap 0.4
-
dispatch
Dispatch which uses a simple packet consumer.- Parameters:
packetConsumer- the packet consumer- Returns:
- returns 0 if count is exhausted or if, when reading from a ``savefile'', no more packets are available. It returns PCAP_ERROR_BREAK if the loop terminated due to a call to pcap_breakloop() before any packets were processed
-
enableIpf
Install factory.- Type Parameters:
T- the generic type- Parameters:
b- the b- Returns:
- the t
-
enableIpfIf
Enable ipf if.- Type Parameters:
T- the generic type- Parameters:
b- the b- Returns:
- the pcap pro
-
enablePacketFormatter
Enable "pretty print" packet formatter.- Parameters:
b- if true enable formatting, otherwise disable formatting and default to builtin "terse" packet format- Returns:
- this pcap pro instance
-
getContext
Gets the context.- Returns:
- the context
-
getDroppedCaplenCount
public long getDroppedCaplenCount()Gets the dropped caplen count.- Specified by:
getDroppedCaplenCountin interfaceCaptureStatistics- Returns:
- the dropped caplen count
- See Also:
-
getDroppedPacketCount
public long getDroppedPacketCount()Gets the dropped packet count.- Specified by:
getDroppedPacketCountin interfaceCaptureStatistics- Returns:
- the dropped packet count
- See Also:
-
getDroppedWirelenCount
public long getDroppedWirelenCount()Gets the dropped wirelen count.- Specified by:
getDroppedWirelenCountin interfaceCaptureStatistics- Returns:
- the dropped wirelen count
- See Also:
-
getPcapType
Gets the pcap type.- Returns:
- the pcapType
-
getReceivedCaplenCount
public long getReceivedCaplenCount()Gets the received caplen count.- Specified by:
getReceivedCaplenCountin interfaceCaptureStatistics- Returns:
- the received caplen count
- See Also:
-
getReceivedPacketCount
public long getReceivedPacketCount()Gets the received packet count.- Specified by:
getReceivedPacketCountin interfaceCaptureStatistics- Returns:
- the received packet count
- See Also:
-
getReceivedWirelenCount
public long getReceivedWirelenCount()Gets the received wirelen count.- Specified by:
getReceivedWirelenCountin interfaceCaptureStatistics- Returns:
- the received wirelen count
- See Also:
-
getUncaughtException
Gets any uncaught exceptions.- Returns:
- the uncaught exception
-
installPost
public <T extends PcapProConfigurator.PostRxProcessor> T installPost(PcapProConfigurator.PostRxProcessorFactory<T> postProcessorSupplier) Install factory.- Type Parameters:
T- the generic type- Parameters:
postProcessorSupplier- the post processor supplier- Returns:
- the t
-
installPre
public <T extends PcapProConfigurator.PreRxProcessor> T installPre(PcapProConfigurator.PreRxProcessorFactory<T> preProcessorSupplier) Install factory.- Type Parameters:
T- the generic type- Parameters:
preProcessorSupplier- the pre processor supplier- Returns:
- the t
-
install
Install.- Type Parameters:
T- the generic type- Parameters:
postProcessor- the post processor- Returns:
- the t
-
install
Install.- Type Parameters:
T- the generic type- Parameters:
preProcessor- the pre processor- Returns:
- the t
-
loop
Process packets from a live capture or savefile.- Parameters:
count- A value of -1 or 0 for count is equivalent to infinity, so that packets are processed until another ending condition occurspacketConsumer- the packet consumer- Returns:
- returns 0 if count is exhausted or if, when reading from a ``savefile'', no more packets are available. It returns PCAP_ERROR_BREAK if the loop terminated due to a call to pcap_breakloop() before any packets were processed
-
loop
Process packets from a live capture or savefile.pcap_loop() processes packets from a live capture or ``savefile'' until cnt packets are processed, the end of the ``savefile'' is reached when reading from a ``savefile'', pcap_breakloop(3PCAP) is called, or an error occurs. It does not return when live packet buffer timeouts occur. A value of -1 or 0 for cnt is equivalent to infinity, so that packets are processed until another ending condition occurs.
Note that, when doing a live capture on some platforms, if the read timeout expires when there are no packets available, pcap_dispatch() will return 0, even when not in non-blocking mode, as there are no packets to process. Applications should be prepared for this to happen, but must not rely on it happening.
callback specifies a pcap_handler routine to be called with three arguments: a u_char pointer which is passed in the user argument to pcap_loop() or pcap_dispatch(), a const struct pcap_pkthdr pointer pointing to the packet time stamp and lengths, and a const u_char pointer to the first caplen (as given in the struct pcap_pkthdr a pointer to which is passed to the callback routine) bytes of data from the packet. The struct pcap_pkthdr and the packet data are not to be freed by the callback routine, and are not guaranteed to be valid after the callback routine returns; if the full needs them to be valid after the callback, it must make a copy of them.
The bytes of data from the packet begin with a link-layer header. The format of the link-layer header is indicated by the return value of the pcap_datalink(3PCAP) routine when handed the pcap_t value also passed to pcap_loop() or pcap_dispatch(). https://www.tcpdump.org/linktypes.html lists the values pcap_datalink() can return and describes the packet formats that correspond to those values. The value it returns will be valid for all packets received unless and until pcap_set_datalink(3PCAP) is called; after a successful call to pcap_set_datalink(), all subsequent packets will have a link-layer header of the type specified by the link-layer header type value passed to pcap_set_datalink().
Do NOT assume that the packets for a given capture or ``savefile`` will have any given link-layer header type, such as DLT_EN10MB for Ethernet. For example, the "any" device on Linux will have a link-layer header type of DLT_LINUX_SLL or DLT_LINUX_SLL2 even if all devices on the system at the time the "any" device is opened have some other data link type, such as DLT_EN10MB for Ethernet.
- Type Parameters:
U- the generic type- Parameters:
count- A value of -1 or 0 for count is equivalent to infinity, so that packets are processed until another ending condition occurshandler- array handler which will receive packetsuser- the user- Returns:
- returns 0 if count is exhausted or if, when reading from a ``savefile'', no more packets are available. It returns PCAP_ERROR_BREAK if the loop terminated due to a call to pcap_breakloop() before any packets were processed
- Since:
- libpcap 0.4
-
loop
Process packets from a live capture or savefile.- Parameters:
packetConsumer- the packet consumer- Returns:
- returns 0 if count is exhausted or if, when reading from a ``savefile'', no more packets are available. It returns PCAP_ERROR_BREAK if the loop terminated due to a call to pcap_breakloop() before any packets were processed
-
next
public org.jnetpcap.util.PcapPacketRefPREVIEW next() throws org.jnetpcap.PcapExceptionNext.- Overrides:
nextin classorg.jnetpcap.Pcap0_4- Returns:
- the pcap packet ref
- Throws:
org.jnetpcap.PcapException- the pcap exception- See Also:
-
nextEx
public org.jnetpcap.util.PcapPacketRefPREVIEW nextEx() throws org.jnetpcap.PcapException, TimeoutExceptionNext ex.- Overrides:
nextExin classorg.jnetpcap.Pcap0_8- Returns:
- the pcap packet ref
- Throws:
org.jnetpcap.PcapException- the pcap exceptionTimeoutException- the timeout exception- See Also:
-
nextExPacket
public com.slytechs.jnet.protocol.Packet nextExPacket() throws org.jnetpcap.PcapException, TimeoutExceptionRead the next packet from a pcap handle.reads the next packet and returns a success/failure indication. If the packet was read without problems, the pointer pointed to by the pktHeader argument is set to point to the pcap_pkthdr struct for the packet, and the pointer pointed to by the pktData argument is set to point to the data in the packet. The struct pcap_pkthdr and the packet data are not to be freed by the caller, and are not guaranteed to be valid after the next call to
nextEx(),next(),loop(int, com.slytechs.jnet.jnetpcap.PcapProHandler.OfPacketConsumer), ordispatch(int, com.slytechs.jnet.jnetpcap.PcapProHandler.OfPacketConsumer); if the full needs them to remain valid, it must make a copy of them. *The bytes of data from the packet begin with a link-layer header. The format of the link-layer header is indicated by the return value of the
datalinkroutine when handed the pcap_t value also passed toloopordispatch. https://www.tcpdump.org/linktypes.html lists the valuesdatalinkcan return and describes the packet formats that correspond to those values. The value it returns will be valid for all packets received unless and untilsetDatalinkis called; after a successful call tosetDatalink, all subsequent packets will have a link-layer header of the type specified by the link-layer header type value passed tosetDatalink.Do NOT assume that the packets for a given capture or ``savefile`` will have any given link-layer header type, such as DLT_EN10MB for Ethernet. For example, the "any" device on Linux will have a link-layer header type of DLT_LINUX_SLL or DLT_LINUX_SLL2 even if all devices on the system at the time the "any" device is opened have some other data link type, such as DLT_EN10MB for Ethernet.
- Returns:
- a native pcap packet reference or null if packets are being read from a ``savefile'' and there are no more packets to read from the savefile.
- Throws:
org.jnetpcap.PcapException- any pcap errors such as not activated, etc.TimeoutException- if packets are being read from a live capture and the packet buffer timeout expired- Since:
- Pcap 0.8
-
nextPacket
public com.slytechs.jnet.protocol.Packet nextPacket() throws org.jnetpcap.PcapExceptionread the next packet from a handle.reads the next packet (by calling dispatch with a cnt of 1) and returns a u_char pointer to the data in that packet. The packet data is not to be freed by the caller, and is not guaranteed to be valid after the next call to nextEx, next, loop, or dispatch; if the full needs it to remain valid, it must make a copy of it. The pcap_pkthdr structure pointed to by h is filled in with the appropriate values for the packet.
The bytes of data from the packet begin with a link-layer header. The format of the link-layer header is indicated by the return value of the
datalinkroutine when handed the pcap_t value also passed toloopordispatch. https://www.tcpdump.org/linktypes.html lists the valuesdatalinkcan return and describes the packet formats that correspond to those values. The value it returns will be valid for all packets received unless and untilsetDatalinkis called; after a successful call tosetDatalink, all subsequent packets will have a link-layer header of the type specified by the link-layer header type value passed tosetDatalink.Do NOT assume that the packets for a given capture or ``savefile`` will have any given link-layer header type, such as DLT_EN10MB for Ethernet. For example, the "any" device on Linux will have a link-layer header type of DLT_LINUX_SLL or DLT_LINUX_SLL2 even if all devices on the system at the time the "any" device is opened have some other data link type, such as DLT_EN10MB for Ethernet.
- Returns:
- a pointer to the packet data on success, and returns NULL if no packets were read from a live capture (if, for example, they were discarded because they didn't pass the packet filter, or if, on platforms that support a packet buffer timeout that starts before any packets arrive, the timeout expires before any packets arrive, or if the file descriptor for the capture device is in non-blocking mode and no packets were available to be read), or if no more packets are available in a ``savefile.'' Unfortunately, there is no way to determine whether an error occurred or not.
- Throws:
org.jnetpcap.PcapException- Unfortunately, there is no way to determine whether an error occurred or not so exception may be due to no packets being captured and not an actual error.- Since:
- libpcap 0.4
-
onClose
On close.- Parameters:
closeAction- the close action- Returns:
- the registration
-
setDescriptorType
public NetPcap setDescriptorType(com.slytechs.jnet.protocol.core.constants.PacketDescriptorType type) Sets the descriptor type.- Parameters:
type- the type- Returns:
- the pcap pro
-
setFrameNumber
Sets the frame number.- Parameters:
frameNumberAssigner- the frame number assigner- Returns:
- the pcap pro
-
setFrameStartingNumber
Sets the frame starting number.- Parameters:
startingNo- the starting no- Returns:
- the pcap pro
-
setPacketFormatter
Sets the packet formatter.- Parameters:
formatter- the formatter- Returns:
- the pcap pro
-
setPortNumber
Sets the port number.- Parameters:
portNo- the port no- Returns:
- the pcap pro
-
setTimestampUnit
Sets the timestamp unit which specifies the timestamp used by this pcap handle.- Parameters:
unit- the new timestamp unit- Returns:
- this pcap
-
setUncaughtExceptionHandler
Sets the uncaught exception handler.- Overrides:
setUncaughtExceptionHandlerin classorg.jnetpcap.Pcap- Parameters:
exceptionHandler- the exception handler- Returns:
- the pcap
-
setUncaughtExceptionHandler
Sets the uncaught exception handler.- Overrides:
setUncaughtExceptionHandlerin classorg.jnetpcap.Pcap0_4- Parameters:
exceptionHandler- the exception handler- Returns:
- the pcap pro
- See Also:
-
uninstall
Uninstall a specific processor (either pre or post) by its type.- Type Parameters:
T- the generic type- Parameters:
processorClass- the processor class- Returns:
- this pcap pro handle
-
uninstall
Uninstall a specific processor instance (either pre or post), if installed.- Type Parameters:
T- the generic type- Parameters:
processor- the processor instance- Returns:
- this pcap pro handle
-
uninstAll
Uninstall selectively all pre or post packet processors. The processors are removed from the install queues and will not be installed at the time of activation.- Parameters:
preProcessors- the pre processorspostProcessors- the post processors- Returns:
- the pcap pro
-
uninstallAll
Uninstall all pre and post packet processors. The processors are removed from the installation queues and will not be installed at the time of activation.- Returns:
- reference to this pcap handle
-
setBufferSize
public NetPcap setBufferSize(long size, com.slytechs.jnet.jnetruntime.util.MemoryUnit unit) throws org.jnetpcap.PcapException Sets the buffer size for a not-yet- activated capture handle.sets the buffer size that will be used on a capture handle when the handle is activated to buffer_size, which is in units of bytes
- Parameters:
size- the size of the buffer in specified unitsunit- memory units- Returns:
- this pcap handle
- Throws:
org.jnetpcap.PcapException- the pcap exception- Since:
- libpcap 1.0, jNetPcap Pro 1.0
-