|
SourceForge Jpcap | |||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectnet.sourceforge.jpcap.net.Packet
public abstract class Packet
A network packet.
This class currently contains no implementation because only Ethernet is supported. In other words, all instances of packets returned by packet factory will always be at least as specific as EthernetPacket.
On large Ethernet networks, I sometimes see packets which don't have link-level ethernet headers. If and when I figure out what these are, maybe this class will be the root node of a packet hierarchy derived from something other than Ethernet.
Constructor Summary | |
---|---|
Packet()
|
Method Summary | |
---|---|
int |
getChecksum()
Return the actual packet checksum as received. |
abstract String |
getColor()
Fetch ASCII escape sequence of the color associated with this packet type. |
abstract byte[] |
getData()
Fetch the data portion of the packet. |
abstract byte[] |
getHeader()
Fetch header portion of the packet. |
abstract int |
getHeaderLength()
Return the length of the header. |
abstract ByteBuffer |
getPacketData()
Fetch the packet data as a ByteBuffer. |
abstract int |
getPacketLength()
Fetch the total length of the packet. |
abstract int |
getProtocol()
Return the protocol. |
abstract Timeval |
getTimeval()
Fetch the timeval containing the time the packet arrived on the device where it was captured. |
protected int |
ipChecksum(byte[] bytes,
int start,
int len)
Compute an IP checksum. |
boolean |
isValidChecksum()
Return true iff all the checksums in the packet are valid, otherwise false. |
abstract void |
setChecksums()
Set all the checksums in this packet prior to sending. |
abstract byte[] |
toByteArray()
Convert this packet to a byte[] array. |
abstract String |
toColoredString(boolean colored)
Generate string with contents describing this packet. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public Packet()
Method Detail |
---|
public abstract int getPacketLength()
public abstract byte[] toByteArray()
toByteArray()
operation requires
copying data across the Java/JNI boundary, which is expensive.
The array returned is a copy, so altering it is futile
unless you construct a new packet with it.
For a much more efficient read/write interface, see getPacketData()
.
getPacketData()
public abstract ByteBuffer getPacketData()
ByteBuffer.array()
,
so its ByteBuffer.hasArray()
method will probably return false.
This is the form in which the packet is actually captured under the hood, and
processed internally, so it is the most efficient way to look at or alter packet data,
using all the methods of ByteBuffer
.
For a simpler but much less efficient interface, see toByteArray()
.
toByteArray()
public abstract byte[] getHeader()
EthernetPacket.getHeader()
returns the Ethernet header
IP.Packet.getHeader()
returns the IP header, which is in the Ethernet payload
TCPPacket.getHeader()
returns the TCP header, which is in the IP payload
public abstract int getHeaderLength()
getHeader()
.getHeader()
public abstract byte[] getData()
EthernetPacket.getData()
returns the entire Ethernet payload excluding the Ethernet header
IP.Packet.getData()
only returns the IP payload, i.e. excluding the IP header which is in the Ethernet payload
TCPPacket.getData()
only returns the TCP payload, i.e. excluding the TCP header which is in the IP payload
public abstract int getProtocol()
EthernetPacket.getProtocol()
returns the Ethernet protocol word.
IPv4.Packet.getProtocol()
returns the IP protocol word
public abstract String getColor()
public abstract Timeval getTimeval()
public boolean isValidChecksum()
super.isValidChecksum()
to check the validity of base class checksums.
The isValidChecksum()
implementation just returns true.
public int getChecksum()
IPv4.Packet.getChecksum()
returns the IP checksum
TCPPacket.getChecksum()
returns the TCP checksum
getChecksum()
returns zero.
public abstract void setChecksums()
PacketOutputStream.writePacket(Packet)
.
Derived classes must override this abstract method, and must call super.setChecksums()
,
after setting their own checksums
(unless super.setChecksums() is abstract, i.e. this method).
Otherwise the lower-level checksums will not be correct.
protected int ipChecksum(byte[] bytes, int start, int len)
IPPacket.onesCompSum(byte[], int, int)
.
This is part of the fix for issue 1352176.
bytes
- datastart
- Initial offsetlen
- Total number of bytes to process
public abstract String toColoredString(boolean colored)
colored
- whether or not the string should contain ansi
color escape sequences.
|
Copyright © Patrick Charles & Jonas Lehmann, 2001; Esmond Pitt, 2008. | |||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |