net.sourceforge.jpcap.client
Class CaptureTool

java.lang.Object
  extended bynet.sourceforge.jpcap.client.CaptureTool
All Implemented Interfaces:
PacketListener, RawPacketListener

public class CaptureTool
extends java.lang.Object
implements RawPacketListener, PacketListener

Tool with text console for controlling packet capture.


Field Summary
protected static java.lang.String MODE_ASCII
           
protected static java.lang.String MODE_OBJECT
           
protected static java.lang.String MODE_RAW
           
protected static java.lang.String MODE_TERSE
           
protected static java.lang.String MODE_TEXT
           
protected static java.lang.String MODE_VERBOSE
           
 
Constructor Summary
CaptureTool()
          Create a new capture tool.
 
Method Summary
 boolean activateUi()
          Active the graphical packet view.
protected  boolean autoDetect()
          Attempt to detect and open a capture device.
 CaptureStatistics capture(int count)
          Capture packets.
 void clearHistory()
          Clear the capture history.
 int dumpHistory()
          Dump the capture history buffer contents.
 java.lang.String getDevice()
          Fetch the capture device name.
 java.lang.String getFilter()
          Fetch the filter expression.
 CaptureHistory getHistory()
          Fetch a reference to the history buffer.
 int getLinkLayerType()
          Fetch the link-layer type.
 java.lang.String getMode()
          Fetch the capture mode.
 int getNetmask()
          Fetch the netmask for the current device.
 int getNetwork()
          Fetch the network number for the current device.
 int getSnaplen()
          Fetch the snapshot length.
 int getTimeout()
          Fetch the capture timeout value.
protected  void initializeConsole()
          Initialize the tool's console.
protected  void initializeSystem()
          Initialize the packet capture system.
static boolean isModeValid(java.lang.String pmode)
          Check if a proposed mode is valid.
static void main(java.lang.String[] args)
          Packet capture.
 void packetArrived(Packet packet)
           
 void rawPacketArrived(RawPacket rawPacket)
           
 boolean resetViewFrame()
          Reset the capture view frame to clear its contents.
 void setDevice(java.lang.String device)
          Set and open the capture device.
 void setFilter(java.lang.String filter)
          Set the packet filter expression.
 void setMaxHistorySize(int size)
          Set the maximum size of the history FIFO.
 void setMode(java.lang.String mode)
          Set the capture mode.
 void setSnaplen(int snaplen)
          Set the snapshot length.
 void setTimeout(int timeout)
          Set the capture timeout value.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

MODE_RAW

protected static final java.lang.String MODE_RAW
See Also:
Constant Field Values

MODE_OBJECT

protected static final java.lang.String MODE_OBJECT
See Also:
Constant Field Values

MODE_VERBOSE

protected static final java.lang.String MODE_VERBOSE
See Also:
Constant Field Values

MODE_TERSE

protected static final java.lang.String MODE_TERSE
See Also:
Constant Field Values

MODE_ASCII

protected static final java.lang.String MODE_ASCII
See Also:
Constant Field Values

MODE_TEXT

protected static final java.lang.String MODE_TEXT
See Also:
Constant Field Values
Constructor Detail

CaptureTool

public CaptureTool()
Create a new capture tool.

Method Detail

rawPacketArrived

public void rawPacketArrived(RawPacket rawPacket)
Specified by:
rawPacketArrived in interface RawPacketListener

packetArrived

public void packetArrived(Packet packet)
Specified by:
packetArrived in interface PacketListener

initializeSystem

protected void initializeSystem()
Initialize the packet capture system.


autoDetect

protected boolean autoDetect()
Attempt to detect and open a capture device.


initializeConsole

protected void initializeConsole()
Initialize the tool's console.


resetViewFrame

public boolean resetViewFrame()
Reset the capture view frame to clear its contents.

Returns:
whether or not the capture view frame was actually cleared. The only time it should ever not be possible to clear it is when it does not exist (usu. because client has no graphics capability).

clearHistory

public void clearHistory()
Clear the capture history.


setMaxHistorySize

public void setMaxHistorySize(int size)
Set the maximum size of the history FIFO.


dumpHistory

public int dumpHistory()
Dump the capture history buffer contents.


activateUi

public boolean activateUi()
Active the graphical packet view.


getNetwork

public int getNetwork()
               throws CaptureConfigurationException
Fetch the network number for the current device.

Throws:
CaptureConfigurationException

getNetmask

public int getNetmask()
               throws CaptureConfigurationException
Fetch the netmask for the current device.

Throws:
CaptureConfigurationException

getLinkLayerType

public int getLinkLayerType()
                     throws CaptureConfigurationException,
                            CaptureDeviceOpenException
Fetch the link-layer type.

Throws:
CaptureConfigurationException
CaptureDeviceOpenException

setDevice

public void setDevice(java.lang.String device)
               throws CaptureDeviceOpenException
Set and open the capture device.

Throws:
CaptureDeviceOpenException

capture

public CaptureStatistics capture(int count)
                          throws CaptureDeviceOpenException,
                                 InvalidFilterException,
                                 CapturePacketException
Capture packets.

Throws:
CaptureDeviceOpenException
InvalidFilterException
CapturePacketException

getDevice

public java.lang.String getDevice()
Fetch the capture device name.


setFilter

public void setFilter(java.lang.String filter)
               throws InvalidFilterException
Set the packet filter expression.

Throws:
InvalidFilterException

getFilter

public java.lang.String getFilter()
Fetch the filter expression.


setMode

public void setMode(java.lang.String mode)
Set the capture mode.


getMode

public java.lang.String getMode()
Fetch the capture mode.


isModeValid

public static boolean isModeValid(java.lang.String pmode)
Check if a proposed mode is valid.


setTimeout

public void setTimeout(int timeout)
                throws CaptureDeviceOpenException
Set the capture timeout value.

Throws:
CaptureDeviceOpenException

getTimeout

public int getTimeout()
Fetch the capture timeout value.


setSnaplen

public void setSnaplen(int snaplen)
                throws CaptureDeviceOpenException
Set the snapshot length.

Throws:
CaptureDeviceOpenException

getSnaplen

public int getSnaplen()
Fetch the snapshot length.


getHistory

public CaptureHistory getHistory()
Fetch a reference to the history buffer.


main

public static void main(java.lang.String[] args)
Packet capture.