Package pcap.spi
Interface Pcap
- All Superinterfaces:
AutoCloseable
public interface Pcap extends AutoCloseable
A handle for
pcap
api.- Since:
- 1.0.0
- Author:
- Ardika Rommy Sanjaya
-
Method Summary
Modifier and Type Method Description void
breakLoop()
Force aloop(int, PacketHandler, Object)
call to return And throwBreakException
onloop(int, PacketHandler, Object)
.void
close()
ClosePcapLive
orPcapOffline
.Dumper
dumpOpen(String file)
OpenDumper
handler.Dumper
dumpOpenAppend(String file)
Append packet buffer on existingpcap
file.<T> void
loop(int count, PacketHandler<T> handler, T args)
Process packets from a livePcapLive
orPcapOffline
.void
send(ByteBuffer directBuffer, int size)
Sends a raw packet through the network interface.void
setFilter(String filter, boolean optimize)
BPF packet filter.Status
status()
Represent packet statistics from the start of the run to the time of the call.
-
Method Details
-
dumpOpen
OpenDumper
handler.- Parameters:
file
- location of capture file will saved.- Returns:
- returns
Pcap
Dumper
handle. - Throws:
ErrorException
- generic exception.- Since:
- 1.0.0
-
dumpOpenAppend
Append packet buffer on existingpcap
file.- Parameters:
file
- location of saved file.- Returns:
- returns
Pcap
Dumper
handle. - Throws:
ErrorException
- generic error.- Since:
- 1.0.0
-
setFilter
BPF packet filter.- Parameters:
filter
- filter expression.optimize
-true
for optimized filter,false
otherwise.- Throws:
ErrorException
- generic error.- Since:
- 1.0.0
-
loop
Process packets from a livePcapLive
orPcapOffline
.- Type Parameters:
T
- args type.- Parameters:
count
- maximum number of packets to process before returning. A value of -1 or 0 for count is equivalent to infinity, so that packets are processed until another ending condition occurs.handler
-PacketHandler
callback function.args
- user args.- Throws:
BreakException
-breakLoop()
is called.ErrorException
- Generic error.- Since:
- 1.0.0
-
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 inPcapOffline
so no statistics are available when reading from aPcapOffline
- Returns:
- returns
Status
on success. - Throws:
ErrorException
- There is an error or if thisPcap
doesn't support packet statistics.- Since:
- 1.0.0
-
breakLoop
void breakLoop()Force aloop(int, PacketHandler, Object)
call to return And throwBreakException
onloop(int, PacketHandler, Object)
.- Since:
- 1.0.0
-
send
Sends a raw packet through the network interface.- Parameters:
directBuffer
- the data of the packet, including the link-layer header.size
- the number of bytes in the packet.- Throws:
ErrorException
- generic error.
-
close
void close()ClosePcapLive
orPcapOffline
.
Note: BPF handle will closed automaticly.- Specified by:
close
in interfaceAutoCloseable
- Since:
- 1.0.0
-