|
SourceForge Jpcap | |||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
public interface PacketCaptureCapable
This is the packet capture interface.
It is implemented by both the packet capture system PacketCapture
and the simulator PacketCaptureSimulator
.
The interface has two major components:
Field Summary | |
---|---|
static int |
DEFAULT_SNAPLEN
Snapshot length. |
static int |
DEFAULT_TIMEOUT
Default capture timeout in milliseconds. |
Method Summary | |
---|---|
void |
addPacketListener(PacketListener listener)
Register a packet object listener with this capture system. |
void |
addRawPacketListener(RawPacketListener listener)
Register a raw packet listener with this capture system. |
void |
capture(int count)
Capture packets. |
void |
close()
Close cleans up after a packet capture session. |
void |
endCapture()
Stop capturing packets. |
String |
findDevice()
Deprecated. Please use PacketCapture.lookupCaptureDevices() . |
String |
getLinkLayerDescription()
Return a description of the link layer for the current capture device, corresponding to getLinkLayerType() . |
int |
getLinkLayerType()
Fetch the link layer type for the current capture device. |
int |
getNetmask(String device)
Deprecated. Please use PacketCapture.lookupCaptureDevices() . |
int |
getNetwork(String device)
Deprecated. Please use PacketCapture.lookupCaptureDevices() . |
int |
getSnapshotLength()
Get the snapshot length specified when this network device was opened. |
CaptureStatistics |
getStatistics()
Fetch statistics on captured packets. |
void |
open(String device,
boolean promiscuous)
Open a network device for data capture. |
void |
open(String device,
int snaplen,
boolean promiscuous,
int timeout)
Open a network device for data capture. |
void |
openOffline(String fileName)
Open a tcpdump-formatted savefile for reading. |
void |
removePacketListener(PacketListener listener)
Deregister a packet object listener from this capture system. |
void |
removeRawPacketListener(RawPacketListener listener)
Deregister a raw packet listener from this capture system. |
void |
setFilter(String filterExpression,
boolean optimize)
Create, compile and activate a filter from a filter expression. |
Field Detail |
---|
static final int DEFAULT_SNAPLEN
static final int DEFAULT_TIMEOUT
Method Detail |
---|
void open(String device, boolean promiscuous) throws CaptureDeviceOpenException
This call is equivalent to
open(device, DEFAULT_SNAPLEN, promiscuous, DEFAULT_TIMEOUT);
device
- the name of the network device.promiscuous
- whether or not the device should be put into
'promiscuous' mode: true => capture all packets; false => capture packets only to and from this system.
CaptureDeviceOpenException
open(String, int, boolean, int)
void open(String device, int snaplen, boolean promiscuous, int timeout) throws CaptureDeviceOpenException
device
- the name of the network device.
Examples of valid network devices on linux are 'eth0' and 'ppp0'.snaplen
- the 'snapshot' length. Defines the maximum number of
bytes to save from each captured packet.promiscuous
- whether or not the device should be put into
'promiscuous' mode: true => capture all packets; false => capture packets only to and from this system.timeout
- the packet capture timeout in milliseconds.
Defines the maximum amount of time that capture will wait for another packet,
if the capture device's buffer isn't full,
before notifying the application of the packets already captured.
A value of zero means return each packet immediately: this mode is rather inefficient.
Timeouts of 500ms-2 seconds are reasonable, or longer if the application can wait longer.
CaptureDeviceOpenException
- can't open the specified devicevoid openOffline(String fileName) throws CaptureFileOpenException
fileName
- the name of the savefile.
CaptureFileOpenException
- can't open the specified filevoid setFilter(String filterExpression, boolean optimize) throws InvalidFilterException
filterExpression
- the filter expression. For example,
the expression "host techno" would filter only packets sent or
arriving at the host named techno.optimize
- whether or not the resulting bpf code is optimized
internally by libpcap.
InvalidFilterException
- invalid filter specificationvoid capture(int count) throws CapturePacketException
count
- the number of packets to capture.
If count is -1, this method will run forever unless endCapture()
is called
or an exception is thrown.
CapturePacketException
- Capture problemvoid endCapture()
capture(int)
call will return.
Does not guarantee that no further packets will be processed after it is called; one more packet might be processed.
CaptureStatistics getStatistics()
capture(int)
was previously called,
with capture occurring from a network device.
void close()
capture(int)
does not return control until 'count' packets are captured.
To signal an end to a capture session before the specified number of packets has been received,
first call endCapture()
.
close
in interface Closeable
String findDevice() throws CaptureDeviceNotFoundException
PacketCapture.lookupCaptureDevices()
.
This API should be static; does not work reliably; and will be removed in a future release.
CaptureDeviceNotFoundException
- No capture devices foundint getNetwork(String device) throws CaptureConfigurationException
PacketCapture.lookupCaptureDevices()
.
This API:
For these reasons it will be removed in a future release.
device
- the name of the network device.
CaptureConfigurationException
- Capture device not foundint getNetmask(String device) throws CaptureConfigurationException
PacketCapture.lookupCaptureDevices()
.
This API:
For these reasons it will be removed in a future release.
device
- the name of the network device.
CaptureConfigurationException
- Capture device not foundString getLinkLayerDescription() throws CaptureConfigurationException
getLinkLayerType()
.
CaptureConfigurationException
- Unknown link layer type.int getLinkLayerType() throws CaptureConfigurationException
CaptureConfigurationException
- Capture configuration lookup problemint getSnapshotLength()
void addRawPacketListener(RawPacketListener listener)
listener
- the raw packet listener to add to the notification
list.
IllegalArgumentException
- 'listener' is nullvoid removeRawPacketListener(RawPacketListener listener)
listener
- the raw packet listener to remove from the
notification list.
IllegalArgumentException
- 'listener' not registeredvoid addPacketListener(PacketListener listener)
listener
- the packet listener to add to the notification list.
IllegalArgumentException
- 'listener' is nullvoid removePacketListener(PacketListener listener)
listener
- the packet listener to remove from the
notification list.
IllegalArgumentException
- 'listener' not registered
|
Copyright © Patrick Charles & Jonas Lehmann, 2001; Esmond Pitt, 2008. | |||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |