src/org/jnetpcap/Pcap.java
public <T> int loop(int cnt,
			PcapPacketHandler<T> handler,
			T user,
			JScanner scanner) {
		final PcapPacket packet = new PcapPacket(Type.POINTER);
		return loop(cnt,
				datalinkToId(),
				handler,
				user,
				packet,
				packet.getState(),
				packet.getCaptureHeader(),
				scanner);
	}
/**
	 * Collect a group of packets. pcap_loop() is similar to pcap_dispatch()
	 * except it keeps reading packets until cnt packets are processed or an error
	 * occurs. It does not return when live read timeouts occur. Rather,
	 * specifying a non-zero read timeout to pcap_open_live() and then calling
	 * pcap_dispatch() allows the reception and processing of any packets that
	 * arrive when the timeout occurs. A negative cnt causes pcap_loop() to loop
	 * forever (or at least until an error occurs). -1 is returned on an error; 0
	 * is returned if cnt is exhausted; -2 is returned if the loop terminated due
	 * to a call to pcap_breakloop() before any packets were processed. If your
	 * application uses pcap_breakloop(), make sure that you explicitly check for
	 * -1 and -2, rather than just checking for a return value < 0.
	 * <p>
	 * This implementation of disptach method performs a scan of the packet buffer
	 * as it is delivered by libpcap. The scanned information is recorded in
	 * native scanner structures which are then peered with a JPacket object
	 * instance. The receiver of the dispatched packets
	 * <code>JPacketHandler.nextPacket</code> receives fully decoded packets.
	 * </p>
	 * <p>
	 * This method provides its own thread-local <code>JScanner</code> and default
	 * shared <code>JPacket</code> instance. The same packet is dispatched to the
	 * user with the state of the packet being changed between each dispatch. If
	 * the user requires the packet state to persist longer than a single
	 * iteration of the dispatcher, the delivered packets state must either be
	 * peered with a different packet (only copied by reference) or the entire
	 * contents and state must be copied to a new packet (a deep copy). The
	 * shallow copy by reference persists longer, but not indefinately. It persist
	 * as long as libpcap internal large capture buffer doesn't wrap around. The
	 * same goes for JScanner's internal scan buffer, it too persists until the
	 * state information exhausts the buffer and the buffer is wrapped around to
	 * the begining as well overriding any information in the scan buffer. If
	 * there are still any packets that reference that scan buffer information,
	 * once that information is overriden by the latest scan, the original scan
	 * information is gone forever and will guarrantee that any old packets still
	 * pointing at the scan buffer will have incorrect infromation.
	 * </p>
	 * <p>
	 * <code>JPacket</code> class provides methods which allow deep copy of the
	 * packet data and state to be made to a new permanent location. This
	 * mechanism works in conjuction of <code>JMemoryPool</code> class which
	 * facilitates native memory management on large scale. Once the packet data
	 * and state are deep copied to new memory location, that packet can stay
	 * permanently in memory. The memory will only be released when all the java
	 * object references to that memory are garbage collected. The memory is
	 * deallocated automatically.
	 * </p>
	 * 
	 * @param <T>
	 *          user data type
	 * @param cnt
	 *          number of packets to process
	 * @param handler
	 *          user supplied packet handler
	 * @param user
	 *          a custom opaque user object
	 * @param scanner
	 *          user supplied custom packet scanner
	 * @return 0 on success, -1 on error and -2 if breakloop was used interrupt
	 *         the captue
	 */
Collect a group of packets. pcap_loop() is similar to pcap_dispatch()
except it keeps reading packets until cnt packets are processed or an error
occurs. It does not return when live read timeouts occur. Rather,
specifying a non-zero read timeout to pcap_open_live() and then calling
pcap_dispatch() allows the reception and processing of any packets that
arrive when the timeout occurs. A negative cnt causes pcap_loop() to loop
forever (or at least until an error occurs). -1 is returned on an error; 0
is returned if cnt is exhausted; -2 is returned if the loop terminated due
to a call to pcap_breakloop() before any packets were processed. If your
application uses pcap_breakloop(), make sure that you explicitly check for
-1 and -2, rather than just checking for a return value < 0.

