- All Implemented Interfaces:
AutoCloseable
- Direct Known Subclasses:
Pcap1_0
- Author:
- Sly Technologies Inc, repos@slytechs.com, mark
-
Nested Class Summary
Modifier and TypeClassDescriptionprotected static class
Symbol container for lazy initialization.Nested classes/interfaces inherited from class org.jnetpcap.Pcap0_8
Pcap0_8.Unix0_8
Nested classes/interfaces inherited from class org.jnetpcap.Pcap0_4
Pcap0_4.PcapSupplier<T extends Pcap>
Nested classes/interfaces inherited from class org.jnetpcap.Pcap
Pcap.LibraryPolicy, Pcap.Linux, Pcap.Unix
-
Field Summary
Fields inherited from class org.jnetpcap.Pcap0_4
dispatcher
Fields inherited from class org.jnetpcap.Pcap
closed, pcapHeaderABI, POINTER_TO_POINTER1, POINTER_TO_POINTER2, POINTER_TO_POINTER3, VERSION
-
Constructor Summary
ModifierConstructorDescriptionprotected
Pcap0_9
(MemorySegment pcapHandle, String name, PcapHeaderABI abi) Instantiates a new pcap 0 9. -
Method Summary
Modifier and TypeMethodDescriptionint
inject
(MemorySegment packet, int length) Inject.static boolean
Checks if thePcap
subclass at a specific libpcap API version is natively supported.static Pcap0_9
Open a fake pcap_t for compiling filters or opening a capture for output.static Pcap0_9
Open a device for capturing.setDirection
(int dir) Sets the direction.protected int
setProtocolLinux
(int protocol) set capture protocol for a not-yet-activated capture handle.Methods inherited from class org.jnetpcap.Pcap0_8
breakloop, datalinkNameToVal, dataLinkValToDescription, dataLinkValToName, getSelectableFd, libVersion, listDataLinks, nextEx, openOffline, sendPacket, setDatalink
Methods inherited from class org.jnetpcap.Pcap0_7
findAllDevs, getNonBlock, setNonBlock
Methods inherited from class org.jnetpcap.Pcap0_5
compileNoPcap
Methods inherited from class org.jnetpcap.Pcap0_4
close, compile, datalink, datalinkGetAsInt, dispatch, dispatch, dispatch, dispatch, dumpOpen, file, fileno, getDispatcher, geterr, isInitialized, isSwapped, lookupDev, lookupNet, loop, loop, loop, loop, majorVersion, minorVersion, next, openLive, openOffline, perror, setDispatcher, setFilter, setUncaughtExceptionHandler, snapshot, stats, strerror
Methods inherited from class org.jnetpcap.Pcap
activate, canSetRfmon, checkPcapVersion, compile, create, create, dataLinkExt, datalinkValToDescription, datalinkValToName, findAllDevsEx, getErrorString, getName, getPcapHandle, getPcapHeaderABI, getTstampPrecision, init, init, inject, inject, inject, listAllPcapIf, listTstampTypes, loadNativePcapLibrary, lookupErrorString, lookupNet, newArena, offlineFilter, openDeadWithTstampPrecision, openLive, openLive, openOffline, order, sendPacket, sendPacket, sendPacket, setBufferSize, setDatalink, setDatalink, setDirection, setDirection, setFilter, setImmediateMode, setPromisc, setRfmon, setSnaplen, setTimeout, setTstampPrecision, setTstampType, setUncaughtExceptionHandler, statusToStr, statusToStr, toString
-
Constructor Details
-
Pcap0_9
Instantiates a new pcap 0 9.- Parameters:
pcapHandle
- the pcap handlename
- the handle nameabi
- the abi
-
-
Method Details
-
setDirection
Sets the direction.- Overrides:
setDirection
in classPcap
- Parameters:
dir
- the dir- Returns:
- the pcap 0 9
- Throws:
PcapException
- the pcap exception- See Also:
-
isSupported
public static boolean isSupported()Checks if thePcap
subclass at a specific libpcap API version is natively supported. This is a safe method to use anytime on any platform, weather native library is present or not.For example,
Pcap1_0.isSupported()
will accurately ascertain if libpcap API version 1.0 level calls are supported by the system runtime. Also a call such asWinPcap.isSupported()
will determine if WinPcap related calls, ie. native WinPcap 4.1.3 or less, are supported and by extension if this is a Microsoft Windows platform.Due to libpcap API versioning, it is safe to assume that if
Pcap1_10.isSupported()
returnstrue
, that at least libpcap API version 1.0 is installed on this platform, and that all lower version calls such as libpcap 0.8 and 0.9 are available as well. The subclass hierarchy of jNetPcap module reflects the versioning of libpcap and its derivatives and the public releases of the native libraries. For exampleNpcap
class extendsWinPcap
class because Npcap project took over the support for WinPcap where it left off.Implementation notes: The check is performed by verifying that certain, subclass specific native symbols were linked with
Pcap
full which was introduced at a specific libpcap or related API levels.- Returns:
- true, if pcap is supported up to this specific version level, otherwise false
- See Also:
-
openDead
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:
PcapException
- any errors- Since:
- libpcap 0.6
-
openLive
public static Pcap0_9 openLive(String device, int snaplen, boolean promisc, long timeout, TimeUnit unit) throws PcapException Open a device for capturing.openLive
is 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:
PcapException
- any errors- Since:
- libpcap 0.4
-
inject
Inject.- Overrides:
inject
in classPcap
- Parameters:
packet
- the packetlength
- the length- Returns:
- the int
- Throws:
PcapException
- the pcap exception- See Also:
-
setProtocolLinux
set capture protocol for a not-yet-activated capture handle.On network interface devices on Linux, pcap_set_protocol_linux() sets the protocol to be used in the socket(2) call to create a capture socket when the handle is activated. The argument is a link-layer protocol value, such as the values in the
<linux/if_ether.h>
header file, specified in host byte order. If protocol is non-zero, packets of that protocol will be captured when the handle is activated, otherwise, all packets will be captured. This function is only provided on Linux, and, if it is used on any device other than a network interface, it will have no effect. It should not be used in portable full; instead, a filter should be specified with pcap_setfilter(3PCAP).If a given network interface provides a standard link-layer header, with a standard packet type, but provides some packet types with a different socket-layer protocol type from the one in the link-layer header, that packet type cannot be filtered with a filter specified with pcap_setfilter() but can be filtered by specifying the socket-layer protocol type using pcap_set_protocol_linux().
- Parameters:
protocol
- the protocol- Returns:
- the int
- Throws:
PcapException
- the pcap exception- Since:
- libpcap 0.9 (Linux only)
-