|
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
net.sourceforge.jpcap.net.EthernetPacket
public class EthernetPacket
An Ethernet packet.
Contains link-layer header and data payload encapsulated by an Ethernet packet.
IP and ARP protocols are supported as subclasses, as are various link-layer and SNAP subclasses.
Field Summary | |
---|---|
protected ByteBuffer |
_byteBuffer
The entire packet data wrapped in a ByteBuffer. |
protected byte[] |
_bytes
Deprecated. Do not use this field: it will be removed in a future release. |
protected int |
_ethOffset
Offset from beginning of byte array where the data payload (e.g. |
protected Timeval |
_timeval
Time the packet was captured off the wire. |
Fields inherited from interface net.sourceforge.jpcap.net.EthernetFields |
---|
ETH_CODE_LEN, ETH_CODE_POS, ETH_DST_POS, ETH_HEADER_LEN, ETH_SRC_POS |
Constructor Summary | |
---|---|
EthernetPacket(int lLen,
byte[] bytes)
Construct a new ethernet packet. |
|
EthernetPacket(int lLen,
byte[] bytes,
Timeval tv)
Construct a new ethernet packet, including the capture time. |
|
EthernetPacket(int lLen,
ByteBuffer byteBuffer,
Timeval tv)
Construct a new ethernet packet, including the capture time. |
Method Summary | |
---|---|
boolean |
equals(Object that)
|
String |
getColor()
Fetch ASCII escape sequence of the color associated with this packet type. |
byte[] |
getData()
Fetch the data portion of the packet. |
String |
getDestinationHwAddress()
Deprecated. Please use getDestinationMACAddress() |
MACAddress |
getDestinationMACAddress()
Fetch the MAC address of the host where the packet originated from. |
int |
getEthernetCRC32()
Return the Ethernet CRC-32. |
byte[] |
getEthernetData()
Fetch the Ethernet data as a byte array. |
byte[] |
getEthernetHeader()
Fetch the ethernet header as a byte array. |
int |
getEthernetHeaderLength()
Fetch the Ethernet header length in bytes. |
int |
getEthernetProtocol()
Fetch the Ethernet protocol. |
byte[] |
getHeader()
Fetch header portion of the packet. |
int |
getHeaderLength()
Return the length of the header. |
ByteBuffer |
getPacketData()
Fetch the packet data as a ByteBuffer. |
int |
getPacketLength()
Fetch the total length of the packet. |
int |
getProtocol()
Return the protocol. |
String |
getSourceHwAddress()
Deprecated. Please use getSourceMACAddress() |
MACAddress |
getSourceMACAddress()
Fetch the MAC address of the host where the packet originated from. |
Timeval |
getTimeval()
Fetch the timeval containing the time the packet arrived on the device where it was captured. |
int |
hashCode()
|
void |
setChecksums()
Set all the checksums in this packet prior to sending. |
void |
setDestinationMACAddress(MACAddress macAddress)
Set the destination hardware address. |
void |
setEthernetProtocol(int protocol)
Set the Ethernet protocol |
void |
setSourceMACAddress(MACAddress macAddress)
Set the source hardware address. |
byte[] |
toByteArray()
Convert this packet to a byte[] array. |
String |
toColoredString(boolean colored)
Generate string with contents describing this packet. |
String |
toString()
|
Methods inherited from class net.sourceforge.jpcap.net.Packet |
---|
getChecksum, ipChecksum, isValidChecksum |
Methods inherited from class java.lang.Object |
---|
clone, finalize, getClass, notify, notifyAll, wait, wait, wait |
Field Detail |
---|
protected byte[] _bytes
toByteArray()
protected transient ByteBuffer _byteBuffer
protected int _ethOffset
protected Timeval _timeval
Constructor Detail |
---|
public EthernetPacket(int lLen, byte[] bytes)
For the purpose of Jpcap, when the type of ethernet packet is recognized as a protocol for which a class exists network library, a more specific class like IPPacket or ARPPacket is instantiated.
lLen
- link-layer header lengthbytes
- Packet datapublic EthernetPacket(int lLen, byte[] bytes, Timeval tv)
lLen
- Length of link-layer databytes
- Packet data bytestv
- Timeval when captured, or nullpublic EthernetPacket(int lLen, ByteBuffer byteBuffer, Timeval tv)
lLen
- Length of link-layer databyteBuffer
- Packet data in a ByteBuffertv
- Timeval when captured, or nullMethod Detail |
---|
public final int getPacketLength()
getPacketLength
in class Packet
public final 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()
.
toByteArray
in class Packet
Packet.getPacketData()
public final 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()
.
getPacketData
in class Packet
Packet.toByteArray()
public final int getEthernetHeaderLength()
public int getHeaderLength()
getHeaderLength
in class Packet
Packet.getHeader()
.Packet.getHeader()
public final byte[] getEthernetHeader()
public byte[] getHeader()
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
getHeader
in class Packet
public final byte[] getEthernetData()
public byte[] getData()
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
getData
in class Packet
public String getSourceHwAddress()
getSourceMACAddress()
public MACAddress getSourceMACAddress()
public void setSourceMACAddress(MACAddress macAddress)
macAddress
- Source MAC address.public String getDestinationHwAddress()
getDestinationMACAddress()
public MACAddress getDestinationMACAddress()
public void setDestinationMACAddress(MACAddress macAddress)
macAddress
- Destination MAC address.public final int getEthernetProtocol()
public final void setEthernetProtocol(int protocol)
protocol
- Protocol wordpublic int getProtocol()
getProtocol()
returns the Ethernet protocol word.
IPv4.Packet.getProtocol()
returns the IP protocol word
getProtocol
in class Packet
public final Timeval getTimeval()
getTimeval
in class Packet
public int getEthernetCRC32()
setEthernetCRC32()
method is provided,
and setChecksums()
doesn't re-compute it.
public 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.
After calling this method the hashCode()
of this object will probably change.
setChecksums
in class Packet
public int hashCode()
This implementation returns the Ethernet CRC-32.
hashCode
in class Object
public boolean equals(Object that)
This implementation returns true iff the hashCodes, i.e. the CRC-32s, are equal.
equals
in class Object
public String toString()
toString
in class Object
public String toColoredString(boolean colored)
toColoredString
in class Packet
colored
- whether or not the string should contain ansi
color escape sequences.public String getColor()
getColor
in class Packet
|
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 |