Package org.pcap4j.packet
Class AbstractPacket.AbstractHeader
- java.lang.Object
-
- org.pcap4j.packet.AbstractPacket.AbstractHeader
-
- All Implemented Interfaces:
java.io.Serializable
,Packet.Header
- Direct Known Subclasses:
ArpPacket.ArpHeader
,BsdLoopbackPacket.BsdLoopbackHeader
,DnsPacket.DnsHeader
,Dot11ManagementPacket.Dot11ManagementHeader
,Dot1qVlanTagPacket.Dot1qVlanTagHeader
,EthernetPacket.EthernetHeader
,GtpV1Packet.GtpV1Header
,HdlcPppPacket.HdlcPppHeader
,IcmpV4CommonPacket.IcmpV4CommonHeader
,IcmpV4DestinationUnreachablePacket.IcmpV4DestinationUnreachableHeader
,IcmpV4EchoPacket.IcmpV4EchoHeader
,IcmpV4EchoReplyPacket.IcmpV4EchoReplyHeader
,IcmpV4InformationReplyPacket.IcmpV4InformationReplyHeader
,IcmpV4InformationRequestPacket.IcmpV4InformationRequestHeader
,IcmpV4ParameterProblemPacket.IcmpV4ParameterProblemHeader
,IcmpV4RedirectPacket.IcmpV4RedirectHeader
,IcmpV4SourceQuenchPacket.IcmpV4SourceQuenchHeader
,IcmpV4TimeExceededPacket.IcmpV4TimeExceededHeader
,IcmpV4TimestampPacket.IcmpV4TimestampHeader
,IcmpV4TimestampReplyPacket.IcmpV4TimestampReplyHeader
,IcmpV6CommonPacket.IcmpV6CommonHeader
,IcmpV6DestinationUnreachablePacket.IcmpV6DestinationUnreachableHeader
,IcmpV6EchoReplyPacket.IcmpV6EchoReplyHeader
,IcmpV6EchoRequestPacket.IcmpV6EchoRequestHeader
,IcmpV6HomeAgentAddressDiscoveryReplyPacket.IcmpV6HomeAgentAddressDiscoveryReplyHeader
,IcmpV6HomeAgentAddressDiscoveryRequestPacket.IcmpV6HomeAgentAddressDiscoveryRequestHeader
,IcmpV6MobilePrefixAdvertisementPacket.IcmpV6MobilePrefixAdvertisementHeader
,IcmpV6MobilePrefixSolicitationPacket.IcmpV6MobilePrefixSolicitationHeader
,IcmpV6NeighborAdvertisementPacket.IcmpV6NeighborAdvertisementHeader
,IcmpV6NeighborSolicitationPacket.IcmpV6NeighborSolicitationHeader
,IcmpV6PacketTooBigPacket.IcmpV6PacketTooBigHeader
,IcmpV6ParameterProblemPacket.IcmpV6ParameterProblemHeader
,IcmpV6RedirectPacket.IcmpV6RedirectHeader
,IcmpV6RouterAdvertisementPacket.IcmpV6RouterAdvertisementHeader
,IcmpV6RouterSolicitationPacket.IcmpV6RouterSolicitationHeader
,IcmpV6TimeExceededPacket.IcmpV6TimeExceededHeader
,IpV4Packet.IpV4Header
,IpV6ExtFragmentPacket.IpV6ExtFragmentHeader
,IpV6ExtOptionsPacket.IpV6ExtOptionsHeader
,IpV6ExtRoutingPacket.IpV6ExtRoutingHeader
,IpV6ExtUnknownPacket.IpV6ExtUnknownHeader
,IpV6Packet.IpV6Header
,LinuxSllPacket.LinuxSllHeader
,LlcPacket.LlcHeader
,PppPacket.PppHeader
,RadiotapPacket.RadiotapHeader
,SctpPacket.SctpHeader
,SnapPacket.SnapHeader
,Ssh2BinaryPacket.Ssh2BinaryHeader
,Ssh2DebugPacket.Ssh2DebugHeader
,Ssh2DisconnectPacket.Ssh2DisconnectHeader
,Ssh2IgnorePacket.Ssh2IgnoreHeader
,Ssh2KexDhInitPacket.Ssh2KexDhInitHeader
,Ssh2KexDhReplyPacket.Ssh2KexDhReplyHeader
,Ssh2KexInitPacket.Ssh2KexInitHeader
,Ssh2NewKeysPacket.Ssh2NewKeysHeader
,Ssh2ServiceAcceptPacket.Ssh2ServiceAcceptHeader
,Ssh2ServiceRequestPacket.Ssh2ServiceRequestHeader
,Ssh2UnimplementedPacket.Ssh2UnimplementedHeader
,Ssh2VersionExchangePacket.Ssh2VersionExchangeHeader
,TcpPacket.TcpHeader
,UdpPacket.UdpHeader
- Enclosing class:
- AbstractPacket
public abstract static class AbstractPacket.AbstractHeader extends java.lang.Object implements Packet.Header
Abstract immutable header class.- Author:
- Kaito Yamada
- See Also:
- Serialized Form
-
-
Constructor Summary
Constructors Modifier Constructor Description protected
AbstractHeader()
-
Method Summary
Modifier and Type Method Description protected java.lang.String
buildHexString()
This method builds the valuetoHexString()
will return using the return value ofgetRawData()
.protected byte[]
buildRawData()
This method builds the valuegetRawData()
will return by concatenating the byte arrays in the listgetRawFields()
returns.protected java.lang.String
buildString()
This method builds the valuetoString()
will return.protected int
calcHashCode()
This method builds the valuehashCode()
will return using the byte arraygetRawData()
returns.protected int
calcLength()
This method calculates the valuelength()
will return by adding up the lengths of byte arrays in the listgetRawFields()
returns.boolean
equals(java.lang.Object obj)
Indicates whether some other object is "equal to" this one using return values ofgetRawData()
.byte[]
getRawData()
Returns this header's raw data.protected abstract java.util.List<byte[]>
getRawFields()
Returns a list of byte arrays which represents this header's fields.int
hashCode()
Returns a hash code value for the object.int
length()
Returns the header length in bytes.java.lang.String
toHexString()
Returns the hex string representation of this object.java.lang.String
toString()
Returns a string representation of the object.
-
-
-
Method Detail
-
getRawFields
protected abstract java.util.List<byte[]> getRawFields()
Returns a list of byte arrays which represents this header's fields. This method is called bycalcLength()
andbuildRawData()
.- Returns:
- a list of byte arrays which represents this header's fields
-
calcLength
protected int calcLength()
This method calculates the valuelength()
will return by adding up the lengths of byte arrays in the listgetRawFields()
returns.- Returns:
- a calculated length
-
length
public int length()
Returns the header length in bytes. This method callscalcLength()
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.- Specified by:
length
in interfacePacket.Header
- Returns:
- the length of the byte stream of the header represented by this object in bytes
-
buildRawData
protected byte[] buildRawData()
This method builds the valuegetRawData()
will return by concatenating the byte arrays in the listgetRawFields()
returns.- Returns:
- a raw data built
-
getRawData
public byte[] getRawData()
Returns this header's raw data. This method callsbuildRawData()
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. More correctly, this method returns a copy of the cached value, so that the cache can't be changed.- Specified by:
getRawData
in interfacePacket.Header
- Returns:
- the raw data of this packet's header, namely a piece of the byte stream which is actually sent through real network
-
buildHexString
protected java.lang.String buildHexString()
This method builds the valuetoHexString()
will return using the return value ofgetRawData()
. Each octet in this return value is separated by a white space. (e.g. 00 01 02 03 aa bb cc)- Returns:
- a hex string representation of this object
-
toHexString
public java.lang.String toHexString()
Returns the hex string representation of this object. This method callsbuildHexString()
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.- Returns:
- a hex string representation of this object
-
buildString
protected java.lang.String buildString()
This method builds the valuetoString()
will return.- Returns:
- a string representation of this object
-
toString
public java.lang.String toString()
Returns a string representation of the object. This method callsbuildString()
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:
toString
in classjava.lang.Object
-
equals
public boolean equals(java.lang.Object obj)
Indicates whether some other object is "equal to" this one using return values ofgetRawData()
. This method should be overridden so that it does more strict comparisons more efficiently.- Overrides:
equals
in classjava.lang.Object
-
calcHashCode
protected int calcHashCode()
This method builds the valuehashCode()
will return using the byte arraygetRawData()
returns. This method may be better to be overridden for performance reason.- Returns:
- a calculated hash code value for the object
-
hashCode
public int hashCode()
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 classjava.lang.Object
-
-