org.jnetpcap
Interface PcapHandler<T>

Type Parameters:
T - user object type

public interface PcapHandler<T>

A handler, listener or call back inteface that gets notified when a new packet has been captured.

Author:
Mark Bednarczyk, Sly Technologies, Inc.

Method Summary
 void nextPacket(T user, long seconds, int useconds, int caplen, int len, java.nio.ByteBuffer buffer)
          Method gets called when a packet is available as dispatched by Libpcap dispatch or loop calls.
 

Method Detail

nextPacket

void nextPacket(T user,
                long seconds,
                int useconds,
                int caplen,
                int len,
                java.nio.ByteBuffer buffer)
Method gets called when a packet is available as dispatched by Libpcap dispatch or loop calls. The typical struct pcap_pkthdr structure is decoded in JNI and passed in as java primitives. The supplied buffer contains the captured packet data. The buffer is initialized as follows. The position property is set to the start of the packet data and limit is set to 1 byte passed the end of the packet. The difference between limit and position properties will equal exactly caplen. The buffer is reused for each packet. Libpcap is initialized with a custom capture buffer that backs the ByteBuffer, only is position and limit properties are adjusted. The buffer may wrap around and start from the start as determined by libpcap itself. Also the buffer is read-only and the data is not mutable. Packet data is not copied into the buffer, but written to directly by the kernel. This ensures that data is only written once into the buffer and then returned to java envioronment.

Parameters:
user - user supplied object to dispatch or loop calls
seconds - timestamp
useconds - timestamp
caplen - amount of data captured
len - original packet length as seen on the network
buffer - buffer containing the packet data.