net.sourceforge.jpcap.capture
Class PacketCaptureBase

java.lang.Object
  extended bynet.sourceforge.jpcap.capture.PacketDispatcher
      extended bynet.sourceforge.jpcap.capture.PacketCaptureBase
All Implemented Interfaces:
PacketDispatchCapable, net.sourceforge.jpcap.capture.PacketHandler
Direct Known Subclasses:
PacketCapture, PacketCaptureSimulator

public abstract class PacketCaptureBase
extends PacketDispatcher
implements net.sourceforge.jpcap.capture.PacketHandler

This class contains base functionality shared by both the simulator and the actual packet capture system.

Regardless of whether 'real' packets are being captured off a network or 'fake' packets are being generated by the simulator, the packet dispatch logic is the same.

This class is abstract because it is useless standalone. The packet capture system which inherits from this class must provide a way of feeding data to handlePacket() where it is then dispatched to listeners.


Field Summary
 int droppedCount
           
 int linkType
          The link-type code for the currently open network device.
 int receivedCount
           
 
Constructor Summary
PacketCaptureBase()
           
 
Method Summary
 void handlePacket(int length, int caplen, int seconds, int useconds, byte[] data)
          Handle arriving packets.
 
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
 

Field Detail

linkType

public int linkType
The link-type code for the currently open network device. The type is queried and set in open() and then utilized when packets are received by handlePacket().


receivedCount

public int receivedCount

droppedCount

public int droppedCount
Constructor Detail

PacketCaptureBase

public PacketCaptureBase()
Method Detail

handlePacket

public void handlePacket(int length,
                         int caplen,
                         int seconds,
                         int useconds,
                         byte[] data)
Handle arriving packets.

Arriving packets are dispatched to registered packet listeners. If caplen is smaller than length, then the packet was truncated because the amount of data on the wire exceeded the snapshot length specified when open() was called.

In the simulator case, fake packets are generated and this method called with the fabricated data. In the case of the capture system, the native library libjpcap calls the method back.

Specified by:
handlePacket in interface net.sourceforge.jpcap.capture.PacketHandler
Parameters:
length - the length of the packet off of the wire.
caplen - the number of bytes actually captured.
seconds - the seconds component of the timestamp.
useconds - the microseconds component of the timestamp.
data - the contents of the captured packet.