public final class MACPacketImpl extends AbstractPacket implements MACPacket
| Constructor and Description |
|---|
MACPacketImpl(Protocol protocol,
PCapPacket parent,
Buffer headers,
Buffer payload)
Construct a new
MACPacket based on the supplied headers. |
| Modifier and Type | Method and Description |
|---|---|
MACPacket |
clone() |
static MACPacketImpl |
create(PCapPacket parent,
Buffer headers)
Creates a new
MACPacketImpl and it assumes ethernet II and it
does not check whether or not the ethertype is a known type. |
long |
getArrivalTime()
The arrival time of this packet in microseconds relative to epoch
(midnight UTC of January 1, 1970).
|
String |
getDestinationMacAddress() |
IPPacket |
getNextPacket()
Get the next frame, or null if there is none.
|
Protocol |
getNextProtocol() |
String |
getSourceMacAddress() |
void |
setDestinationMacAddress(String macAddress) |
void |
setSourceMacAddress(String macAddress)
Set the MAC address of this
MACPacket. |
static String |
toHexString(Buffer buffer,
int start,
int length) |
String |
toString() |
void |
verify()
Calling this method will force the packet to completely parse its data
and check so that all the information conforms to whatever rules this
packet needs to follow.
|
void |
write(OutputStream out,
Buffer payload)
Writes this packet to the
OutputStream with the supplied payload. |
checkParent, getName, getPacket, getParentPacket, getPayload, getProtocol, hasProtocol, writeequals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitgetName, getPacket, getParentPacket, getPayload, getProtocol, hasProtocol, writepublic MACPacketImpl(Protocol protocol, PCapPacket parent, Buffer headers, Buffer payload)
MACPacket based on the supplied headers.public static MACPacketImpl create(PCapPacket parent, Buffer headers)
MACPacketImpl and it assumes ethernet II and it
does not check whether or not the ethertype is a known type. This method
should only be used by the internal packet creating functions such as the
TransportPacketFactoryImpl or the framers.parent - headers - public final String getSourceMacAddress()
getSourceMacAddress in interface MACPacketpublic static String toHexString(Buffer buffer, int start, int length) throws IOException
IOExceptionpublic final String getDestinationMacAddress()
getDestinationMacAddress in interface MACPacketpublic void verify()
IPPacket, hardly does anything
in this method but more complex protocols such as SIP (once again), HTTP
etc can spend quite some time verifying everything, which is why you
don't want to do it unless you really have to.
In general, yajpcap has the philosophy of
"assume that everything is ok until things blow up and then deal with it"verify in interface Packetverify in class AbstractPacketpublic long getArrivalTime()
PacketSimpleDateFormat but it can
only handle milliseconds precision (you will have to write your own date
formatter if you want microseconds).
Here is a snippet illustrating how to turn the arrival time of the packet
into a human readable date
Packet p = ...;
SimpleDateFormat formatter = new SimpleDateFormat("yyyy.MM.dd HH:mm:ss.SSS");
Date date = new Date(p.getArrivalTime() / 1000);
System.out.println("Arrival time: " + formatter.format(date));
Note how an integer devision is performed on the arrival time to
"cut off" the microseconds from the time stampgetArrivalTime in interface Packetpublic void write(OutputStream out, Buffer payload) throws IOException
PacketOutputStream with the supplied payload.
You can use this method to e.g. write a raw UDPPacket to the
stream with this payload. Note, if the UDPPacket already had a
payload it will be ignored so use this method with care.write in interface PacketIOExceptionpublic void setSourceMacAddress(String macAddress)
MACPacket.setSourceMacAddress in interface MACPacketpublic void setDestinationMacAddress(String macAddress)
setDestinationMacAddress in interface MACPacketpublic MACPacket clone()
public Protocol getNextProtocol() throws IOException
IOExceptionpublic IPPacket getNextPacket() throws IOException
PacketgetNextPacket in interface PacketIOExceptionCopyright © 2021. All Rights Reserved.