org.jnetpcap
Class PcapUtils

java.lang.Object
  extended by org.jnetpcap.PcapUtils

public final class PcapUtils
extends java.lang.Object

A Pcap utility class which provides certain additional and convenience methods.

Since:
1.2
Author:
Mark Bednarczyk, Sly Technologies, Inc.

Method Summary
static
<T> PcapTask<T>
dispatchInBackground(Pcap pcap, int cnt, ByteBufferHandler<T> handler, T data)
          Runs the dispatch function in a background thread.
static
<T> PcapTask<T>
dispatchInBackground(Pcap pcap, int cnt, JBufferHandler<T> handler, T data)
          Runs the dispatch function in a background thread.
static byte[] getHardwareAddress(PcapIf netif)
          Retrieves a network hardware address or MAC for a network interface
static byte[] getHardwareAddress(java.lang.String device)
          Retrieves a network hardware address or MAC for a network interface
static
<T> PcapTask<T>
loopInBackground(Pcap pcap, int cnt, ByteBufferHandler<T> handler, T data)
          Runs the loop function in a background thread.
static
<T> PcapTask<T>
loopInBackground(Pcap pcap, int cnt, JBufferHandler<T> handler, T data)
          Runs the loop function in a background thread.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

dispatchInBackground

public static <T> PcapTask<T> dispatchInBackground(Pcap pcap,
                                                   int cnt,
                                                   ByteBufferHandler<T> handler,
                                                   T data)
Runs the dispatch function in a background thread. The function returns immediately and returns a PcapTask from which the user can interact with the background task.

Parameters:
pcap - an open pcap object
cnt - number of packets to capture and exit, 0 for infinate
handler - user supplied callback handler
data - opaque, user supplied data object dispatched back to the handler
Returns:
a task object which allows interaction with the underlying capture loop and thread

dispatchInBackground

public static <T> PcapTask<T> dispatchInBackground(Pcap pcap,
                                                   int cnt,
                                                   JBufferHandler<T> handler,
                                                   T data)
Runs the dispatch function in a background thread. The function returns immediately and returns a PcapTask from which the user can interact with the background task.

Parameters:
pcap - an open pcap object
cnt - number of packets to capture and exit, 0 for infinate
handler - user supplied callback handler
data - opaque, user supplied data object dispatched back to the handler
Returns:
a task object which allows interaction with the underlying capture loop and thread

getHardwareAddress

public static byte[] getHardwareAddress(PcapIf netif)
                                 throws java.io.IOException
Retrieves a network hardware address or MAC for a network interface

Parameters:
netif - network device as retrieved from Pcap.findAllDevs().
Returns:
network interface hardware address or null if unable to retrieve it
Throws:
java.io.IOException - any communication errors
See Also:
Pcap.findAllDevs(List, StringBuilder)

getHardwareAddress

public static byte[] getHardwareAddress(java.lang.String device)
                                 throws java.io.IOException
Retrieves a network hardware address or MAC for a network interface

Parameters:
device - network interface name
Returns:
network interface hardware address or null if unable to retrieve it
Throws:
java.io.IOException - any communication errors

loopInBackground

public static <T> PcapTask<T> loopInBackground(Pcap pcap,
                                               int cnt,
                                               ByteBufferHandler<T> handler,
                                               T data)
Runs the loop function in a background thread. The function returns immediately and returns a PcapTask from which the user can interact with the background task.

Parameters:
pcap - an open pcap object
cnt - number of packets to capture and exit, 0 for infinate
handler - user supplied callback handler
data - opaque, user supplied data object dispatched back to the handler
Returns:
a task object which allows interaction with the underlying capture loop and thread

loopInBackground

public static <T> PcapTask<T> loopInBackground(Pcap pcap,
                                               int cnt,
                                               JBufferHandler<T> handler,
                                               T data)
Runs the loop function in a background thread. The function returns immediately and returns a PcapTask from which the user can interact with the background task.

Parameters:
pcap - an open pcap object
cnt - number of packets to capture and exit, 0 for infinate
handler - user supplied callback handler
data - opaque, user supplied data object dispatched back to the handler
Returns:
a task object which allows interaction with the underlying capture loop and thread