|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectisc.util.pcap.javacap
public class javacap
This is a very rough RMI cover over the pcap library. This library was adapted from jpcap.sourceforge.net. I added a number of routines and restructured some of the code. please refer to man pcap, for details on pcap files
Field Summary | |
---|---|
int |
EOF
pcap end of file flag |
int |
PROTOCOL_IP
Protocol constant for IPV4. |
int |
PROTOCOL_PPOE
Protocol constant for PPOE |
int |
PROTOCOL_PPOE_IP
|
Constructor Summary | |
---|---|
javacap()
Create a new javacap Object Initialize packet buffer to default 4k |
|
javacap(int size)
Create a new javacap Object Intialize packet buffer to specified size |
Method Summary | |
---|---|
int |
_open_offline(java.lang.String fname,
byte[] errbuf)
RMI method for opening an existing pcap file |
void |
_parseL2Headers(byte[] b,
byte[] l2hdr,
byte[] l2encap,
int caplen)
Parse the the packet for the layer2 header and encapsulation |
int |
_read_next(byte[] b,
byte[] l2hdr,
byte[] l2encap)
Read a packet form a capture device. |
int |
_read(byte[] b,
byte[] l2hdr)
RMI method for reading the next packet from the device |
void |
close()
Close the network capture device |
void |
dump_close()
Close the pcap file opened by dump_open() |
int |
dump_flush()
flush the pcap file to disk |
int |
dump_open(java.lang.String filename,
int linktype,
int snaplen,
byte[] errbuf)
Create a pcap file |
void |
dump_write(long timestamp,
long nanoseconds,
byte[] data,
int datasize)
Write a packet to a previously opened dump file |
int |
findAllDevices(java.lang.String[] devices,
java.lang.String[] Desc,
byte[] errbuf)
Enumerates all of the device available for capture |
int |
getCapturedLength()
|
byte[] |
getData()
Get the read packet data |
int |
getDataLinkType()
|
long |
getDevicePacketTimestampMicroseconds()
Get the packet microseconds of the timestamp, from the previously read packet |
long |
getDevicePacketTimestampSeconds()
Get the packet timestamp, from the previously read packet |
int |
getDroppedPackets()
|
java.lang.String |
getError()
|
int |
getEthHeaderProto()
Get the protocol information from the ethernet header |
int |
getFilePacketLength()
|
long |
getFilePacketTimestampMicroseconds()
Get the packet microseconds of the timestamp, from the previously read packet |
long |
getFilePacketTimestampSeconds()
Get the packet timestamp, from the previously read packet |
int |
getNextProto(byte[] hdr,
int offset)
|
int |
getPacketLength()
|
int |
getPacketProtocol()
|
int |
getReceivedPackets()
|
boolean |
isFileOpen()
Check if the pcap file is open |
boolean |
open_offline(java.lang.String fname,
byte[] errbuf)
Open the pcap file |
void |
open(java.lang.String name,
int bufferSize)
Open a network device for reading |
void |
read(byte[] b)
|
int |
readDeviceNextPacket()
|
int |
readFileNextPacket()
Read the next packet from the pcap file |
int |
setFilter(java.lang.String rule,
int netmask)
|
int |
size()
Returns the size of the allocated packet length |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
public final int PROTOCOL_IP
public final int PROTOCOL_PPOE
public final int PROTOCOL_PPOE_IP
public final int EOF
Constructor Detail |
---|
public javacap()
public javacap(int size)
size
- size of the packet buffer to use.Method Detail |
---|
public void read(byte[] b)
public java.lang.String getError()
public int setFilter(java.lang.String rule, int netmask)
public void open(java.lang.String name, int bufferSize)
name
- Name of he devicebufferSize
- Size of buffer to be readpublic void close()
public int getReceivedPackets()
public int getDroppedPackets()
public int getDataLinkType()
public int getPacketLength()
public int getCapturedLength()
public int getFilePacketLength()
public int findAllDevices(java.lang.String[] devices, java.lang.String[] Desc, byte[] errbuf)
devices
- Array of strings to be filled in containing the devicesDesc
- Array of strings to be filed in containing the descriptionserrbuf
- error mesages if return = -1
public int dump_open(java.lang.String filename, int linktype, int snaplen, byte[] errbuf)
filename
- The name of the file to createlinktype
- The link typesnaplen
- The buffer sizepublic void dump_write(long timestamp, long nanoseconds, byte[] data, int datasize)
timestamp
- Timestamp in milliseconds of the packetnanoseconds
- nanoseconds of the packetsdata
- the packet datadatasize
- the size of the packet datapublic void dump_close()
public int dump_flush()
public int _read_next(byte[] b, byte[] l2hdr, byte[] l2encap)
b
- The datal2hdr
- the layer 2 headerl2encap
- the encapsulation layer
public void _parseL2Headers(byte[] b, byte[] l2hdr, byte[] l2encap, int caplen)
b
- the packetl2hdr
- layer2 headerl2encap
- encapsulationcaplen
- capturelenpublic int _read(byte[] b, byte[] l2hdr)
_data
- Contains the IP packet_ethdata
- Contains the ethernet header
public long getDevicePacketTimestampSeconds()
public long getDevicePacketTimestampMicroseconds()
public int _open_offline(java.lang.String fname, byte[] errbuf)
fname
- The name of the pcap fle to be openederrbuf
- The error message if the file could not be openedpublic long getFilePacketTimestampSeconds()
public long getFilePacketTimestampMicroseconds()
public boolean isFileOpen()
public boolean open_offline(java.lang.String fname, byte[] errbuf)
fname
- Name of the file to openerrbuf
- Error message if failed
public int size()
public int readDeviceNextPacket()
public int readFileNextPacket()
public byte[] getData()
public int getEthHeaderProto()
public int getNextProto(byte[] hdr, int offset)
public int getPacketProtocol()
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |