Package pcap.api.internal
Class Pcap
java.lang.Object
pcap.api.internal.Pcap
- All Implemented Interfaces:
java.lang.AutoCloseable,pcap.spi.Pcap
@Inclubating
public class Pcap
extends java.lang.Object
implements pcap.spi.Pcap
Pcap handle.- Author:
- Ardika Rommy Sanjaya
-
Constructor Summary
Constructors Constructor Description Pcap(java.foreign.memory.Pointer<pcap_mapping.pcap> pcap)Pcap(java.foreign.memory.Pointer<pcap_mapping.pcap> pcap, int netmask) -
Method Summary
Modifier and Type Method Description voidbreakLoop()Force aloop(int, PacketHandler, Object)call to return And throwBreakExceptiononloop(int, PacketHandler, Object).voidclose()ClosePcapLiveorPcapOffline.pcap.spi.DumperdumpOpen(java.lang.String file)OpenDumperhandler.pcap.spi.DumperdumpOpenAppend(java.lang.String file)Append packet buffer on existingpcapfile.<T> voidloop(int count, pcap.spi.PacketHandler<T> handler, T args)Process packets from a livePcapLiveorPcapOffline.voidsend(java.nio.ByteBuffer buffer)Sends a raw packet through the network interface.voidsend(java.nio.ByteBuffer buffer, int size)Sends a raw packet through the network interface.voidsetFilter(java.lang.String filter, boolean optimize)BPF packet filter.pcap.spi.Statusstatus()Represent packet statistics from the start of the run to the time of the call.
-
Constructor Details
-
Method Details
-
dumpOpen
public pcap.spi.Dumper dumpOpen(java.lang.String file) throws pcap.spi.exception.ErrorExceptionOpenDumperhandler.- Specified by:
dumpOpenin interfacepcap.spi.Pcap- Parameters:
file- location of capture file will saved.- Returns:
- returns
PcapDumperhandle. - Throws:
pcap.spi.exception.ErrorException
-
dumpOpenAppend
public pcap.spi.Dumper dumpOpenAppend(java.lang.String file) throws pcap.spi.exception.ErrorExceptionAppend packet buffer on existingpcapfile.- Specified by:
dumpOpenAppendin interfacepcap.spi.Pcap- Parameters:
file- location of saved file.- Returns:
- returns
PcapDumperhandle. - Throws:
pcap.spi.exception.ErrorException- generic error.
-
setFilter
public void setFilter(java.lang.String filter, boolean optimize) throws pcap.spi.exception.ErrorExceptionBPF packet filter.- Specified by:
setFilterin interfacepcap.spi.Pcap- Parameters:
filter- filter expression.optimize-truefor optimized filter,falseotherwise.- Throws:
pcap.spi.exception.ErrorException- generic error.
-
loop
public <T> void loop(int count, pcap.spi.PacketHandler<T> handler, T args) throws pcap.spi.exception.error.BreakException, pcap.spi.exception.ErrorExceptionProcess packets from a livePcapLiveorPcapOffline.- Specified by:
loopin interfacepcap.spi.Pcap- Type Parameters:
T- args type.- Parameters:
count- maximum number of packets to process before returning. A value of -1 or 0 for cnt is equivalent to infinity, so that packets are processed until another ending condition occurs.handler-PacketHandlercallback function.args- user args.- Throws:
pcap.spi.exception.error.BreakException-breakLoop()is called.pcap.spi.exception.ErrorException- Generic error.
-
status
public pcap.spi.Status status() throws pcap.spi.exception.ErrorExceptionRepresent packet statistics from the start of the run to the time of the call.Supported only on live captures, not on
PcapOffline; no statistics are stored inPcapOfflineso no statistics are available when reading from aPcapOffline- Specified by:
statusin interfacepcap.spi.Pcap- Returns:
- returns
Statuson success. - Throws:
pcap.spi.exception.ErrorException- There is an error or if thisPcapdoesn't support packet statistics.
-
breakLoop
public void breakLoop()Force aloop(int, PacketHandler, Object)call to return And throwBreakExceptiononloop(int, PacketHandler, Object).- Specified by:
breakLoopin interfacepcap.spi.Pcap
-
send
public void send(java.nio.ByteBuffer buffer) throws pcap.spi.exception.ErrorExceptionSends a raw packet through the network interface.- Parameters:
buffer- the data of the packet, including the link-layer header.- Throws:
pcap.spi.exception.ErrorException- generic error.
-
send
public void send(java.nio.ByteBuffer buffer, int size) throws pcap.spi.exception.ErrorExceptionSends a raw packet through the network interface.- Specified by:
sendin interfacepcap.spi.Pcap- Parameters:
buffer- the data of the packet, including the link-layer header.size- the number of bytes in the packet.- Throws:
pcap.spi.exception.ErrorException- generic error.
-
close
public void close()ClosePcapLiveorPcapOffline. Note: BPF handle will closed automaticly.- Specified by:
closein interfacejava.lang.AutoCloseable- Specified by:
closein interfacepcap.spi.Pcap
-