public final class IPv4PacketImpl extends AbstractPacket implements IPv4Packet
| Constructor and Description |
|---|
IPv4PacketImpl(Packet parent,
Buffer headers,
int options,
Buffer payload) |
| Modifier and Type | Method and Description |
|---|---|
IPv4Packet |
clone() |
long |
getArrivalTime()
The arrival time of this packet in microseconds relative to epoch
(midnight UTC of January 1, 1970).
|
String |
getDestinationIP()
Convenience method for returning the destination IP in a more human readable form.
|
short |
getDSCP() |
short |
getECN() |
short |
getFragmentOffset()
The fragment offset field, measured in units of eight-byte blocks, is 13
bits long and specifies the offset of a particular fragment relative to
the beginning of the original unfragmented IP datagram.
|
int |
getHeaderLength()
The length of the ipv4 headers
|
int |
getIdentification()
Note, this should be treated as a unsigned short.
|
int |
getIpChecksum()
The checksum of the IP-packet.
|
Packet |
getNextPacket()
Get the next frame, or null if there is none.
|
byte[] |
getRawDestinationIP()
Get the raw bytes, either 4 or 16, that represent the destination IP address.
|
int |
getRawDestinationIpInt()
Get the raw destination ip as a 32-bit integer.
|
byte[] |
getRawSourceIP()
Get the raw bytes, either 4 or 16, that represent the source IP.
|
int |
getRawSourceIpInt()
Get the raw source ip as 32-bit integer
Note, these are the raw bits and should be treated as such.
|
String |
getSourceIP()
Convenience method for returning the source IP in a more human readable form.
|
int |
getTimeToLive() |
int |
getTotalIPLength()
This 16-bit field defines the entire packet (fragment) size, including
header and data, in bytes.
|
int |
getVersion()
The version of this ip frame, will always be 4
|
boolean |
isDontFragmentSet()
The DF flag is part of the three-bit flag field and those flags are: (in
order, from high order to low order):
|
boolean |
isFragmented() |
boolean |
isMoreFragmentsSet()
The MF flag is part of the three-bit flag field and those flags are: (in
order, from high order to low order):
|
boolean |
isReservedFlagSet()
The Reserved flag is part of the three-bit flag field and those flags
are: (in order, from high order to low order):
|
void |
reCalculateChecksum()
Whenever we change a value in the IP packet we need to update the
checksum as well.
|
void |
setDestinationIP(byte a,
byte b,
byte c,
byte d) |
void |
setDestinationIP(int a,
int b,
int c,
int d)
Setting an IPv4 address the fast way! Specify each part separately.
|
void |
setDestinationIP(String destinationIP)
Set the destination IP of this
IPv4Packet. |
void |
setSourceIP(byte a,
byte b,
byte c,
byte d)
Setting an IPv4 address the fast(est?) way! Specify each part separately.
|
void |
setSourceIP(int a,
int b,
int c,
int d)
Setting an IPv4 address the fast way! Specify each part separately.
|
void |
setSourceIP(String sourceIp)
Set the source IP of this
IPv4Packet. |
void |
setTotalLength(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.
|
boolean |
verifyIpChecksum() |
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 int getIpChecksum()
IPv4PacketgetIpChecksum in interface IPv4Packetpublic byte[] getRawSourceIP()
IPPacketgetRawSourceIP in interface IPPacketpublic int getRawSourceIpInt()
public String getSourceIP()
getSourceIP in interface IPPacketpublic byte[] getRawDestinationIP()
IPPacketgetRawDestinationIP in interface IPPacketpublic int getRawDestinationIpInt()
public String getDestinationIP()
getDestinationIP in interface IPPacketpublic 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 int getTotalIPLength()
IPPacketgetTotalIPLength in interface IPPacketpublic void setTotalLength(int length)
public void setSourceIP(int a,
int b,
int c,
int d)
IPv4Packet#setSourceIP(192, 168, 0, 100)setSourceIP in interface IPv4Packeta - the first part of the IPv4 address, e.g. 192b - the second part of the IPv4 address, e.g. 168c - the third part of the IPv4 address, e.g. 0d - the fourth part of the IPv4 address, e.g. 100public void setSourceIP(byte a,
byte b,
byte c,
byte d)
IPv4PacketsetSourceIP in interface IPv4Packetpublic void setDestinationIP(int a,
int b,
int c,
int d)
IPv4Packet#setSourceIP(192, 168, 0, 100)setDestinationIP in interface IPv4Packeta - the first part of the IPv4 address, e.g. 192b - the second part of the IPv4 address, e.g. 168c - the third part of the IPv4 address, e.g. 0d - the fourth part of the IPv4 address, e.g. 100public void setDestinationIP(byte a,
byte b,
byte c,
byte d)
setDestinationIP in interface IPv4Packetpublic void setSourceIP(String sourceIp)
IPv4PacketIPv4Packet. Note, using
IPv4Packet.setSourceIP(int, int, int, int) will be must faster so try and
use it instead.setSourceIP in interface IPPacketsetSourceIP in interface IPv4Packetpublic void setDestinationIP(String destinationIP)
IPv4PacketIPv4Packet. Note, using
IPv4Packet.setDestinationIP(int, int, int, int) will be must faster so try
and use it instead.setDestinationIP in interface IPPacketsetDestinationIP in interface IPv4Packetpublic void reCalculateChecksum()
reCalculateChecksum in interface IPv4Packetpublic boolean verifyIpChecksum()
verifyIpChecksum in interface IPv4Packetpublic IPv4Packet clone()
clone in interface IPPacketclone in interface IPv4Packetclone in interface Packetclone in class AbstractPacketpublic Packet getNextPacket() throws IOException
PacketgetNextPacket in interface PacketIOExceptionpublic int getVersion()
getVersion in interface IPPacketpublic int getHeaderLength()
getHeaderLength in interface IPPacketpublic boolean isFragmented()
isFragmented in interface IPPacketisFragmented in interface IPv4Packetpublic boolean isReservedFlagSet()
bit 0: Reserved; must be zero. bit 1: Don't Fragment (DF) bit 2: More Fragments (MF)(source http://en.wikipedia.org/wiki/IPv4)
isReservedFlagSet in interface IPv4Packetpublic boolean isDontFragmentSet()
bit 0: Reserved; must be zero. bit 1: Don't Fragment (DF) bit 2: More Fragments (MF)If the DF flag is set, and fragmentation is required to route the packet, then the packet is dropped. This can be used when sending packets to a host that does not have sufficient resources to handle fragmentation. It can also be used for Path MTU Discovery, either automatically by the host IP software, or manually using diagnostic tools such as ping or traceroute. For unfragmented packets, the MF flag is cleared. For fragmented packets, all fragments except the last have the MF flag set. The last fragment has a non-zero Fragment Offset field, differentiating it from an unfragmented packet. (source http://en.wikipedia.org/wiki/IPv4)
isDontFragmentSet in interface IPv4Packetpublic boolean isMoreFragmentsSet()
bit 0: Reserved; must be zero. bit 1: Don't Fragment (DF) bit 2: More Fragments (MF)If the DF flag is set, and fragmentation is required to route the packet, then the packet is dropped. This can be used when sending packets to a host that does not have sufficient resources to handle fragmentation. It can also be used for Path MTU Discovery, either automatically by the host IP software, or manually using diagnostic tools such as ping or traceroute. For unfragmented packets, the MF flag is cleared. For fragmented packets, all fragments except the last have the MF flag set. The last fragment has a non-zero Fragment Offset field, differentiating it from an unfragmented packet. (source http://en.wikipedia.org/wiki/IPv4)
isMoreFragmentsSet in interface IPv4Packetpublic short getFragmentOffset()
IPv4PacketgetFragmentOffset in interface IPPacketgetFragmentOffset in interface IPv4Packetpublic short getDSCP()
getDSCP in interface IPv4Packetpublic short getECN()
getECN in interface IPv4Packetpublic int getTimeToLive()
getTimeToLive in interface IPv4Packetpublic int getIdentification()
IPPacketgetIdentification in interface IPPacketCopyright © 2021. All Rights Reserved.