|
||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
| SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||
java.lang.Object | +--jpcap.Jpcap
Main class of package jpcap.
Capturing and Sending packets are done through the instance of this class.
Sample tcpdump-like capturing 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=new Jpcap(args[0],1000,true,20);
jpcap.processPacket(-1,new Tcpdump());
}
}
| Inner Class Summary | |
class |
Jpcap.JpcapInfo
Class for keeping capture info. |
| Field Summary | |
int |
dropped_packets
Number of packets dropped |
int |
received_packets
Number of packets received |
| Constructor Summary | |
Jpcap(java.lang.String filename)
Opens the dump file created by tcpdump and creates the instance of this class. |
|
Jpcap(java.lang.String device,
int snaplen,
boolean promisc,
int to_ms)
Initializes the specified network interface and creates the instance of this class. |
|
| Method Summary | |
void |
close()
Close the interface or dump file which is currently opened. |
java.lang.String |
getErrorMessage()
Returns the error message which was caused by the error while capturing. |
Jpcap.JpcapInfo |
getJpcapInfo()
Return JpcapInfo of this Jpcap instance. |
Packet |
getPacket()
Captures one packet. |
static java.lang.String |
lookupDevice()
Returns the name of the device which can be used for capturing. |
void |
openRawSocket()
Initializes the sending socket. This method must be called before sending packets. |
int |
processPacket(int count,
JpcapHandler handler)
Captures the specified number of packets consecutively. |
void |
sendPacket(IPPacket packet)
Sends a IP packet. Currently only TCP/UDP/ICMP over IPv4 are supported. For ICMP, only echo packets can be sent. |
void |
setFilter(java.lang.String condition,
boolean optimize)
Sets up the capturing filter. |
void |
updateStat()
Updates received_packets and dropped_packets |
| Methods inherited from class java.lang.Object |
equals,
getClass,
hashCode,
notify,
notifyAll,
toString,
wait,
wait,
wait |
| Field Detail |
public int received_packets
updateStat()public int dropped_packets
updateStat()| Constructor Detail |
public Jpcap(java.lang.String device,
int snaplen,
boolean promisc,
int to_ms)
throws java.io.IOException
device - Name of the interface (eg: hme0,eth0)snaplen - Maximum number of bytes captured at oncepromisc - The specified interface goes promiscuous mode if trueto_ms - Time out of processPacket()
public Jpcap(java.lang.String filename)
throws java.io.IOException
filename - Name of dump file| Method Detail |
public static java.lang.String lookupDevice()
public Packet getPacket()
public int processPacket(int count,
JpcapHandler handler)
count - Maximum number of packets processinghandler - The captures packets are passed to this JpcapHandler object to analyze
public void setFilter(java.lang.String condition,
boolean optimize)
condition - String which represents the condition of filtering. (See the document of tcpdump)optimize - Filter is optimized if truepublic void updateStat()
received_packets and dropped_packetspublic void openRawSocket()
public void sendPacket(IPPacket packet)
packet - IP packet to be sentpublic java.lang.String getErrorMessage()
public void close()
public Jpcap.JpcapInfo getJpcapInfo()
|
||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
| SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||