Package org.pcap4j.core
Class PcapPacket
- java.lang.Object
-
- org.pcap4j.packet.AbstractPacket
-
- org.pcap4j.core.PcapPacket
-
public final class PcapPacket extends AbstractPacket
Pseudo packet to hold a timestamp, an original length, and a raw data of a captured packet. This class doesn't dissect the raw data until certain methods (refer to each method's javadoc) are called. Instances of this class are not immutable.- Since:
- pcap4j 2.0.0
- Author:
- Kaito Yamada
- See Also:
- Serialized Form
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
PcapPacket.Builder
-
Nested classes/interfaces inherited from class org.pcap4j.packet.AbstractPacket
AbstractPacket.AbstractBuilder, AbstractPacket.AbstractHeader
-
Nested classes/interfaces inherited from interface org.pcap4j.packet.Packet
Packet.Header
-
-
Method Summary
Modifier and Type Method Description protected java.lang.String
buildString()
This method builds the valuetoString()
will return by concatenating the header's string representation and the payload's string representation.boolean
equals(java.lang.Object o)
Indicates whether some other object is "equal to" this one.PcapPacket.Builder
getBuilder()
Returns a new Builder object populated with this object's fields' values.int
getOriginalLength()
Packet
getPacket()
This method dissect the raw data.Packet
getPayload()
An alternative togetPacket()
.byte[]
getRawData()
Get the raw data of the captured packet.java.time.Instant
getTimestamp()
int
hashCode()
Returns a hash code value for the object.int
length()
Get the length of the captured packet.java.lang.String
toString()
Returns a string representation of the object.-
Methods inherited from class org.pcap4j.packet.AbstractPacket
buildHexString, buildRawData, calcHashCode, calcLength, getHeader, toHexString
-
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface org.pcap4j.packet.Packet
contains, get, getLowerLayerOf, iterator
-
-
-
-
Method Detail
-
getTimestamp
public java.time.Instant getTimestamp()
- Returns:
- the timestamp of when this packet was captured.
-
getOriginalLength
public int getOriginalLength()
- Returns:
- the original length of this packet.
-
getPacket
public Packet getPacket()
This method dissect the raw data.- Returns:
- the captured packet.
-
getPayload
public Packet getPayload()
An alternative togetPacket()
. This method dissect the raw data.- Specified by:
getPayload
in interfacePacket
- Overrides:
getPayload
in classAbstractPacket
- Returns:
- the same object as
getPacket()
.
-
length
public int length()
Get the length of the captured packet.- Specified by:
length
in interfacePacket
- Overrides:
length
in classAbstractPacket
- Returns:
- length
-
getRawData
public byte[] getRawData()
Get the raw data of the captured packet. This method doesn't do a defensive copy for performance reason.- Specified by:
getRawData
in interfacePacket
- Overrides:
getRawData
in classAbstractPacket
- Returns:
- raw data
-
getBuilder
public PcapPacket.Builder getBuilder()
Description copied from interface:Packet
Returns a new Builder object populated with this object's fields' values.- Specified by:
getBuilder
in interfacePacket
- Specified by:
getBuilder
in classAbstractPacket
- Returns:
- a new Builder object populated with this object's fields values
-
buildString
protected java.lang.String buildString()
Description copied from class:AbstractPacket
This method builds the valuetoString()
will return by concatenating the header's string representation and the payload's string representation. If you write this subclass which represents a packet with extra parts (e.g. a trailer), you need to override this method.- Overrides:
buildString
in classAbstractPacket
- Returns:
- a string representation of this object
-
toString
public java.lang.String toString()
Returns a string representation of the object. This method dissect the raw data.- Overrides:
toString
in classAbstractPacket
-
equals
public boolean equals(java.lang.Object o)
Description copied from class:AbstractPacket
Indicates whether some other object is "equal to" this one. This method firstly compares this packet's header using the header's equals(Object) method, then compares this packet's payload using the payload's equals(Object) method. If you write this subclass with fields which represent somethings other than header or payload, you need to override this method.- Overrides:
equals
in classAbstractPacket
-
hashCode
public int hashCode()
Description copied from class:AbstractPacket
Returns a hash code value for the object. This method callscalcHashCode()
and caches the return value when it is called for the first time, and then, this method returns the cached value from the second time.- Overrides:
hashCode
in classAbstractPacket
-
-