jnetpcap.capture
Interface LiveCapture

All Superinterfaces:
Capture<LivePacket>, java.io.Closeable

public interface LiveCapture
extends Capture<LivePacket>, java.io.Closeable

A network packet cature on a live network interface. To obtain an instance of a class implementing this interface, use one of the CaptureFactory.openLive() methods which open up a network interface live capture.

 LiveCapture capture = CaptureFactory.openLive();
 
 while (capture.hasNext()) {
   CapturePacket packet = capture.next(); 
   // Do something with the packet now
 }
 

Author:
Mark Bednarczyk, Sly Technologies, Inc.

Nested Class Summary
static class LiveCapture.Option
          Options which can be set on open captures.
 
Field Summary
static LiveCapture.Option DEFAULT_CAPTURE_OPTION
          The default option when none are specified by the user.
 
Method Summary
 CaptureInterface[] interfaceSnapshot()
          Takes a snapshot of all the CaptureInterface configurations currently open for live capture.
 CaptureInterface[] interfaceSnapshot(CaptureInterface... currentInterface)
          Takes a snapshot of supplied CaptureInterface configurations currently open for live capture.
 CaptureInterface setFilter(Filter filter, CaptureInterface currentInterface)
          Sets a new filter for currently open CaptureInterface.
 
Methods inherited from interface jnetpcap.capture.Capture
close, getFilter, getMutableCapture, getRemoteSession, isCaptureMutable, isCaptureRemote, setFilter
 

Field Detail

DEFAULT_CAPTURE_OPTION

static final LiveCapture.Option DEFAULT_CAPTURE_OPTION
The default option when none are specified by the user.

Method Detail

setFilter

CaptureInterface setFilter(Filter filter,
                           CaptureInterface currentInterface)
                           throws java.io.IOException

Sets a new filter for currently open CaptureInterface. CaptureInterfaces, once opened for live network capture are frozen and made immutable. This allows previously captured packets that reference a CaptureInterface they were captured on, to contain exact configuration state as the time the packet was captured. In order to apply a new filter, a copy is made of the currentInterface and the new user filter applied to the clone of the currentInterface. From this time on, any new packets captured on this interface, will reference the new CaptureInterface object with new filter and any new interface config changes such as well.

Note that no changes to the config of the supplied currentInterface object are made. All changes are made to the new instance of CaptureInterface returned.

Parameters:
filter - new filter to appy to the current interface
currentInterface - current interface the filter should be applied to
Returns:
new instance, essentially a copy of the user supplied currentInterface, that has the filter applied.
Throws:
java.io.IOException

interfaceSnapshot

CaptureInterface[] interfaceSnapshot()
                                     throws java.io.IOException
Takes a snapshot of all the CaptureInterface configurations currently open for live capture. New CaptureInterface objects are created for every open CaptureInterface currently open. Some information is copied from the old instances. This method allows, essentially, a snapshot of the physical network interface configuration to be made. This method is useful if you know that network interface configuration has changed and that you would like to make sure this change is reflected, as returned by packets that are being captured on this interface.

Returns:
old CaptureInterfaces that are being replaced by this new snapshot
Throws:
java.io.IOException - any IO errors

interfaceSnapshot

CaptureInterface[] interfaceSnapshot(CaptureInterface... currentInterface)
                                     throws java.io.IOException
Takes a snapshot of supplied CaptureInterface configurations currently open for live capture. New CaptureInterface objects are created for every open CaptureInterface currently open. Some information is copied from the old instances. This method allows, essentially, a snapshot of the physical network interface configuration to be made. This method is useful if you know that network interface configuration has changed and that you would like to make sure this change is reflected, as returned by packets that are being captured on this interface.

Parameters:
currentInterface - current open capture interfaces active in this capture session
Returns:
the new capture interfaces that were created
Throws:
java.io.IOException - any IO errors or if any of the specified CaptureInterfaces do not exist