|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Object | +--jpcap.Jpcap
This class is used to capture packets.
Sample program
import jpcap.*;
class Tcpdump implements JpcapHandler
{
public void handlePacket(Packet packet){
System.out.println(packet);
}
public static void main(String[] args) throws java.io.IOException{
Jpcap jpcap=Jpcap.openDevice(args[0],1000,true,20);
jpcap.processPacket(-1,new Tcpdump());
}
}
| Field Summary | |
int |
dropped_packets
Number of dropped packets |
int |
received_packets
Number of received packets |
| Method Summary | |
void |
close()
Closes the opened interface of dump file. |
static java.lang.String[] |
getDeviceDescription()
Returns the descriptions of the interfaces (For Windows only) |
static java.lang.String[] |
getDeviceList()
Returns the names of the interfaces that can be used for capturing. |
java.lang.String |
getErrorMessage()
Returns an error message |
Packet |
getPacket()
Returns a captured packet. |
static java.lang.String |
lookupDevice()
Returns the names of the interfaces that can be used for capturing. |
int |
loopPacket(int count,
JpcapHandler handler)
Captures the specified number of packets consecutively. |
static Jpcap |
openDevice(java.lang.String device,
int snaplen,
boolean promisc,
int to_ms)
Initializes the network interface, and returns an instance of this class. |
static Jpcap |
openFile(java.lang.String filename)
Opens a dump file created by tcpdump or Ethereal, and returns an instance of this class. |
int |
processPacket(int count,
JpcapHandler handler)
Captures the specified number of packets consecutively. |
void |
setFilter(java.lang.String condition,
boolean optimize)
Sets a filter. |
void |
updateStat()
Updates received_packets and dropped_packets. |
| Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
public int received_packets
updateStat()public int dropped_packets
updateStat()| Method Detail |
public static Jpcap openDevice(java.lang.String device,
int snaplen,
boolean promisc,
int to_ms)
throws java.io.IOException
device - Name of the network interfacesnaplen - Max number of bytes captured at oncepromisc - If true, the inferface becomes promiscuous modeto_ms - Timeout of processPacket()
java.io.IOException - Raised when the specified interface cannot be opened
public static Jpcap openFile(java.lang.String filename)
throws java.io.IOException
filename - File name of the dump file
java.io.IOException - If the file cannot be openedpublic static java.lang.String lookupDevice()
public static java.lang.String[] getDeviceList()
public static java.lang.String[] getDeviceDescription()
On Windows, the interface name is represented as a difficult string (e.g. \Device\Packet_{6E05D...}) This method returns the description of each interface that is easier to understand (e.g. 3com EtherLinkII).
public Packet getPacket()
public int processPacket(int count,
JpcapHandler handler)
count - Number of packets to be capturedhandler - an instnace of JpcapHandler that analyzes the captured packets
public int loopPacket(int count,
JpcapHandler handler)
Unlike processPacket(), this method ignores the timeout.
count - Number of packets to be capturedhandler - an instnace of JpcapHandler that analyzes the captured packets
public void setFilter(java.lang.String condition,
boolean optimize)
condition - a string representation of the filteroptimize - If true, the filter is optimizedpublic void updateStat()
received_packets and dropped_packets.
public java.lang.String getErrorMessage()
public void close()
|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||