net.sourceforge.jpcap.capture
Class SyncPacketCapture

java.lang.Object
  |
  +--net.sourceforge.jpcap.capture.PacketDispatcher
        |
        +--net.sourceforge.jpcap.capture.PacketCaptureBase
              |
              +--net.sourceforge.jpcap.capture.PacketCapture
                    |
                    +--net.sourceforge.jpcap.capture.SyncPacketCapture
All Implemented Interfaces:
PacketCaptureCapable, PacketDispatchCapable, net.sourceforge.jpcap.capture.PacketHandler

public class SyncPacketCapture
extends PacketCapture

This class adds to PacketCapture the ability to explicitly terminate a capture session using close().

SyncPacketCapture utilizes libpcap's pcap_dispatch().

SyncPacketCapture inherits from the PacketCapture overriding its open(), capture() and close() methods in a way to keep synchronized the starting and the stopping phases of any capture() session . That allows close() method call to be performed any time from everywhere.


Fields inherited from class net.sourceforge.jpcap.capture.PacketCapture
LIB_PCAP_WRAPPER
 
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
SyncPacketCapture()
           
 
Method Summary
 void capture(int pck_count)
          Capture packets.
 void close()
          Close cleans up after a packet capture session.
protected  void syncCapture(int pck_count)
           
 
Methods inherited from class net.sourceforge.jpcap.capture.PacketCapture
findDevice, getLinkLayerType, getNetmask, getNetwork, getSnapshotLength, getStatistics, lookupDevices, open, open, openOffline, setFilter
 
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
 

Constructor Detail

SyncPacketCapture

public SyncPacketCapture()
Method Detail

syncCapture

protected void syncCapture(int pck_count)
                    throws CapturePacketException

capture

public void capture(int pck_count)
             throws CapturePacketException
Description copied from interface: PacketCaptureCapable
Capture packets.
Overrides:
capture in class PacketCapture
Following copied from interface: net.sourceforge.jpcap.capture.PacketCaptureCapable
Parameters:
count - the number of packets to capture. If count is negative, capture will block forever, unless an exception is thrown.

close

public void close()
Description copied from class: PacketCapture
Close cleans up after a packet capture session. It does _not_ terminate a packet capture. capture() does not return control until 'count' packets are captured.

If you are looking for a way to signal an end to a capture session before a set number of packets are received, check out the class SyncPacketCapture.

Overrides:
close in class PacketCapture