public interface Packet extends Cloneable
| Modifier and Type | Method and Description |
|---|---|
Packet |
clone() |
long |
getArrivalTime()
The arrival time of this packet in microseconds relative to epoch
(midnight UTC of January 1, 1970).
|
String |
getName()
Get the name of the packet.
|
Packet |
getNextPacket()
Get the next frame, or null if there is none.
|
Packet |
getPacket(Protocol p)
Find the packet for protocol p.
|
Packet |
getParentPacket()
Almost all packets have a parent, which is the encapsulating protocol.
|
Buffer |
getPayload()
Get the payload of the frame.
|
Protocol |
getProtocol()
Get the protocol of this frame.
|
boolean |
hasProtocol(Protocol p)
Check whether this packet contains a particular protocol.
|
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)
Write this packet to the
OutputStream. |
void |
write(OutputStream out,
Buffer payload)
Writes this packet to the
OutputStream with the supplied payload. |
long getArrivalTime()
SimpleDateFormat 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 stampvoid 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"void write(OutputStream out) throws IOException
OutputStream. Typically, the
OutputStream would be a PcapOutputStream so when writing
packets to this stream they will still be a valid pcap.out - IOExceptionvoid write(OutputStream out, Buffer payload) throws IOException
OutputStream 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.out - payload - IOExceptionPacket clone()
boolean hasProtocol(Protocol p) throws IOException
p - IOException - in case something goes wrong when framing the rest of the
protocol stackProtocol getProtocol()
Packet getPacket(Protocol p) throws IOException, PacketParseException
p - IOException - in case something goes wrong when framing the rest of the
protocol stackPacketParseException - if the next packet can't be parsed by the
framerString getName()
Packet getNextPacket() throws IOException, PacketParseException
IOExceptionPacketParseException - if the next packet can't be parsed by the
framerPacket getParentPacket()
SipPacket is typically a
TransportPacket such as UDPPacket or a TCPPacket.
The parent of a TransportPacket is usually a IPPacket and
so on.Buffer getPayload()
Copyright © 2021. All Rights Reserved.