public class IPHeader extends Object
Modifier and Type | Class and Description |
---|---|
static class |
IPHeader.EndOfOptions
This class is used to represent the End-Of-Option list in the
IP header.
|
static class |
IPHeader.LooseSourceRouteOption
This class represents the loose source routing options that may be part
of an IP header.
|
static class |
IPHeader.Option
The Option class is used as the base class for any options that are at
the end of the IP header.
|
static class |
IPHeader.RouteOption
This class represents routing options that may be part of an IP header.
|
static class |
IPHeader.RouteRecordOption
This class represents the route record option that may be part of an IP
header.
|
static class |
IPHeader.StrictSourceRouteOption
This class represents the strict source routing options that may be part
of an IP header.
|
Modifier and Type | Field and Description |
---|---|
static int |
FLAGS_DONT_FRAGMENT
Don't fragment datagrams field
|
static int |
FLAGS_MASK
The mask of the flags in the fragment field of the IP header
|
static int |
FLAGS_MORE_FRAGMENTS
More fragments are necessary to reassemble this packet
|
static int |
IP_VERSION
The supported version of the IP header
|
static int |
OPTION_CLASS_MASK
The option class mask
|
static int |
OPTION_COPY_MASK
The bit(s) that define if the optiosn are copied to each datagram when
(or if) it is fragmented.
|
static int |
OPTION_ID_EOO
Option identifier for the End Of Options List option.
|
static int |
OPTION_ID_LOOSE_SOURCE_ROUTING
Option identifier for the loose source routing option
|
static int |
OPTION_ID_ROUTE_RECORD
Option identifier for the route record option
|
static int |
OPTION_ID_STRICT_SOURCE_ROUTING
Option identifer for the the strict source routing option
|
static int |
OPTION_NUMBER_MASK
The option number mask
|
static int |
TOS_DELAY_LOW
Minimize the delay when handling packets.
|
static int |
TOS_DELAY_MASK
TOS delay mask as defined by RFC 791.
|
static int |
TOS_DELAY_NORMAL
Normal packet handling
|
static int |
TOS_PRECEDENCE_CRITICAL_ECP
Critical/ECP TOS.
|
static int |
TOS_PRECEDENCE_FLASH
Flash TOS.
|
static int |
TOS_PRECEDENCE_FLASH_OVERRIDE
Flash Override TOS.
|
static int |
TOS_PRECEDENCE_IMMEDIATE
Immediate TOS.
|
static int |
TOS_PRECEDENCE_INTERNETWORK_CONTROL
Internetworking Control TOS.
|
static int |
TOS_PRECEDENCE_MASK
The Type-Of-Service mask.
|
static int |
TOS_PRECEDENCE_NETWORK_CRITICAL
Network Critical TOS.
|
static int |
TOS_PRECEDENCE_PRIORITY
Priority TOS.
|
static int |
TOS_PRECEDENCE_ROUTINE
Routine TOS.
|
static int |
TOS_RELIBILITY_HIGH
High Reliability requested.
|
static int |
TOS_RELIBILITY_MASK
Packet reliablity mask.
|
static int |
TOS_RELIBILITY_NORMAL
Normal reliability requrested
|
static int |
TOS_RESERVED_MASK
Mask of the reseered bits.
|
static int |
TOS_THROUGHPUT_HIGH
High throughput requested
|
static int |
TOS_THROUGHPUT_MASK
TOS Throughput mask
|
static int |
TOS_THROUGHPUT_NORMAL
Normal throughput requested
|
Constructor and Description |
---|
IPHeader()
Constructs a basic IP header, but the header is not valid
until a large part of the information is configured.
|
IPHeader(byte[] header,
int offset)
Constructs a new IPHeader object from the passed data buffer.
|
IPHeader(IPHeader second)
Constructs a new IP Header object that is identical to the passed
IPHeader.
|
Modifier and Type | Method and Description |
---|---|
void |
addOption(IPHeader.Option opt)
Adds an option to the IP header.
|
static String |
addressToString(byte[] buf)
Converts the passed IPv4 address buffer to a dotted decimal IP address
string.
|
static String |
addressToString(int ipv4Addr)
Converts the passed 32-bit IPv4 address to a dotted decimal IP address
string.
|
short |
getChecksum()
Gets the 16-bit ones compliment checksum for the IP header.
|
int |
getDestinationAddress()
Returns the dotted decimal string address of the destination IP address.
|
boolean |
getFlag(int bit)
Used to get an individual flag from the flags field.
|
byte |
getFlags()
Used to get the 3-bit flags from the header.
|
short |
getFragmentOffset()
Returns the 13-bit fragment offset field from the IP header.
|
int |
getHeaderLength()
Used to get the current length of the IP Header.
|
short |
getIdentity()
Used to retreive the 16-bit identity of the header.
|
byte[] |
getOptionData()
Retrieves the IP header options from the header.
|
List<IPHeader.Option> |
getOptions()
Returns a list of options that are associated with the IP header.
|
int |
getPacketLength()
Returns the length of the IP packet, including the header, in bytes.
|
byte |
getProtocol()
Gets the protocol for the IP datagram.
|
int |
getSourceAddress()
Returns the dotted decimal string address of the source IP address.
|
byte |
getTTL()
Gets the 8-bit Time To Live (TTL) of the packet.
|
byte |
getTypeOfService()
Retreives the current TOS field from the header.
|
boolean |
getTypeOfService(int bit)
Use to test individual bits in the TOS fields.
|
byte |
getVersion()
Used to retreive the current version of the IP Header.
|
void |
setChecksum(short sum)
Sets the checksum for the IP header.
|
void |
setDestinationAddress(int addr)
Sets the IP headers destination address.
|
void |
setFlags(byte flags)
Sets the flags contained in the upper 3 bits of the short value for the
fragmentation offset.
|
void |
setFragmentOffset(short offset)
Sets the fragmentation index for this packet
|
void |
setIdentity(short ident)
Sets the identity of the IP header
|
void |
setOptionData(byte[] options)
Sets the current option data for the header.
|
void |
setPacketLength(short length)
Sets the length for IP packet, including the header.
|
void |
setProtocol(byte protocol)
Sets the protocol for the IP header.
|
void |
setSourceAddr(int addr)
Sets the IP headers source address.
|
void |
setTTL(byte ttl)
Sets the time to live for the IP header
|
void |
setTypeOfService(byte tos)
Sets the TOS flags for the IP header.
|
int |
writeBytes(byte[] data,
int offset)
Stores the IP header as an array of bytes into the passed data buffer.
|
public static final int IP_VERSION
public static final int TOS_PRECEDENCE_MASK
public static final int TOS_PRECEDENCE_NETWORK_CRITICAL
public static final int TOS_PRECEDENCE_INTERNETWORK_CONTROL
public static final int TOS_PRECEDENCE_CRITICAL_ECP
public static final int TOS_PRECEDENCE_FLASH_OVERRIDE
public static final int TOS_PRECEDENCE_FLASH
public static final int TOS_PRECEDENCE_IMMEDIATE
public static final int TOS_PRECEDENCE_PRIORITY
public static final int TOS_PRECEDENCE_ROUTINE
public static final int TOS_DELAY_MASK
public static final int TOS_DELAY_LOW
public static final int TOS_DELAY_NORMAL
public static final int TOS_THROUGHPUT_MASK
public static final int TOS_THROUGHPUT_HIGH
public static final int TOS_THROUGHPUT_NORMAL
public static final int TOS_RELIBILITY_MASK
public static final int TOS_RELIBILITY_HIGH
public static final int TOS_RELIBILITY_NORMAL
public static final int TOS_RESERVED_MASK
public static final int FLAGS_MASK
public static final int FLAGS_DONT_FRAGMENT
public static final int FLAGS_MORE_FRAGMENTS
public static final int OPTION_COPY_MASK
public static final int OPTION_CLASS_MASK
public static final int OPTION_NUMBER_MASK
public static final int OPTION_ID_EOO
public static final int OPTION_ID_LOOSE_SOURCE_ROUTING
public static final int OPTION_ID_STRICT_SOURCE_ROUTING
public static final int OPTION_ID_ROUTE_RECORD
public IPHeader()
public IPHeader(IPHeader second)
second
- The object to duplicate.public IPHeader(byte[] header, int offset)
header
- The buffer containing the headeroffset
- The offset into the buffer where the IP header is located.IndexOutOfBoundsException
- This exception is thrown if the minimum number of bytes
are not present to represent an IPHeader object.UnknownIPVersionException
- Thrown if the format of the version is unknown.public byte getVersion()
public int getHeaderLength()
public byte getTypeOfService()
public void setTypeOfService(byte tos)
tos
- The new TOS for the IP headerpublic boolean getTypeOfService(int bit)
bit
- The bit to validate. Valid values are 0 - 7.public int getPacketLength()
public void setPacketLength(short length)
length
- The length of the IP header plus the data contained withinpublic short getIdentity()
public void setIdentity(short ident)
ident
- The new identity of the IP headerpublic byte getFlags()
public void setFlags(byte flags)
flags
- The flag bits, set in the lower 3 bits of the value.public boolean getFlag(int bit)
bit
- The flag to retreive.public short getFragmentOffset()
public void setFragmentOffset(short offset)
public byte getTTL()
public void setTTL(byte ttl)
public byte getProtocol()
public void setProtocol(byte protocol)
protocol
- The IP protocol.public short getChecksum()
public void setChecksum(short sum)
sum
- The IP header checksum.public int getSourceAddress()
public void setSourceAddr(int addr)
addr
- The soruce address for the header.public int getDestinationAddress()
public void setDestinationAddress(int addr)
addr
- The destination addresspublic byte[] getOptionData()
public void setOptionData(byte[] options)
options
- The new options data.public List<IPHeader.Option> getOptions() throws InstantiationException
InstantiationException
public void addOption(IPHeader.Option opt)
opt
- The option to add to the header.public int writeBytes(byte[] data, int offset)
data
- The location to write the dataoffset
- The offset to start storing information.public static String addressToString(int ipv4Addr)
ipv4Addr
- The 32-bit addresspublic static String addressToString(byte[] buf)
buf
- The 4 byte bufferIllegalArgumentException
- Thrown if the buffer is not exactly 4 bytes in length.Copyright © 2002–2023 The OpenNMS Group, Inc.. All rights reserved.