Class EthernetPacket
java.lang.Object
org.pcap4j.packet.AbstractPacket
org.pcap4j.packet.EthernetPacket
- All Implemented Interfaces:
Serializable, Iterable<Packet>, Packet
This Class handles from DA to data. Both preamble, SFD, and FCS are not contained.
- Since:
- pcap4j 0.9.1
- See Also:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic final classstatic final classNested classes/interfaces inherited from class AbstractPacket
AbstractPacket.AbstractBuilder, AbstractPacket.AbstractHeaderNested classes/interfaces inherited from interface Packet
Packet.Header -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final EthernetPacket.EthernetHeaderprivate static final intprivate final byte[]private final Packetprivate static final long -
Constructor Summary
ConstructorsModifierConstructorDescriptionprivateEthernetPacket(byte[] rawData, int offset, int length) privateEthernetPacket(EthernetPacket.Builder builder) -
Method Summary
Modifier and TypeMethodDescriptionprotected byte[]This method builds the valuegetRawData()will return by concatenating the header's raw data and the payload's raw data.protected StringThis method builds the valuetoString()will return by concatenating the header's string representation and the payload's string representation.protected intThis method calculates the valuehashCode()will return using the header's hash code and the payload's hash code.protected intThis method calculates the valuelength()will return by adding up the header length and the payload length.booleanIndicates whether some other object is "equal to" this one.Returns a new Builder object populated with this object's fields' values.Returns the Header object representing this packet's header.byte[]getPad()Returns the Packet object representing this packet's payload.static EthernetPacketnewPacket(byte[] rawData, int offset, int length) A static factory method.Methods inherited from class AbstractPacket
buildHexString, contains, get, getOuterOf, getRawData, hashCode, iterator, length, toHexString, toStringMethods inherited from interface Iterable
forEach, spliterator
-
Field Details
-
serialVersionUID
private static final long serialVersionUID- See Also:
-
MIN_ETHERNET_PAYLOAD_LENGTH
private static final int MIN_ETHERNET_PAYLOAD_LENGTH- See Also:
-
header
-
payload
-
pad
private final byte[] pad
-
-
Constructor Details
-
EthernetPacket
- Throws:
IllegalRawDataException
-
EthernetPacket
-
-
Method Details
-
newPacket
public static EthernetPacket newPacket(byte[] rawData, int offset, int length) throws IllegalRawDataException A static factory method. This method validates the arguments byByteArrays.validateBounds(byte[], int, int), which may throw exceptions undocumented here.- Parameters:
rawData- rawDataoffset- offsetlength- length- Returns:
- a new EthernetPacket object.
- Throws:
IllegalRawDataException- if parsing the raw data fails.
-
getHeader
Description copied from class:AbstractPacketReturns the Header object representing this packet's header. This subclass have to override this method if the packet represented by the subclass has a header.- Specified by:
getHeaderin interfacePacket- Overrides:
getHeaderin classAbstractPacket- Returns:
- the Header object representing this packet's header. May be null if the header doesn't exist
-
getPayload
Description copied from class:AbstractPacketReturns the Packet object representing this packet's payload. This subclass have to override this method if the packet represented by the subclass has a payload.- Specified by:
getPayloadin interfacePacket- Overrides:
getPayloadin classAbstractPacket- Returns:
- the Packet object representing this packet's payload. May be null if the payload doesn't exist
-
getPad
public byte[] getPad()- Returns:
- pad
-
calcLength
protected int calcLength()Description copied from class:AbstractPacketThis method calculates the valuelength()will return by adding up the header length and the payload length. If you write this subclass which represents a packet with extra parts (e.g. a trailer), you need to override this method.- Overrides:
calcLengthin classAbstractPacket- Returns:
- a calculated length
-
buildRawData
protected byte[] buildRawData()Description copied from class:AbstractPacketThis method builds the valuegetRawData()will return by concatenating the header's raw data and the payload's raw data. If you write this subclass which represents a packet with extra parts (e.g. a trailer), you need to override this method.- Overrides:
buildRawDatain classAbstractPacket- Returns:
- a raw data built
-
buildString
Description copied from class:AbstractPacketThis 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:
buildStringin classAbstractPacket- Returns:
- a string representation of this object
-
getBuilder
Description copied from interface:PacketReturns a new Builder object populated with this object's fields' values.- Specified by:
getBuilderin interfacePacket- Specified by:
getBuilderin classAbstractPacket- Returns:
- a new Builder object populated with this object's fields values
-
equals
Description copied from class:AbstractPacketIndicates 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:
equalsin classAbstractPacket
-
calcHashCode
protected int calcHashCode()Description copied from class:AbstractPacketThis method calculates the valuehashCode()will return using the header's hash code and the payload's hash code. If you write this subclass which represents a packet with extra parts (e.g. a trailer), you need to override this method.- Overrides:
calcHashCodein classAbstractPacket- Returns:
- a calculated hash code value for the object
-