This implementation of disptach method performs a scan of the packet buffer
as it is delivered by libpcap. The scanned information is recorded in
native scanner structures which are then peered with a JPacket object
instance. The receiver of the dispatched packets
JPacketHandler.nextPacket receives fully decoded packets.


This method provides its own thread-local JScanner and default
shared JPacket instance. The same packet is dispatched to the
user with the state of the packet being changed between each dispatch. If
the user requires the packet state to persist longer than a single
iteration of the dispatcher, the delivered packets state must either be
peered with a different packet (only copied by reference) or the entire
contents and state must be copied to a new packet (a deep copy). The
shallow copy by reference persists longer, but not indefinately. It persist
as long as libpcap internal large capture buffer doesn't wrap around. The
same goes for JScanner's internal scan buffer, it too persists until the
state information exhausts the buffer and the buffer is wrapped around to
the begining as well overriding any information in the scan buffer. If
there are still any packets that reference that scan buffer information,
once that information is overriden by the latest scan, the original scan
information is gone forever and will guarrantee that any old packets still
pointing at the scan buffer will have incorrect infromation.


JPacket class provides methods which allow deep copy of the
packet data and state to be made to a new permanent location. This
mechanism works in conjuction of JMemoryPool class which
facilitates native memory management on large scale. Once the packet data
and state are deep copied to new memory location, that packet can stay
permanently in memory. The memory will only be released when all the java
object references to that memory are garbage collected. The memory is
deallocated automatically.


Collect a group of packets . pcap_loop () is similar to pcap_dispatch () except it keeps reading packets until cnt packets are processed or an error occurs . It does not return when live read timeouts occur . Rather specifying a non - zero read timeout to pcap_open_live () and then calling pcap_dispatch () allows the reception and processing of any packets that arrive when the timeout occurs . A negative cnt causes pcap_loop () to loop forever ( or at least until an error occurs ) . - 1 is returned on an error ; 0 is returned if cnt is exhausted ; - 2 is returned if the loop terminated due to a call to pcap_breakloop () before any packets were processed . If your application uses pcap_breakloop () make sure that you explicitly check for - 1 and - 2 rather than just checking for a return value < 0 . This implementation of disptach method performs a scan of the packet buffer as it is delivered by libpcap . The scanned information is recorded in native scanner structures which are then peered with a JPacket object instance . The receiver of the dispatched packets JPacketHandler . nextPacket receives fully decoded packets . This method provides its own thread - local JScanner and default shared JPacket instance . The same packet is dispatched to the user with the state of the packet being changed between each dispatch . If the user requires the packet state to persist longer than a single iteration of the dispatcher the delivered packets state must either be peered with a different packet ( only copied by reference ) or the entire contents and state must be copied to a new packet ( a deep copy ) . The shallow copy by reference persists longer but not indefinately . It persist as long as libpcap internal large capture buffer doesn ' t wrap around . The same goes for JScanner ' s internal scan buffer it too persists until the state information exhausts the buffer and the buffer is wrapped around to the begining as well overriding any information in the scan buffer . If there are still any packets that reference that scan buffer information once that information is overriden by the latest scan the original scan information is gone forever and will guarrantee that any old packets still pointing at the scan buffer will have incorrect infromation . JPacket class provides methods which allow deep copy of the packet data and state to be made to a new permanent location . This mechanism works in conjuction of JMemoryPool class which facilitates native memory management on large scale . Once the packet data and state are deep copied to new memory location that packet can stay permanently in memory . The memory will only be released when all the java object references to that memory are garbage collected . The memory is deallocated automatically .
public <T> int loop(int cnt,
			PcapPacketHandler<T> handler,
			T user,
			JScanner scanner) {
		final PcapPacket packet = new PcapPacket(Type.POINTER);
		return loop(cnt,
				datalinkToId(),
				handler,
				user,
				packet,
				packet.getState(),
				packet.getCaptureHeader(),
				scanner);
	}
public < T > int loop ( int cnt , PcapPacketHandler < T > handler , T user , JScanner scanner ) { final PcapPacket packet = new PcapPacket ( Type . POINTER ) ; return loop ( cnt , datalinkToId ( ) , handler , user , packet , packet . getState ( ) , packet . getCaptureHeader ( ) , scanner ) ; }
Collect a group of packets.
Collect a group of packets .