public final class PcapHandle extends Object
| Modifier and Type | Class and Description |
|---|---|
static class |
PcapHandle.BlockingMode |
static class |
PcapHandle.Builder
This class is used to open (i.e.
|
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) |
int |
dispatch(int packetCount,
RawPacketListener listener) |
int |
dispatch(int packetCount,
RawPacketListener listener,
Executor executor) |
PcapDumper |
dumpOpen(String filePath) |
PcapHandle.BlockingMode |
getBlockingMode() |
DataLinkType |
getDlt() |
String |
getError() |
String |
getFilteringExpression() |
int |
getMajorVersion() |
int |
getMinorVersion() |
Packet |
getNextPacket() |
Packet |
getNextPacketEx() |
byte[] |
getNextRawPacket() |
byte[] |
getNextRawPacketEx() |
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 |
loop(int packetCount,
RawPacketListener listener)
A wrapper method for
int pcap_loop(pcap_t *, int, pcap_handler, u_char *). |
void |
loop(int packetCount,
RawPacketListener listener,
Executor executor)
A wrapper method for
int pcap_loop(pcap_t *, int, pcap_handler, u_char *). |
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 setPcapNativeExceptionNotOpenExceptionpublic boolean isOpen()
close());
false otherwise.public String getFilteringExpression()
public Long getTimestampInts()
public Integer getTimestampMicros()
public int getSnapshot()
throws NotOpenException
NotOpenExceptionpublic PcapHandle.SwappedType isSwapped() throws NotOpenException
SwappedType object.NotOpenExceptionpublic int getMajorVersion()
throws NotOpenException
NotOpenExceptionpublic int getMinorVersion()
throws NotOpenException
NotOpenExceptionpublic BpfProgram compileFilter(String bpfExpression, BpfProgram.BpfCompileMode mode, Inet4Address netmask) throws PcapNativeException, NotOpenException
bpfExpression - mode - netmask - BpfProgram object.PcapNativeExceptionNotOpenExceptionpublic void setFilter(String bpfExpression, BpfProgram.BpfCompileMode mode, Inet4Address netmask) throws PcapNativeException, NotOpenException
bpfExpression - mode - netmask - PcapNativeExceptionNotOpenExceptionNullPointerExceptionpublic void setFilter(String bpfExpression, BpfProgram.BpfCompileMode mode) throws PcapNativeException, NotOpenException
bpfExpression - mode - PcapNativeExceptionNotOpenExceptionNullPointerExceptionpublic void setFilter(BpfProgram prog) throws PcapNativeException, NotOpenException
prog - PcapNativeExceptionNotOpenExceptionpublic void setBlockingMode(PcapHandle.BlockingMode mode) throws PcapNativeException, NotOpenException
mode - PcapNativeExceptionNotOpenExceptionpublic PcapHandle.BlockingMode getBlockingMode() throws PcapNativeException, NotOpenException
PcapNativeExceptionNotOpenExceptionpublic Packet getNextPacket() throws NotOpenException
NotOpenExceptionpublic byte[] getNextRawPacket()
throws NotOpenException
NotOpenExceptionpublic Packet getNextPacketEx() throws PcapNativeException, EOFException, TimeoutException, NotOpenException
PcapNativeExceptionEOFExceptionTimeoutExceptionNotOpenExceptionpublic byte[] getNextRawPacketEx()
throws PcapNativeException,
EOFException,
TimeoutException,
NotOpenException
PcapNativeExceptionEOFExceptionTimeoutExceptionNotOpenExceptionpublic void loop(int packetCount,
PacketListener listener)
throws PcapNativeException,
InterruptedException,
NotOpenException
int pcap_loop(pcap_t *, int, pcap_handler, u_char *).
This method creates a Packet object from a captured packet using the packet factory and
passes it to listener.gotPacket(Packet).
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 buffer.packetCount - the number of packets to capture. -1 is equivalent to infinity.
0 may result in different behaviors between platforms
and pcap library versions.listener - PcapNativeExceptionInterruptedExceptionNotOpenExceptionpublic void loop(int packetCount,
PacketListener listener,
Executor executor)
throws PcapNativeException,
InterruptedException,
NotOpenException
int pcap_loop(pcap_t *, int, pcap_handler, u_char *).
This method creates a Packet object from a captured packet using the packet factory and
passes it to listener.gotPacket(Packet).
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 buffer from overflowing.packetCount - the number of packets to capture. -1 is equivalent to infinity.
0 may result in different behaviors between platforms
and pcap library versions.listener - executor - PcapNativeExceptionInterruptedExceptionNotOpenExceptionpublic void loop(int packetCount,
RawPacketListener listener)
throws PcapNativeException,
InterruptedException,
NotOpenException
int pcap_loop(pcap_t *, int, pcap_handler, u_char *).
When a packet is captured, listener.gotPacket(byte[]) 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 buffer.packetCount - the number of packets to capture. -1 is equivalent to infinity.
0 may result in different behaviors between platforms
and pcap library versions.listener - PcapNativeExceptionInterruptedExceptionNotOpenExceptionpublic void loop(int packetCount,
RawPacketListener 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(byte[]).
If listener.gotPacket(byte[]) is expected to take a long time to
process a packet, this method should be used with a proper executor instead of
loop(int, RawPacketListener) in order to prevent the pcap buffer from overflowing.packetCount - the number of packets to capture. -1 is equivalent to infinity.
0 may result in different behaviors between platforms
and pcap library versions.listener - executor - PcapNativeExceptionInterruptedExceptionNotOpenExceptionpublic int dispatch(int packetCount,
PacketListener listener)
throws PcapNativeException,
InterruptedException,
NotOpenException
packetCount - the maximum number of packets to process.
If -1 is specified, all the packets in the pcap buffer or pcap file
will be processed before returning.
0 may result in different behaviors between platforms
and pcap library versions.listener - PcapNativeExceptionInterruptedExceptionNotOpenExceptionpublic int dispatch(int packetCount,
PacketListener listener,
Executor executor)
throws PcapNativeException,
InterruptedException,
NotOpenException
packetCount - the maximum number of packets to process.
If -1 is specified, all the packets in the pcap buffer or pcap file
will be processed before returning.
0 may result in different behaviors between platforms
and pcap library versions.listener - executor - PcapNativeExceptionInterruptedExceptionNotOpenExceptionpublic int dispatch(int packetCount,
RawPacketListener listener)
throws PcapNativeException,
InterruptedException,
NotOpenException
packetCount - the maximum number of packets to process.
If -1 is specified, all the packets in the pcap buffer or pcap file
will be processed before returning.
0 may result in different behaviors between platforms
and pcap library versions.listener - PcapNativeExceptionInterruptedExceptionNotOpenExceptionpublic int dispatch(int packetCount,
RawPacketListener listener,
Executor executor)
throws PcapNativeException,
InterruptedException,
NotOpenException
packetCount - the maximum number of packets to process.
If -1 is specified, all the packets in the pcap buffer or pcap file
will be processed before returning.
0 may result in different behaviors between platforms
and pcap library versions.listener - executor - PcapNativeExceptionInterruptedExceptionNotOpenExceptionpublic 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.PcapNativeExceptionNotOpenExceptionpublic void loop(int packetCount,
PcapDumper dumper)
throws PcapNativeException,
InterruptedException,
NotOpenException
packetCount - dumper - PcapNativeExceptionInterruptedExceptionNotOpenExceptionpublic void breakLoop()
throws NotOpenException
NotOpenExceptionpublic void sendPacket(Packet packet) throws PcapNativeException, NotOpenException
packet - PcapNativeExceptionNotOpenExceptionNullPointerExceptionpublic PcapStat getStats() throws PcapNativeException, NotOpenException
PcapStat object.PcapNativeExceptionNotOpenExceptionpublic List<DataLinkType> listDatalinks() throws PcapNativeException, NotOpenException
DataLinkTypePcapNativeExceptionNotOpenExceptionpublic String getError() throws NotOpenException
NotOpenExceptionpublic void close()
Copyright © 2015. All Rights Reserved.