|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--net.sourceforge.jpcap.capture.PacketDispatcher | +--net.sourceforge.jpcap.capture.PacketCaptureBase | +--net.sourceforge.jpcap.capture.PacketCapture
This class is the core of packet capture in jpcap. It provides a high-level interface for capturing network packets by encapsulating libpcap.
If you want to capture network packets, implement PacketListener and register with an instance of this class. When packets arrive, the object will call you back via packetArrived().
Examples can be found in net.sourceforge.jpcap.tutorial.
For more documentation on this class's methods, see PacketCaptureCapable; Javadoc is 'inherited' from this interface.
Field Summary | |
protected static java.lang.String |
LIB_PCAP_WRAPPER
Name of the java-enabled wrapper around libpcap. |
Fields inherited from class net.sourceforge.jpcap.capture.PacketCaptureBase |
droppedCount, linkType, receivedCount |
Fields inherited from interface net.sourceforge.jpcap.capture.PacketCaptureCapable |
DEFAULT_SNAPLEN, DEFAULT_TIMEOUT |
Constructor Summary | |
PacketCapture()
|
Method Summary | |
void |
capture(int count)
Capture packets. |
void |
close()
Close the capture device. |
java.lang.String |
findDevice()
Detect a network device suitable for packet capture. |
int |
getLinkLayerType()
Fetch the link layer type for the specified device. |
int |
getNetmask(java.lang.String device)
Fetch the network mask for the specified device. |
int |
getNetwork(java.lang.String device)
Fetch the network number for the specified device. |
int |
getSnapshotLength()
Get the snapshot length given that network device is open. |
CaptureStatistics |
getStatistics()
Fetch statistics on captured packets. |
static java.lang.String[] |
lookupDevices()
Get Interface List |
void |
open(java.lang.String device,
boolean promiscuous)
Open a network device for data capture. |
void |
open(java.lang.String device,
int snaplen,
boolean promiscuous,
int timeout)
Open a network device for data capture. |
void |
openOffline(java.lang.String fileName)
Open a tcpdump-formatted savefile. |
void |
setFilter(java.lang.String filterExpression,
boolean optimize)
Create, compile and activate a filter from a filter expression. |
Methods inherited from class net.sourceforge.jpcap.capture.PacketCaptureBase |
handlePacket |
Methods inherited from class net.sourceforge.jpcap.capture.PacketDispatcher |
addPacketListener, addRawPacketListener, dispatchPacket, dispatchRawPacket, removePacketListener, removeRawPacketListener |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Methods inherited from interface net.sourceforge.jpcap.capture.PacketCaptureCapable |
addPacketListener, addRawPacketListener, removePacketListener, removeRawPacketListener |
Field Detail |
protected static java.lang.String LIB_PCAP_WRAPPER
Constructor Detail |
public PacketCapture()
Method Detail |
public void open(java.lang.String device, boolean promiscuous) throws CaptureDeviceOpenException
PacketCaptureCapable
open
in interface PacketCaptureCapable
net.sourceforge.jpcap.capture.PacketCaptureCapable
device
- the name of the network device.
Examples of valid network devices on linux are 'eth0' and 'ppp0'.promiscuous
- whether or not the device should be opened in
promiscuous mode.public void open(java.lang.String device, int snaplen, boolean promiscuous, int timeout) throws CaptureDeviceOpenException
PacketCaptureCapable
open
in interface PacketCaptureCapable
net.sourceforge.jpcap.capture.PacketCaptureCapable
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 opened in
promiscuous mode.timeout
- the packet capture timeout in milliseconds.public void openOffline(java.lang.String fileName) throws CaptureFileOpenException
PacketCaptureCapable
openOffline
in interface PacketCaptureCapable
net.sourceforge.jpcap.capture.PacketCaptureCapable
fileName
- the name of the savefile.public void setFilter(java.lang.String filterExpression, boolean optimize) throws InvalidFilterException
PacketCaptureCapable
setFilter
in interface PacketCaptureCapable
net.sourceforge.jpcap.capture.PacketCaptureCapable
filterExpression
- the filter expression. For example,
the expression "host techno" would filter only packets sent or
arriving at the host named techno.public void capture(int count) throws CapturePacketException
PacketCaptureCapable
capture
in interface PacketCaptureCapable
net.sourceforge.jpcap.capture.PacketCaptureCapable
count
- the number of packets to capture.
If count is negative, capture will block forever, unless an exception
is thrown.public CaptureStatistics getStatistics()
PacketCaptureCapable
getStatistics
in interface PacketCaptureCapable
net.sourceforge.jpcap.capture.PacketCaptureCapable
public void close()
PacketCaptureCapable
close
in interface PacketCaptureCapable
public static java.lang.String[] lookupDevices() throws CaptureDeviceLookupException
public java.lang.String findDevice() throws CaptureDeviceNotFoundException
PacketCaptureCapable
findDevice
in interface PacketCaptureCapable
net.sourceforge.jpcap.capture.PacketCaptureCapable
public int getNetwork(java.lang.String device) throws CaptureConfigurationException
PacketCaptureCapable
getNetwork
in interface PacketCaptureCapable
net.sourceforge.jpcap.capture.PacketCaptureCapable
device
- the name of the network device.public int getNetmask(java.lang.String device) throws CaptureConfigurationException
PacketCaptureCapable
getNetmask
in interface PacketCaptureCapable
net.sourceforge.jpcap.capture.PacketCaptureCapable
device
- the name of the network device.public int getLinkLayerType() throws CaptureConfigurationException
PacketCaptureCapable
getLinkLayerType
in interface PacketCaptureCapable
net.sourceforge.jpcap.capture.PacketCaptureCapable
public int getSnapshotLength()
PacketCaptureCapable
getSnapshotLength
in interface PacketCaptureCapable
net.sourceforge.jpcap.capture.PacketCaptureCapable
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |