|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.jnetpcap.Pcap
public class Pcap
This class is the main class peered with native pcap_t
structure in libpcap and winpcap library impelementations. It provides a
direct mapping of various library methods from Java.
Pcap
class provides several static methods which allow
discovery of networking interfaces and then subsequently open up either
openLive
, openDead
or openOffline
pcap capture sessions. In all 3 cases a Pcap
object is
returned. The object is backed by a C pcap_t
structure outside
of java VM address space. Any non-static operations on the Pcap
object, are translated using java JNI API into corresponding Libpcap C calls
and the appropriate pcap_t
C structure is supplied to complete
the call.
After aquiring a Pcap
object from above mentioned static
methods, you must call on close()
call to release any Libpcap
resources and the backing C structure. The Pcap
object does
implicitly call the close()
method from its finalize()
method,
but that will only happen when the Pcap
is garabage collected.
Its best practice to remember to always call on close()
when
Pcap
object and capture session is no longer needed.
If Pcap
object is closed and any of its non-static methods are
called on, after the close, IllegalStateException
will be thrown.
StringBuilder errbuf = new StringBuilder(); List<PcapIf> ifs = new ArrayList<PcapIf>(); // Will hold list of devices int statusCode = Pcap.findAllDevs(ifs, errbuf); if (statusCode != Pcap.OK) { System.out.println("Error occured: " + errbuf.toString()); return; } // We have a list of PcapIf devices to work with now.
Note: the return value from findAllDevs(java.util.List
is an integer result
code, just like in the C counter part. The ifs
list is filled
in with all the network devices as found from the corresponding C structure
pcap_if
linked list returned from the C function call
findAllDevs.
Now that we have a list of devices, we we print out the list of them and ask the user to pick one to open for capture:
for (int i = 0; i < ifs.size(); i++) { System.out.println("#" + i + ": " + ifs.get(i).getName()); } String l = System.in.readline().trim(); Integer i = Integer.valueOf(l); PcapIf netInterface = ifs.get(i);
openLive(String, int, int, int, StringBuilder)
:
int snalen = 2048; // Truncate packet at this size int promiscous = Pcap.MODE_PROMISCUOUS; int timeout = 60 * 1000; // In milliseconds Pcap pcap = Pcap.openLive(netInterface.getName(), snaplen, promiscous, timeout, errbuf);Last argument is a buffer that will hold an error string, if error occures. On error
openLive
will return null.
PcapBpfProgram filter = new PcapBpfProgram(); String expression = "port 23" int optimize = 0; // 1 means true, 0 means false int netmask = 0; int r = pcap.compile(filter, expression, optimize, netmask); if (r != Pcap.OK) { System.out.println("Filter error: " + pcap.getErr()); } pcap.setFilter(filter);
If filter expression contained a syntax error, the return code will be -1 and
exact error message can be retrieved using getErr()
method.
Note of caution: the PcapBpfProgram
at the top of the
previous code section, can not be accessed until successfully filled in with
values in the pcap.compile
code. If you try and access any of
its methods an IllegalStateException
will be thrown. Only
after a successful call to compile
does the object become
usable. The object is peered with C structure and until properly intialized,
can not be accessed from java.
PcapHandler handler = new PcapHandler() { public void newPacket(Object userData, int caplen, int len, int seconds, int usecs, ByteBuffer buffer) { PrintStream out = (PrintStream) userData; out.println("Packet captured on: " + new Date(seconds * 1000).toString()); } }; int cnt = 10; // Capture packet count PrintStream out = System.out; // Our custom object to send into the handler pcap.loop(cnt, handler, out); // Each packet will be dispatched to the handler pcap.close();
This sets up PCAP to capture 10 packets and notify our handler of each packet as each one is captured. Then after 10 packets the loop exits and we call pcap.close() to free up all the resources and we can safely throw away our pcap object. Also you may be curious why we pass System.out as userData to the loop handler. This is simply to demonstrate the typical usage for this kind of parameter. In our case we could easily pass a different PrintStream bound to lets say a network socket and our handler would produce output to it.
Alternative way of capturing packets from any of the open pcap sessions is to
use dispatch(int, PcapHandler, Object)
method, which works very
similarly to loop(int, PcapHandler, Object)
. You can also use
next(PcapPktHdr)
and nextEx(PcapPktHdr, PcapPktBuffer)
methods which will deliver 1 packet at a time.
The packet data is delivered in a java.nio.ByteBuffer
. The
data is not copied into the buffer, but a direct byte buffer is allocated and
wrapped around the packet data as returned from libpcap. No in memory copies
are performed, so if the native operating system supports no-copy packet
captures, the packet are delived to Java without copies. Only a single
ByteBuffer object allocation is incured.
lookupDev
, lookupNet
. Also any methods that
return FILE *
since that is not appropriate for java
environment.
Field Summary | |
---|---|
static int |
DISPATCH_BUFFER_FULL
Value of packet count argument for dispatch method call
which indicates that only as many packets should be returned as will fit in
a single buffer , unless an error occured or breakloop call
was used to interrupt the dispatcher. |
static java.lang.String |
JNETPCAP_LIBRARY_NAME
Name of the native library that wraps around libpcap and extensions |
static int |
LOOP_INFINATE
Value of packet count argument for loop method call which
indicates that the loop should never exit, unless an error occured or
breakloop call was used to interrupt the dispatcher. |
static int |
LOOP_INTERRUPTED
Pcap status return code for loop and dispatch
methods. |
static int |
MODE_BLOCKING
Flag which can be used with setNonBlock method to set the
previously opened pcap descriptor into 'blocking' mode. |
static int |
MODE_NON_BLOCKING
Flag which can be used with setNonBlock method to set the
previously opened pcap descriptor into 'non-blocking' mode. |
static int |
MODE_NON_PROMISCUOUS
Flag used with openLive to specify that the interface should
not be put into promisuous mode, but only if poassible. |
static int |
MODE_PROMISCUOUS
Flag used with openLive to specify that the interface should
be put into promisuous mode. |
static int |
NEXT_EX_EOF
Exit code for nextEx method which indicates that pcap
reached end of file while reading a 'savefile'. |
static int |
NEXT_EX_NOT_OK
Exit code for nextEx method which indicates failure of some
kind. |
static int |
NEXT_EX_OK
Exit code for nextEx method which indicates success. |
static int |
NEXT_EX_TIMEDOUT
Exit code for nextEx method which indicates timeout has
expired before a packet was captured. |
static int |
NOT_OK
Pcap status return code for most of the methods defined here. |
static int |
OK
Pcap status return code for most of the methods defined here. |
Constructor Summary | |
---|---|
Pcap()
Pcap object can only be created by calling one of the static openLive(java.lang.String, int, int, int, java.lang.StringBuilder) methods. |
Method Summary | ||
---|---|---|
void |
breakloop()
set a flag that will force pcap_dispatch() or pcap_loop() to return rather than looping. |
|
protected void |
checkIsActive()
Checks if the current Pcap structure is active and open. |
|
void |
close()
pcap_close() closes the files associated with p and deallocates resources. |
|
int |
compile(PcapBpfProgram program,
java.lang.String str,
int optimize,
int netmask)
Compile a packet filter, converting a high level filtering expression in to a progra that can be interpreted by the kernel-level filtering engine. |
|
static int |
compileNoPcap(int snaplen,
int dlt,
PcapBpfProgram program,
java.lang.String str,
int optimize,
int netmask)
Compile a packet filter without the need of opening an adapter. |
|
int |
datalink()
Returns the link layer of an adapter. |
|
static int |
datalinkNameToVal(java.lang.String name)
Translates a data link type name, which is a DLT_ name with the DLT_ removed, to the corresponding data link type value. |
|
static java.lang.String |
datalinkValToDescription(int dlt)
Translates a data link type value to a short description of that data link type. |
|
static java.lang.String |
datalinkValToName(int dlt)
Translates a data link type value to the corresponding data link type name. |
|
|
dispatch(int cnt,
PcapHandler<T> handler,
T user)
Collect a group of packets. |
|
PcapDumper |
dumpOpen(java.lang.String fname)
Open a file to write packets. |
|
protected void |
finalize()
Cleanup before we're GCed. |
|
static int |
findAllDevs(java.util.List<PcapIf> alldevs,
java.lang.StringBuilder errbuf)
pcap_findalldevs() constructs a list of network devices that can be opened with pcap_open_live(). |
|
static void |
freeAllDevs(java.util.List<PcapIf> alldevs,
byte[] errbuf)
This method does nothing. |
|
static void |
freecode(PcapBpfProgram program)
This frees up the code structures, but does not released the peered base bpf_program peer structure. |
|
java.lang.String |
getErr()
return the error text pertaining to the last pcap library error. |
|
int |
getNonBlock(java.lang.StringBuilder errbuf)
pcap_getnonblock() returns the current ``non-blocking'' state of the capture descriptor; it always returns 0 on ``savefiles''. |
|
int |
inject(byte[] buf)
This method allows to send a raw packet to the network. |
|
int |
inject(byte[] buf,
int offset,
int length)
This method allows to send a raw packet to the network. |
|
int |
inject(java.nio.ByteBuffer buf)
This method allows to send a raw packet to the network. |
|
static boolean |
isInjectSupported()
Checks if the current platform has support for pcap_inject call. |
|
static boolean |
isSendPacketSupported()
Checks if the current platform has support for pcap_sendpacket call. |
|
int |
isSwapped()
returns true if the current savefile uses a different byte order than the current system |
|
static java.lang.String |
libVersion()
Returns a pointer to a string giving information about the version of the libpcap library being used; note that it contains more information than just a version number |
|
static java.lang.String |
lookupDev(java.lang.StringBuilder errbuf)
Returns a network device suitable for use with openLive and
lookupNet . |
|
static int |
lookupNet(java.lang.String device,
PcapInteger netp,
PcapInteger maskp,
java.lang.StringBuilder errbuf)
Determines the network number and mask associated with the network device. |
|
|
loop(int cnt,
PcapHandler<T> handler,
T user)
Collect a group of packets. |
|
int |
majorVersion()
Return the major version number of the pcap library used to write the savefile. |
|
int |
minorVersion()
Return the minor version number of the pcap library used to write the savefile. |
|
java.nio.ByteBuffer |
next(PcapPktHdr pkt_header)
Return the next available packet. |
|
int |
nextEx(PcapPktHdr pkt_header,
PcapPktBuffer buffer)
Read a packet from an interface or from an offline capture. |
|
static Pcap |
openDead(int linktype,
int snaplen)
Create a pcap_t structure without starting a capture. |
|
static Pcap |
openLive(java.lang.String device,
int snaplen,
int promisc,
int timeout,
java.lang.StringBuilder errbuf)
Open a live capture associated with the specified network interface device. |
|
static Pcap |
openOffline(java.lang.String fname,
java.lang.StringBuilder errbuf)
Open a savefile in the tcpdump/libpcap format to read packets. |
|
int |
sendPacket(byte[] buf)
This method allows to send a raw packet to the network. |
|
int |
sendPacket(byte[] buf,
int offset,
int length)
This method allows to send a raw packet to the network. |
|
int |
sendPacket(java.nio.ByteBuffer buf)
This method allows to send a raw packet to the network. |
|
int |
setDatalink(int dlt)
Set the current data link type of the pcap descriptor to the type specified by dlt. |
|
int |
setFilter(PcapBpfProgram program)
Associate a filter to a capture. |
|
int |
setNonBlock(int nonBlock,
java.lang.StringBuilder errbuf)
pcap_setnonblock() puts a capture descriptor, opened with pcap_open_live(), into ``non-blocking'' mode, or takes it out of ``non-blocking'' mode, depending on whether the nonblock argument is non-zero or zero. |
|
int |
snapshot()
Return the dimension of the packet portion (in bytes) that is delivered to the application. |
|
int |
stats(PcapStat stats)
Returns statistics on the current capture. |
|
java.lang.String |
toString()
Prints libVersion that Pcap is based on. |
Methods inherited from class java.lang.Object |
---|
clone, equals, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Field Detail |
---|
public static final int DISPATCH_BUFFER_FULL
dispatch
method call
which indicates that only as many packets should be returned as will fit in
a single buffer , unless an error occured or breakloop
call
was used to interrupt the dispatcher. Note, that this constant is only
appropriate value for dispatch
method call. Loop method uses
LOOP_INFINATE for something similar, but definately not identical to this
option.
public static final java.lang.String JNETPCAP_LIBRARY_NAME
public static final int LOOP_INFINATE
loop
method call which
indicates that the loop should never exit, unless an error occured or
breakloop
call was used to interrupt the dispatcher. Note,
that this constant is not appropriate value for dispatch
method call, which has a different meaning.
public static final int LOOP_INTERRUPTED
loop
and dispatch
methods. This status code indicates that the the dispatcher was interrupted
by a call to breakloop
call.
public static final int MODE_BLOCKING
setNonBlock
method to set the
previously opened pcap descriptor into 'blocking' mode. The flag can also
be the return code from getNonBlock
. The flag has no affect
on 'savefiles'.
public static final int MODE_NON_BLOCKING
setNonBlock
method to set the
previously opened pcap descriptor into 'non-blocking' mode. The flag can
also be the return code from getNonBlock
. The flag has no
affect on 'savefiles'.
public static final int MODE_NON_PROMISCUOUS
openLive
to specify that the interface should
not be put into promisuous mode, but only if poassible. Note, the even
though the flag is specified, the interface could still be opened in
promiscous mode for other reasons, such as a different process had already
put the interface into promiscuous mode.
public static final int MODE_PROMISCUOUS
openLive
to specify that the interface should
be put into promisuous mode.
public static final int NEXT_EX_EOF
nextEx
method which indicates that pcap
reached end of file while reading a 'savefile'.
public static final int NEXT_EX_NOT_OK
nextEx
method which indicates failure of some
kind. Use getErr()
to retrieve the error message.
public static final int NEXT_EX_OK
nextEx
method which indicates success.
public static final int NEXT_EX_TIMEDOUT
nextEx
method which indicates timeout has
expired before a packet was captured. The packet header and packet buffer
do no point to any valid data.
public static final int NOT_OK
public static final int OK
Constructor Detail |
---|
public Pcap()
openLive(java.lang.String, int, int, int, java.lang.StringBuilder)
methods.
Method Detail |
---|
public static int compileNoPcap(int snaplen, int dlt, PcapBpfProgram program, java.lang.String str, int optimize, int netmask)
Compile a packet filter without the need of opening an adapter. This function converts an high level filtering expression (see Filtering expression syntax) in a program that can be interpreted by the kernel-level filtering engine.
pcap_compile_nopcap() is similar to pcap_compile() except that instead of passing a pcap structure, one passes the snaplen and linktype explicitly. It is intended to be used for compiling filters for direct BPF usage, without necessarily having called pcap_open(). (pcap_compile_nopcap() is a wrapper around pcap_open_dead(), pcap_compile(), and pcap_close(); the latter three routines can be used directly in order to get the error text for a compilation error.)
Look at the Filtering expression syntax section for details on the str parameter.
snaplen
- generate code to truncate packets to this length upon a matchdlt
- the first header type within the packet, or data link type of the
interfaceprogram
- initially empty, but after the method call will contain the
compiled BPF programstr
- a string containing the textual expression to be compiledoptimize
- 1 means to do optimizations, any other value means nonetmask
- netmask needed to determine the broadcast address
public static int datalinkNameToVal(java.lang.String name)
name
- data link type name
public static java.lang.String datalinkValToDescription(int dlt)
dlt
- data link type value
public static java.lang.String datalinkValToName(int dlt)
dlt
- data link type value
public static int findAllDevs(java.util.List<PcapIf> alldevs, java.lang.StringBuilder errbuf)
alldevs
- the list is filled in with PcapIf
interface
objects; the list must not be immutableerrbuf
- error buffer containing error message as a string on failure
public static void freeAllDevs(java.util.List<PcapIf> alldevs, byte[] errbuf)
alldevs
- is set to point to the first element of the list; each element of
the list is of type PcapIferrbuf
- error buffer containing error message as a string on failurepublic static void freecode(PcapBpfProgram program)
program
- program to free up the backend resources forpublic static boolean isInjectSupported()
inject(byte[])
is supported, otherwise notinject(byte[])
public static boolean isSendPacketSupported()
sendPacket(byte[])
is supported, otherwise notinject(byte[])
public static java.lang.String libVersion()
public static java.lang.String lookupDev(java.lang.StringBuilder errbuf)
openLive
and
lookupNet
.
errbuf
- if there is an error, errbuf is filled with appropriate message
public static int lookupNet(java.lang.String device, PcapInteger netp, PcapInteger maskp, java.lang.StringBuilder errbuf)
Note: this method is deprecated in pcap as it can not be used to pass back information about IP v6 addresses.
device
- device to do the lookup onnetp
- object which will contain the value of network addressmaskp
- object which will contain the value of network netmaskerrbuf
- any error messages if return value is -1
public static Pcap openDead(int linktype, int snaplen)
linktype
- pcap DLT link type integer valuesnaplen
- filters generated using the pcap structure will truncate captured
packets to this length
public static Pcap openLive(java.lang.String device, int snaplen, int promisc, int timeout, java.lang.StringBuilder errbuf)
Open a live capture associated with the specified network interface device. pcap_open_live() is used to obtain a packet capture descriptor to look at packets on the network. device is a string that specifies the network device to open; on Linux systems with 2.2 or later kernels, a device argument of "any" or NULL can be used to capture packets from all interfaces. snaplen specifies the maximum number of bytes to capture. If this value is less than the size of a packet that is captured, only the first snaplen bytes of that packet will be captured and provided as packet data. A value of 65535 should be sufficient, on most if not all networks, to capture all the data available from the packet. promisc specifies if the interface is to be put into promiscuous mode. (Note that even if this parameter is false, the interface could well be in promiscuous mode for some other reason.)
For now, this doesn't work on the "any" device; if an argument of "any" or NULL is supplied, the promisc flag is ignored. to_ms specifies the read timeout in milliseconds. The read timeout is used to arrange that the read not necessarily return immediately when a packet is seen, but that it wait for some amount of time to allow more packets to arrive and to read multiple packets from the OS kernel in one operation. Not all platforms support a read timeout; on platforms that don't, the read timeout is ignored. A zero value for to_ms, on platforms that support a read timeout, will cause a read to wait forever to allow enough packets to arrive, with no timeout. errbuf is used to return error or warning text. It will be set to error text when pcap_open_live() fails and returns NULL. errbuf may also be set to warning text when pcap_open_live() succeds; to detect this case the caller should store a zero-length string in errbuf before calling pcap_open_live() and display the warning to the user if errbuf is no longer a zero-length string.
Special note about snaplen
argument. The behaviour
of this argument may be suprizing to some. The argument
is
only applied when there is a filter set using setFilter
method after the openLive
call. Otherwise snaplen, even non
zero is ignored. This is the behavior of all BSD systems utilizing BPF and
WinPcap. This may change in the future, but that is the current behavior.
(For more detailed explanation and discussion please see jNetPcap website
and its FAQs.)
device
- buffer containing a C, '\0' terminated string with the the name of
the devicesnaplen
- amount of data to capture per packet; (see special note in doc
comments about when this argument is ignored even when non-zero)promisc
- 1 means open in promiscious mode, a 0 means non-propmiscoustimeout
- timeout in mserrbuf
- a buffer that will contain any error messages if the call to open
failed
pcap_t
C structure as
returned by native libpcap call to openpublic static Pcap openOffline(java.lang.String fname, java.lang.StringBuilder errbuf)
fname
- filename of the pcap fileerrbuf
- any error messages in UTC8 encoding
public void breakloop()
set a flag that will force pcap_dispatch() or pcap_loop() to return rather than looping. They will return the number of packets that have been processed so far, or -2 if no packets have been processed so far. This routine is safe to use inside a signal handler on UNIX or a console control handler on Windows, as it merely sets a flag that is checked within the loop. The flag is checked in loops reading packets from the OS - a signal by itself will not necessarily terminate those loops - as well as in loops processing a set of packets returned by the OS. Note that if you are catching signals on UNIX systems that support restarting system calls after a signal, and calling pcap_breakloop() in the signal handler, you must specify, when catching those signals, that system calls should NOT be restarted by that signal. Otherwise, if the signal interrupted a call reading packets in a live capture, when your signal handler returns after calling pcap_breakloop(), the call will be restarted, and the loop will not terminate until more packets arrive and the call completes.
Note: pcap_next() will, on some platforms, loop reading packets from the OS; that loop will not necessarily be terminated by a signal, so pcap_breakloop() should be used to terminate packet processing even if pcap_next() is being used. pcap_breakloop() does not guarantee that no further packets will be processed by pcap_dispatch() or pcap_loop() after it is called; at most one more packet might be processed. If -2 is returned from pcap_dispatch() or pcap_loop(), the flag is cleared, so a subsequent call will resume reading packets. If a positive number is returned, the flag is not cleared, so a subsequent call will return -2 and clear the flag.
protected void checkIsActive() throws PcapClosedException
PcapClosedException
- if pcap_t structure has been deallocated, another words if
Pcap.close has already been called.public void close()
public int compile(PcapBpfProgram program, java.lang.String str, int optimize, int netmask)
program
- initially empty, but after the method call will contain the
compiled BPF programstr
- a string containing the textual expression to be compiledoptimize
- 1 means to do optimizations, any other value means nonetmask
- netmask needed to determine the broadcast address
getErr()
may be used to display the error text.public int datalink()
public <T> int dispatch(int cnt, PcapHandler<T> handler, T user)
Collect a group of packets. pcap_dispatch() is used to collect and process packets. cnt specifies the maximum number of packets to process before returning. This is not a minimum number; when reading a live capture, only one bufferful of packets is read at a time, so fewer than cnt packets may be processed. A cnt of -1 processes all the packets received in one buffer when reading a live capture, or all the packets in the file when reading a ``savefile''. callback specifies a routine to be called with three arguments: a u_char pointer which is passed in from pcap_dispatch(), a const struct pcap_pkthdr pointer, and a const u_char pointer to the first caplen (as given in the struct pcap_pkthdr a pointer to which is passed to the callback routine) bytes of data from the packet (which won't necessarily be the entire packet; to capture the entire packet, you will have to provide a value for snaplen in your call to pcap_open_live() that is sufficiently large to get all of the packet's data - a value of 65535 should be sufficient on most if not all networks).
The number of packets read is returned. 0 is returned if no packets were read from a live capture (if, for example, they were discarded because they didn't pass the packet filter, or if, on platforms that support a read timeout that starts before any packets arrive, the timeout expires before any packets arrive, or if the file descriptor for the capture device is in non-blocking mode and no packets were available to be read) or if no more packets are available in a ``savefile.'' A return of -1 indicates an error in which case pcap_perror() or pcap_geterr() may be used to display the error text. A return of -2 indicates that 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.
Note: when reading a live capture, pcap_dispatch() will not necessarily return when the read times out; on some platforms, the read timeout isn't supported, and, on other platforms, the timer doesn't start until at least one packet arrives. This means that the read timeout should NOT be used in, for example, an interactive application, to allow the packet capture loop to ``poll'' for user input periodically, as there's no guarantee that pcap_dispatch() will return after the timeout expires.
T
- handler's user object typecnt
- number of packets to readhandler
- called when packet arrives for each packetuser
- opaque user object
public PcapDumper dumpOpen(java.lang.String fname)
dumpOpen
method is called
to open a "savefile" for writing. The name '-' is a synonym for stdout.
fname
- specifies the name of the file to open; currently the libpcap
option to open stdout by using "-" as a string, is not supported
by jNetPcap
getErr
method
to retrieve the error messageprotected void finalize()
finalize
in class java.lang.Object
public java.lang.String getErr()
Note: the pointer Return will no longer point to a valid error message string after the pcap_t passed to it is closed; you must use or copy the string before closing the pcap_t.
public int getNonBlock(java.lang.StringBuilder errbuf)
setNonBlock(int, StringBuilder)
public int inject(byte[] buf)
buf
- contains the data of the packet to send (including the various
protocol headers)
public int inject(byte[] buf, int offset, int length)
buf
- contains the data of the packet to send (including the various
protocol headers)offset
- offset of the first index into the byte arraylength
- amount of data to write from the offset
public int inject(java.nio.ByteBuffer buf)
buf
- contains the data of the packet to send (including the various
protocol headers); the buffer should be a direct buffer; array
based buffers will be copied into a direct buffer
public int isSwapped()
public <T> int loop(int cnt, PcapHandler<T> handler, T user)
T
- handler's user object typecnt
- number of packets to readhandler
- called when packet arrives for each packetuser
- opaque user object
public int majorVersion()
public int minorVersion()
public java.nio.ByteBuffer next(PcapPktHdr pkt_header)
pkt_header
- a packet header that will be initialized to corresponding C
structure captured values
public int nextEx(PcapPktHdr pkt_header, PcapPktBuffer buffer)
pkt_header
- a packet header that will be initialized to corresponding C
structure captured valuesbuffer
- buffer containing packet data or null if error occured
public int sendPacket(byte[] buf)
buf
- contains the data of the packet to send (including the various
protocol headers)
public int sendPacket(byte[] buf, int offset, int length)
buf
- contains the data of the packet to send (including the various
protocol headers)offset
- offset of the first index into the byte arraylength
- amount of data to write from the offset
public int sendPacket(java.nio.ByteBuffer buf)
buf
- contains the data of the packet to send (including the various
protocol headers); the buffer should be a direct buffer; array
based buffers will be copied into a direct buffer
public int setDatalink(int dlt)
dlt
- new dlt
public int setFilter(PcapBpfProgram program)
program
-
public int setNonBlock(int nonBlock, java.lang.StringBuilder errbuf)
nonBlock
- a non negative value means to set in non blocking mode
getNonBlock(StringBuilder)
public int snapshot()
openLive(String, int, int, int, StringBuilder)
public int stats(PcapStat stats)
stats
- PcapStat object to fill in
getErr
to retrieve the
error messagepublic java.lang.String toString()
toString
in class java.lang.Object
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |