public class IPv4 extends BasePacket
Modifier and Type | Field and Description |
---|---|
protected short |
checksum |
protected int |
destinationAddress |
protected byte |
diffServ |
protected byte |
flags |
protected short |
fragmentOffset |
protected byte |
headerLength |
protected short |
identification |
protected boolean |
isTruncated |
protected byte[] |
options |
protected byte |
protocol |
static byte |
PROTOCOL_ICMP |
static byte |
PROTOCOL_TCP |
static byte |
PROTOCOL_UDP |
static java.util.Map<java.lang.Byte,java.lang.Class<? extends IPacket>> |
protocolClassMap |
protected int |
sourceAddress |
protected short |
totalLength |
protected byte |
ttl |
protected byte |
version |
parent, payload
Constructor and Description |
---|
IPv4()
Default constructor that sets the version to 4.
|
Modifier and Type | Method and Description |
---|---|
IPacket |
deserialize(byte[] data,
int offset,
int length)
Deserializes this packet layer and all possible payloads
|
boolean |
equals(java.lang.Object obj) |
static java.lang.String |
fromIPv4Address(int ipAddress)
Accepts an IPv4 address and returns of string of the form xxx.xxx.xxx.xxx
ie 192.168.0.1
|
static java.lang.String |
fromIPv4AddressCollection(java.util.Collection<java.lang.Integer> ipAddresses)
Accepts a collection of IPv4 addresses as integers and returns a single
String useful in toString method's containing collections of IP
addresses.
|
short |
getChecksum() |
int |
getDestinationAddress() |
byte |
getDiffServ() |
byte |
getFlags() |
short |
getFragmentOffset() |
byte |
getHeaderLength() |
short |
getIdentification() |
byte[] |
getOptions() |
byte |
getProtocol() |
int |
getSourceAddress() |
short |
getTotalLength() |
byte |
getTtl() |
byte |
getVersion() |
int |
hashCode() |
boolean |
isTruncated() |
void |
resetChecksum()
Reset any checksums as needed, and call resetChecksum on all parents
|
byte[] |
serialize()
Serializes the packet.
|
IPv4 |
setChecksum(short checksum) |
IPv4 |
setDestinationAddress(int destinationAddress) |
IPv4 |
setDestinationAddress(java.lang.String destinationAddress) |
IPv4 |
setDiffServ(byte diffServ) |
IPv4 |
setFlags(byte flags) |
IPv4 |
setFragmentOffset(short fragmentOffset) |
IPv4 |
setIdentification(short identification) |
IPv4 |
setOptions(byte[] options) |
IPv4 |
setProtocol(byte protocol) |
IPv4 |
setSourceAddress(int sourceAddress) |
IPv4 |
setSourceAddress(java.lang.String sourceAddress) |
void |
setTruncated(boolean isTruncated) |
IPv4 |
setTtl(byte ttl) |
IPv4 |
setVersion(byte version) |
static int |
toIPv4Address(byte[] ipAddress)
Accepts an IPv4 address in a byte array and returns the corresponding
32-bit integer value.
|
static int |
toIPv4Address(java.lang.String ipAddress)
Accepts an IPv4 address of the form xxx.xxx.xxx.xxx, ie 192.168.0.1 and
returns the corresponding 32 bit integer.
|
static byte[] |
toIPv4AddressBytes(int ipAddress)
Accepts an IPv4 address in the form of an integer and
returns the corresponding byte array.
|
static byte[] |
toIPv4AddressBytes(java.lang.String ipAddress)
Accepts an IPv4 address of the form xxx.xxx.xxx.xxx, ie 192.168.0.1 and
returns the corresponding byte array.
|
static byte[] |
toPortBytes(int port) |
clone, getParent, getPayload, setParent, setPayload
public static final byte PROTOCOL_ICMP
public static final byte PROTOCOL_TCP
public static final byte PROTOCOL_UDP
public static java.util.Map<java.lang.Byte,java.lang.Class<? extends IPacket>> protocolClassMap
protected byte version
protected byte headerLength
protected byte diffServ
protected short totalLength
protected short identification
protected byte flags
protected short fragmentOffset
protected byte ttl
protected byte protocol
protected short checksum
protected int sourceAddress
protected int destinationAddress
protected byte[] options
protected boolean isTruncated
public byte getVersion()
public IPv4 setVersion(byte version)
version
- the version to setpublic byte getHeaderLength()
public byte getDiffServ()
public IPv4 setDiffServ(byte diffServ)
diffServ
- the diffServ to setpublic short getTotalLength()
public short getIdentification()
public boolean isTruncated()
public void setTruncated(boolean isTruncated)
public IPv4 setIdentification(short identification)
identification
- the identification to setpublic byte getFlags()
public IPv4 setFlags(byte flags)
flags
- the flags to setpublic short getFragmentOffset()
public IPv4 setFragmentOffset(short fragmentOffset)
fragmentOffset
- the fragmentOffset to setpublic byte getTtl()
public IPv4 setTtl(byte ttl)
ttl
- the ttl to setpublic byte getProtocol()
public IPv4 setProtocol(byte protocol)
protocol
- the protocol to setpublic short getChecksum()
public IPv4 setChecksum(short checksum)
checksum
- the checksum to setpublic void resetChecksum()
IPacket
resetChecksum
in interface IPacket
resetChecksum
in class BasePacket
public int getSourceAddress()
public IPv4 setSourceAddress(int sourceAddress)
sourceAddress
- the sourceAddress to setpublic IPv4 setSourceAddress(java.lang.String sourceAddress)
sourceAddress
- the sourceAddress to setpublic int getDestinationAddress()
public IPv4 setDestinationAddress(int destinationAddress)
destinationAddress
- the destinationAddress to setpublic IPv4 setDestinationAddress(java.lang.String destinationAddress)
destinationAddress
- the destinationAddress to setpublic byte[] getOptions()
public IPv4 setOptions(byte[] options)
options
- the options to setpublic byte[] serialize()
public IPacket deserialize(byte[] data, int offset, int length)
IPacket
offset
- offset to start deserializing fromlength
- length of the data to deserializepublic static int toIPv4Address(java.lang.String ipAddress)
ipAddress
- public static int toIPv4Address(byte[] ipAddress)
ipAddress
- public static java.lang.String fromIPv4Address(int ipAddress)
ipAddress
- public static java.lang.String fromIPv4AddressCollection(java.util.Collection<java.lang.Integer> ipAddresses)
ipAddresses
- collection of all IP addressespublic static byte[] toIPv4AddressBytes(java.lang.String ipAddress)
ipAddress
- The IP address in the form xx.xxx.xxx.xxx.public static byte[] toIPv4AddressBytes(int ipAddress)
ipAddress
- The IP address as an integer.public static byte[] toPortBytes(int port)
public int hashCode()
hashCode
in class BasePacket
public boolean equals(java.lang.Object obj)
equals
in class BasePacket