|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--org.opennms.protocols.ip.IPHeader
This class defines a loaded IP header object. It does not allow the user of the class to set any of the values. Nor can a default object be constructed. A copy of an existing header can be created or one can be loaded from a collection of bytes. For more information on the IP header see the book "TCP/IP Illustrated, Volume 1: The Protocols" by W. Richard Stevens.
Field Summary | |
private short |
m_checksum
|
private int |
m_dstAddr
|
private byte |
m_flags
|
private short |
m_fragOffset
|
private byte |
m_hdrlen
|
private short |
m_identity
|
private short |
m_length
|
private byte[] |
m_options
|
private byte |
m_protocol
|
private int |
m_srcAddr
|
private byte |
m_tos
|
private byte |
m_ttl
|
private byte |
m_version
|
Constructor Summary | |
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. |
Method Summary | |
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. |
private static int |
byteToInt(byte b)
Converts a byte to an integer, treating the byte as unsigned. |
private static short |
byteToShort(byte b)
Converts a byte to a short, treating the byte as unsigned. |
private byte[] |
dup(byte[] src)
Duplicates the array of bytes. |
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. |
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. |
private static int |
shortToInt(short s)
Converts a short to an integer, treating the short as unsigned. |
Methods inherited from class java.lang.Object |
|
Field Detail |
private byte m_version
private byte m_hdrlen
private byte m_tos
private short m_length
private short m_identity
private byte m_flags
private short m_fragOffset
private byte m_ttl
private byte m_protocol
private short m_checksum
private int m_srcAddr
private int m_dstAddr
private byte[] m_options
Constructor Detail |
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.InsufficientDataException
- 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.Method Detail |
private byte[] dup(byte[] src)
src
- The source bytes to duplicate.private static short byteToShort(byte b)
b
- The byte to convert.private static int byteToInt(byte b)
b
- The byte to convert.private static int shortToInt(short s)
s
- The short to convert.public byte getVersion()
public int getHeaderLength()
public byte getTypeOfService()
public boolean getTypeOfService(int bit)
bit
- The bit to validate. Valid values are 0 - 7.public int getPacketLength()
public short getIdentity()
public byte getFlags()
public boolean getFlag(int bit)
bit
- The flag to retreive.public short getFragmentOffset()
public byte getTTL()
public byte getProtocol()
public short getChecksum()
public int getSourceAddress()
public int getDestinationAddress()
public byte[] getOptionData()
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.
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |