Package pcap.api.internal
Class Pcap
java.lang.Object
pcap.api.internal.Pcap
- All Implemented Interfaces:
java.lang.AutoCloseable,Pcap
@Inclubating public class Pcap extends java.lang.Object implements Pcap
Pcap handle.- Author:
- Ardika Rommy Sanjaya
-
Nested Class Summary
-
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.<T> voiddispatch(int count, PacketHandler<T> handler, T args)DumperdumpOpen(java.lang.String file)OpenDumperhandler.DumperdumpOpenAppend(java.lang.String file)Append packet buffer on existingpcapfile.<T> voidloop(int count, 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.voidsetDirection(Pcap.Direction direction)voidsetFilter(java.lang.String filter, boolean optimize)BPF packet filter.Statusstatus()Represent packet statistics from the start of the run to the time of the call.
-
Constructor Details
-
Method Details
-
dumpOpen
OpenDumperhandler.- Specified by:
dumpOpenin interfacePcap- Parameters:
file- location of capture file will saved.- Returns:
- returns
PcapDumperhandle. - Throws:
ErrorException
-
dumpOpenAppend
Append packet buffer on existingpcapfile.- Specified by:
dumpOpenAppendin interfacePcap- Parameters:
file- location of saved file.- Returns:
- returns
PcapDumperhandle. - Throws:
ErrorException- generic error.
-
setFilter
BPF packet filter.- Specified by:
setFilterin interfacePcap- Parameters:
filter- filter expression.optimize-truefor optimized filter,falseotherwise.- Throws:
ErrorException- generic error.
-
loop
public <T> void loop(int count, PacketHandler<T> handler, T args) throws BreakException, ErrorExceptionProcess packets from a livePcapLiveorPcapOffline.- Specified by:
loopin interfacePcap- 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:
BreakException-breakLoop()is called.ErrorException- Generic error.
-
dispatch
public <T> void dispatch(int count, PacketHandler<T> handler, T args) throws BreakException, ErrorException- Specified by:
dispatchin interfacePcap- Throws:
BreakExceptionErrorException
-
status
Represent 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- Returns:
- returns
Statuson success. - Throws:
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). -
send
Sends a raw packet through the network interface.- Parameters:
buffer- the data of the packet, including the link-layer header.- Throws:
ErrorException- generic error.
-
send
Sends a raw packet through the network interface.- Specified by:
sendin interfacePcap- Parameters:
buffer- the data of the packet, including the link-layer header.size- the number of bytes in the packet.- Throws:
ErrorException- generic error.
-
setDirection
- Specified by:
setDirectionin interfacePcap- Throws:
ErrorException
-
close
public void close()ClosePcapLiveorPcapOffline. Note: BPF handle will closed automaticly.
-