public final class PcapHandle extends Object
Modifier and Type | Class and Description |
---|---|
static class |
PcapHandle.BlockingMode |
static class |
PcapHandle.Builder |
static class |
PcapHandle.SwappedType |
Modifier and Type | Method and Description |
---|---|
void |
breakLoop()
Breaks a loop which this handle is working on.
|
void |
close()
Closes this PcapHandle.
|
BpfProgram |
compileFilter(String bpfExpression,
BpfProgram.BpfCompileMode mode,
Inet4Address netmask) |
int |
dispatch(int packetCount,
PacketListener listener) |
int |
dispatch(int packetCount,
PacketListener listener,
Executor executor) |
PcapDumper |
dumpOpen(String filePath) |
PcapHandle.BlockingMode |
getBlockingMode() |
DataLinkType |
getDlt() |
String |
getError() |
String |
getFilteringExpression() |
int |
getMajorVersion() |
int |
getMinorVersion() |
Packet |
getNextPacket() |
Packet |
getNextPacketEx() |
int |
getSnapshot() |
PcapStat |
getStats() |
Long |
getTimestampInts() |
Integer |
getTimestampMicros() |
boolean |
isOpen() |
PcapHandle.SwappedType |
isSwapped() |
List<DataLinkType> |
listDatalinks() |
void |
loop(int packetCount,
PacketListener listener)
A wrapper method for
int pcap_loop(pcap_t *, int, pcap_handler, u_char *) . |
void |
loop(int packetCount,
PacketListener listener,
Executor executor)
A wrapper method for
int pcap_loop(pcap_t *, int, pcap_handler, u_char *) . |
void |
loop(int packetCount,
PcapDumper dumper) |
void |
sendPacket(Packet packet) |
void |
setBlockingMode(PcapHandle.BlockingMode mode) |
void |
setDlt(DataLinkType dlt) |
void |
setFilter(BpfProgram prog) |
void |
setFilter(String bpfExpression,
BpfProgram.BpfCompileMode mode) |
void |
setFilter(String bpfExpression,
BpfProgram.BpfCompileMode mode,
Inet4Address netmask) |
String |
toString() |
public DataLinkType getDlt()
public void setDlt(DataLinkType dlt) throws PcapNativeException, NotOpenException
dlt
- a DataLinkType
object to setPcapNativeException
NotOpenException
public boolean isOpen()
close()
);
false otherwise.public String getFilteringExpression()
public Long getTimestampInts()
public Integer getTimestampMicros()
public int getSnapshot() throws NotOpenException
NotOpenException
public PcapHandle.SwappedType isSwapped() throws NotOpenException
SwappedType
object.NotOpenException
public int getMajorVersion() throws NotOpenException
NotOpenException
public int getMinorVersion() throws NotOpenException
NotOpenException
public BpfProgram compileFilter(String bpfExpression, BpfProgram.BpfCompileMode mode, Inet4Address netmask) throws PcapNativeException, NotOpenException
bpfExpression
- mode
- netmask
- BpfProgram
object.PcapNativeException
NotOpenException
public void setFilter(String bpfExpression, BpfProgram.BpfCompileMode mode, Inet4Address netmask) throws PcapNativeException, NotOpenException
bpfExpression
- mode
- netmask
- PcapNativeException
NotOpenException
NullPointerException
public void setFilter(String bpfExpression, BpfProgram.BpfCompileMode mode) throws PcapNativeException, NotOpenException
bpfExpression
- mode
- PcapNativeException
NotOpenException
NullPointerException
public void setFilter(BpfProgram prog) throws PcapNativeException, NotOpenException
prog
- PcapNativeException
NotOpenException
public void setBlockingMode(PcapHandle.BlockingMode mode) throws PcapNativeException, NotOpenException
mode
- PcapNativeException
NotOpenException
public PcapHandle.BlockingMode getBlockingMode() throws PcapNativeException, NotOpenException
PcapNativeException
NotOpenException
public Packet getNextPacket() throws NotOpenException
NotOpenException
public Packet getNextPacketEx() throws PcapNativeException, EOFException, TimeoutException, NotOpenException
PcapNativeException
EOFException
TimeoutException
NotOpenException
public void loop(int packetCount, PacketListener listener) throws PcapNativeException, InterruptedException, NotOpenException
int pcap_loop(pcap_t *, int, pcap_handler, u_char *)
.
When a packet is captured, listener.gotPacket(Packet)
is called in
the thread which called the loop()
. And then this PcapHandle waits for
the thread to return from the gotPacket()
before it retrieves the next
packet from the pcap capture buffer.packetCount
- listener
- PcapNativeException
InterruptedException
NotOpenException
public void loop(int packetCount, PacketListener listener, Executor executor) throws PcapNativeException, InterruptedException, NotOpenException
int pcap_loop(pcap_t *, int, pcap_handler, u_char *)
.
When a packet is captured, the
executor.execute()
is called
with a Runnable object in the thread which called the loop()
.
Then, the Runnable object calls listener.gotPacket(Packet)
.
If listener.gotPacket(Packet)
is expected to take a long time to
process a packet, this method should be used with a proper executor instead of
loop(int, PacketListener)
in order to prevent the pcap capture buffer from overflowing.packetCount
- listener
- executor
- PcapNativeException
InterruptedException
NotOpenException
public int dispatch(int packetCount, PacketListener listener) throws PcapNativeException, InterruptedException, NotOpenException
packetCount
- listener
- PcapNativeException
InterruptedException
NotOpenException
public int dispatch(int packetCount, PacketListener listener, Executor executor) throws PcapNativeException, InterruptedException, NotOpenException
packetCount
- listener
- executor
- PcapNativeException
InterruptedException
NotOpenException
public PcapDumper dumpOpen(String filePath) throws PcapNativeException, NotOpenException
filePath
- "-" means stdout.
The dlt of the PcapHandle which captured the packets you want to dump
must be the same as this dlt.PcapNativeException
NotOpenException
public void loop(int packetCount, PcapDumper dumper) throws PcapNativeException, InterruptedException, NotOpenException
packetCount
- dumper
- PcapNativeException
InterruptedException
NotOpenException
public void breakLoop() throws NotOpenException
NotOpenException
public void sendPacket(Packet packet) throws PcapNativeException, NotOpenException
packet
- PcapNativeException
NotOpenException
NullPointerException
public PcapStat getStats() throws PcapNativeException, NotOpenException
PcapStat
object.PcapNativeException
NotOpenException
public List<DataLinkType> listDatalinks() throws PcapNativeException, NotOpenException
DataLinkType
PcapNativeException
NotOpenException
public String getError() throws NotOpenException
NotOpenException
public void close()
Copyright © 2014. All Rights Reserved.