OpenNMS API 1.2.9

## org.opennms.protocols.icmp
Class ICMPHeader

    java.lang.Object
      org.opennms.protocols.icmp.ICMPHeader

Direct Known Subclasses:
  AddressMaskReply, AddressMaskRequest, ErrorMessage, Packet, TimestampReply, TimestampRequest

public class ICMPHeader
extends java.lang.Object

This class defines Internet Control Message Protocol header. The header defines the first 8 bytes of any ICMP message. Some ICMP messages may need to override the format of the second 4 bytes, the first 4 bytes are fixed by the RFC. The minimum message size for any ICMP message is 8 bytes.

Version:
  0.1
Author:
  Brian Weaver <weave@oculan.com>

Field Summary
`static byte` `CODE_BAD_IP_HEADER`
`static byte` `CODE_COMMUNICATIONS_ADMIN_PROHIBITIED`
`static byte` `CODE_DESTINATION_HOST_ADMIN_PROHIBITED`
`static byte` `CODE_DESTINATION_HOST_UNKNOWN`
`static byte` `CODE_DESTINATION_NETWORK_ADMIN_PROHIBITED`
`static byte` `CODE_DESTINATION_NETWORK_UNKNOWN`
`static byte` `CODE_FRAGMENTATION_NEEDED`
`static byte` `CODE_HOST_PRECEDENCE_VIOLATION`
`static byte` `CODE_HOST_UNREACHABLE`
`static byte` `CODE_HOST_UNREACHABLE_FOR_TOS`
`static byte` `CODE_NETWORK_UNREACHABLE`
`static byte` `CODE_NETWORK_UNREACHABLE_FOR_TOS`
`static byte` `CODE_PORT_UNREACHABLE`
`static byte` `CODE_PRECEDENCE_CUTOFF_IN_EFFECT`
`static byte` `CODE_PROTOCOL_UNREACHABLE`
`static byte` `CODE_REDIRECT_FOR_HOST`
`static byte` `CODE_REDIRECT_FOR_NETWORK`
`static byte` `CODE_REDIRECT_FOR_TYPE_OF_SERVICE_AND_HOST`
`static byte` `CODE_REDIRECT_FOR_TYPE_OF_SERVICE_AND_NETWORK`
`static byte` `CODE_REQUIRED_OPTION_MISSING`
`static byte` `CODE_SOURCE_HOST_ISOLATED`
`static byte` `CODE_SOURCE_ROUTE_FAILED`
`static byte` `CODE_TTL_EQ_ZERO_IN_REASSEMBLY`
`static byte` `CODE_TTL_EQ_ZERO_IN_TRANSIT`
`private short` `m_checksum`
`private byte` `m_code`
`private short` `m_ident`
`private short` `m_sequence`
`private byte` `m_type`
`private static short` `sm_seq` Used to generate the sequence numbers for the class.
`static byte` `TYPE_ADDRESS_MASK_REPLY`
`static byte` `TYPE_ADDRESS_MASK_REQUEST`
`static byte` `TYPE_DESTINATION_UNREACHABLE`
`static byte` `TYPE_ECHO_REPLY`
`static byte` `TYPE_ECHO_REQUEST`
`static byte` `TYPE_INFORMATION_REPLY`
`static byte` `TYPE_INFORMATION_REQUEST`
`static byte` `TYPE_PARAMETER_PROBLEM`
`static byte` `TYPE_REDIRECT`
`static byte` `TYPE_ROUTER_ADVERTISEMENT`
`static byte` `TYPE_ROUTER_SOLICITATION`
`static byte` `TYPE_SOURCE_QUENCH`
`static byte` `TYPE_TIME_EXCEEDED`
`static byte` `TYPE_TIMESTAMP_REPLY`
`static byte` `TYPE_TIMESTAMP_REQUEST`

Constructor Summary
`ICMPHeader()` Initializes the header to a default value.
`ICMPHeader(byte type)` Initializes the header using the specified type.
`ICMPHeader(byte[] data, int offset)` Constructs a new ICMP header based upon the data contained in the buffer.
`ICMPHeader(byte type, byte code)` Initializes the header with the specified type and code values.
`ICMPHeader(byte type, byte code, short checksum, short identity, short sequence)` Constructs an ICMP header with the specified header fields.
`ICMPHeader(ICMPHeader second)` Constructs a duplicate ICMP header that is identical to the passed ICMPHeader object.

Method Summary
`protected static int` `byteToInt(byte b)` Converts a byte to an integer.
`protected static short` `byteToShort(byte b)` Converts a byte to a short.
`void` `computeChecksum()` Provides the default checksum implementation for the ICMP header.
`protected void` `computeChecksum(OC16ChecksumProducer summer)` Used by derived classes to begin the checksum process.
`short` `getChecksum()` Used to retrieve the current checksum for the header.
`byte` `getCode()` Returns the 8-bit code for the ICMP packet.
`short` `getIdentity()` Used to get the headers user defined identity.
`static int` `getNetworkSize()` Returns the number of bytes required to read/write an icmp header.
`short` `getSequenceId()` Returns the sequence identifier for the ICMP header.
`byte` `getType()` Returns the 8-bit type code for the ICMP packet.
`boolean` `isEchoReply()` Used to test to see if the header is an echo reply message.
`boolean` `isEchoRequest()` Used to test to see if the header is an echo request message.
`protected int` `loadFromBuffer(byte[] buf, int offset)` Reads the ICMP header from the specified buffer and sets the internal fields equal to the data.
`static short` `nextSequenceId()` Returns the next 16-bit sequence identifier for the class.
`protected void` `setChecksum(short sum)`
`void` `setCode(byte code)` Sets the 8-bit code for the ICMP packet
`void` `setIdentity(short identity)` Sets the header's 16-bit user defined identity value.
`short` `setNextSequenceId()` Gets the next global identifier and sets the value in the object.
`void` `setSequenceId(short id)` Sets the headers 16-bit sequence identifier.
`protected void` `setType(byte type)` Sets the 8-bit type code for the packet.
`protected int` `storeToBuffer(byte[] buf, int offset)` Writes the ICMP header out to the specified buffer at the starting offset.
`byte[]` `toBytes()` Converts the object to a string of bytes.

Methods inherited from class java.lang.Object
`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

Field Detail

### TYPE_ECHO_REPLY

    public static final byte TYPE_ECHO_REPLY

See Also:
  Constant Field Values

### TYPE_DESTINATION_UNREACHABLE

    public static final byte TYPE_DESTINATION_UNREACHABLE

See Also:
  Constant Field Values

### CODE_NETWORK_UNREACHABLE

    public static final byte CODE_NETWORK_UNREACHABLE

See Also:
  Constant Field Values

### CODE_HOST_UNREACHABLE

    public static final byte CODE_HOST_UNREACHABLE

See Also:
  Constant Field Values

### CODE_PROTOCOL_UNREACHABLE

    public static final byte CODE_PROTOCOL_UNREACHABLE

See Also:
  Constant Field Values

### CODE_PORT_UNREACHABLE

    public static final byte CODE_PORT_UNREACHABLE

See Also:
  Constant Field Values

### CODE_FRAGMENTATION_NEEDED

    public static final byte CODE_FRAGMENTATION_NEEDED

See Also:
  Constant Field Values

### CODE_SOURCE_ROUTE_FAILED

    public static final byte CODE_SOURCE_ROUTE_FAILED

See Also:
  Constant Field Values

### CODE_DESTINATION_NETWORK_UNKNOWN

    public static final byte CODE_DESTINATION_NETWORK_UNKNOWN

See Also:
  Constant Field Values

### CODE_DESTINATION_HOST_UNKNOWN

    public static final byte CODE_DESTINATION_HOST_UNKNOWN

See Also:
  Constant Field Values

### CODE_SOURCE_HOST_ISOLATED

    public static final byte CODE_SOURCE_HOST_ISOLATED

See Also:
  Constant Field Values

### CODE_DESTINATION_NETWORK_ADMIN_PROHIBITED

    public static final byte CODE_DESTINATION_NETWORK_ADMIN_PROHIBITED

See Also:
  Constant Field Values

### CODE_DESTINATION_HOST_ADMIN_PROHIBITED

    public static final byte CODE_DESTINATION_HOST_ADMIN_PROHIBITED

See Also:
  Constant Field Values

### CODE_NETWORK_UNREACHABLE_FOR_TOS

    public static final byte CODE_NETWORK_UNREACHABLE_FOR_TOS

See Also:
  Constant Field Values

### CODE_HOST_UNREACHABLE_FOR_TOS

    public static final byte CODE_HOST_UNREACHABLE_FOR_TOS

See Also:
  Constant Field Values

### CODE_COMMUNICATIONS_ADMIN_PROHIBITIED

    public static final byte CODE_COMMUNICATIONS_ADMIN_PROHIBITIED

See Also:
  Constant Field Values

### CODE_HOST_PRECEDENCE_VIOLATION

    public static final byte CODE_HOST_PRECEDENCE_VIOLATION

See Also:
  Constant Field Values

### CODE_PRECEDENCE_CUTOFF_IN_EFFECT

    public static final byte CODE_PRECEDENCE_CUTOFF_IN_EFFECT

See Also:
  Constant Field Values

### TYPE_SOURCE_QUENCH

    public static final byte TYPE_SOURCE_QUENCH

See Also:
  Constant Field Values

### TYPE_REDIRECT

    public static final byte TYPE_REDIRECT

See Also:
  Constant Field Values

### CODE_REDIRECT_FOR_NETWORK

    public static final byte CODE_REDIRECT_FOR_NETWORK

See Also:
  Constant Field Values

### CODE_REDIRECT_FOR_HOST

    public static final byte CODE_REDIRECT_FOR_HOST

See Also:
  Constant Field Values

### CODE_REDIRECT_FOR_TYPE_OF_SERVICE_AND_NETWORK

    public static final byte CODE_REDIRECT_FOR_TYPE_OF_SERVICE_AND_NETWORK

See Also:
  Constant Field Values

### CODE_REDIRECT_FOR_TYPE_OF_SERVICE_AND_HOST

    public static final byte CODE_REDIRECT_FOR_TYPE_OF_SERVICE_AND_HOST

See Also:
  Constant Field Values

### TYPE_ECHO_REQUEST

    public static final byte TYPE_ECHO_REQUEST

See Also:
  Constant Field Values

### TYPE_ROUTER_ADVERTISEMENT

    public static final byte TYPE_ROUTER_ADVERTISEMENT

See Also:
  Constant Field Values

### TYPE_ROUTER_SOLICITATION

    public static final byte TYPE_ROUTER_SOLICITATION

See Also:
  Constant Field Values

### TYPE_TIME_EXCEEDED

    public static final byte TYPE_TIME_EXCEEDED

See Also:
  Constant Field Values

### CODE_TTL_EQ_ZERO_IN_TRANSIT

    public static final byte CODE_TTL_EQ_ZERO_IN_TRANSIT

See Also:
  Constant Field Values

### CODE_TTL_EQ_ZERO_IN_REASSEMBLY

    public static final byte CODE_TTL_EQ_ZERO_IN_REASSEMBLY

See Also:
  Constant Field Values

### TYPE_PARAMETER_PROBLEM

    public static final byte TYPE_PARAMETER_PROBLEM

See Also:
  Constant Field Values

### CODE_BAD_IP_HEADER

    public static final byte CODE_BAD_IP_HEADER

See Also:
  Constant Field Values

### CODE_REQUIRED_OPTION_MISSING

    public static final byte CODE_REQUIRED_OPTION_MISSING

See Also:
  Constant Field Values

### TYPE_TIMESTAMP_REQUEST

    public static final byte TYPE_TIMESTAMP_REQUEST

See Also:
  Constant Field Values

### TYPE_TIMESTAMP_REPLY

    public static final byte TYPE_TIMESTAMP_REPLY

See Also:
  Constant Field Values

### TYPE_INFORMATION_REQUEST

    public static final byte TYPE_INFORMATION_REQUEST

See Also:
  Constant Field Values

### TYPE_INFORMATION_REPLY

    public static final byte TYPE_INFORMATION_REPLY

See Also:
  Constant Field Values

### TYPE_ADDRESS_MASK_REQUEST

    public static final byte TYPE_ADDRESS_MASK_REQUEST

See Also:
  Constant Field Values

### TYPE_ADDRESS_MASK_REPLY

    public static final byte TYPE_ADDRESS_MASK_REPLY

See Also:
  Constant Field Values

### m_type

    private byte m_type

### m_code

    private byte m_code

### m_checksum

    private short m_checksum

### m_ident

    private short m_ident

### m_sequence

    private short m_sequence

### sm_seq

    private static short sm_seq

  Used to generate the sequence numbers for the class. This number is generated application wide.

Constructor Detail

### ICMPHeader

    public ICMPHeader()

  Initializes the header to a default value.

### ICMPHeader

    public ICMPHeader(byte type)

  Initializes the header using the specified type.

Parameters:
  `type` - The header type.

### ICMPHeader

    public ICMPHeader(byte type,
                      byte code)

  Initializes the header with the specified type and code values.

Parameters:
  `type` - The type value for the header
  `code` - The code value for the header

### ICMPHeader

    public ICMPHeader(byte type,
                      byte code,
                      short checksum,
                      short identity,
                      short sequence)

  Constructs an ICMP header with the specified header fields.

Parameters:
  `type` - The 8-bit ICMP type.
  `code` - The 8-bit ICMP code.
  `checksum` - The 16-bit checksum header.
  `identity` - The 16-bit identity (user).
  `sequence` - The 16-bit sequence id.

### ICMPHeader

    public ICMPHeader(ICMPHeader second)

  Constructs a duplicate ICMP header that is identical to the passed ICMPHeader object.

Parameters:
  `second` - The object to duplicate.

### ICMPHeader

    public ICMPHeader(byte[] data,
                      int offset)

  Constructs a new ICMP header based upon the data contained in the buffer. The buffer is decode in network byte ordering (big-endin) and must be at least a `minimum`number of bytes available to be decoded.

  If there is an insufficent amount of data to decode a header then an exception is thrown.

Parameters:
  `data` - The data buffer containing the header
  `offset` - The offset of the header in the buffer
Throws:
  `java.lang.IndexOutOfBoundsException` - Thrown if there is not enough data to construct the header.

Method Detail

### nextSequenceId

    public static final short nextSequenceId()

  Returns the next 16-bit sequence identifier for the class. The method is synchronized to prevent duplicate identifiers from being issued. depending on the number of classes and how often the method is called it will eventually wrap. When the value wraps back to zero, a random number is generated and may cause a collision with an existing identifier. The probability is low, but possible.

  Returns:
    The next 16-bit sequence number, may be negative.

### byteToShort

    protected static short byteToShort(byte b)

  Converts a byte to a short.

  Parameters:
    `b` - The byte to convert.
  Returns:
    The converted byte.

### byteToInt

    protected static int byteToInt(byte b)

  Converts a byte to an integer.

  Parameters:
    `b` - The byte to convert.
  Returns:
    The converted byte.

### getType

    public final byte getType()

  Returns the 8-bit type code for the ICMP packet.

  Returns:
    The ICMP type.

### setType

    protected void setType(byte type)

  Sets the 8-bit type code for the packet.

  Parameters:
    `type` - The new ICMP type.

### getCode

    public final byte getCode()

  Returns the 8-bit code for the ICMP packet.

  Returns:
    The ICMP code.

### setCode

    public final void setCode(byte code)

  Sets the 8-bit code for the ICMP packet

  Parameters:
    `code` - The new ICMP code.

### getSequenceId

    public final short getSequenceId()

  Returns the sequence identifier for the ICMP header.

  Returns:
    The 16-bit sequence identifier.

### setNextSequenceId

    public final short setNextSequenceId()

  Gets the next global identifier and sets the value in the object. In addition the new sequence identifier is returned.

  Returns:
    The new 16-bit sequence identifier.

### setSequenceId

    public final void setSequenceId(short id)

  Sets the headers 16-bit sequence identifier.

  Parameters:
    `id` - The new 16-bit sequence id.

### getIdentity

    public final short getIdentity()

  Used to get the headers user defined identity.

  Returns:
    The 16-bit identity.

### setIdentity

    public final void setIdentity(short identity)

  Sets the header's 16-bit user defined identity value.

  Parameters:
    `identity` - The header's new identity.

### getChecksum

    public final short getChecksum()

  Used to retrieve the current checksum for the header. This is the last checksum computed for the header (or it's derived classes). To compute the new checksum a call to the method computeChecksum() must be called.

  Returns:
    The 16-bit one's compliment checksum.

### setChecksum

    protected void setChecksum(short sum)

### computeChecksum

    public void computeChecksum()

  Provides the default checksum implementation for the ICMP header. It MUST be overriden by any derived classes to ensure that the checksum includes the dervived class data. Once the checksum is calculated, a call to the method getChecksum() will return the calculated sum.

### computeChecksum

    protected void computeChecksum(OC16ChecksumProducer summer)

  Used by derived classes to begin the checksum process. The process involves setting the checksum to zero and then performing the checksum over the various values.

  Parameters:
    `summer` - The checksum builder object.

### storeToBuffer

    protected int storeToBuffer(byte[] buf,
                                int offset)

  Writes the ICMP header out to the specified buffer at the starting offset. If the buffer does not have sufficent data to store the information then an IndexOutOfBoundsException is thrown.

  Parameters:
    `buf` - The storage buffer.
    `offset` - The location to start in buf.
  Returns:
    The new offset after storing to the buffer.
  Throws:
    `java.lang.IndexOutOfBoundsException` - Thrown if the buffer does not have enough storage space.

### loadFromBuffer

    protected int loadFromBuffer(byte[] buf,
                                 int offset)

  Reads the ICMP header from the specified buffer and sets the internal fields equal to the data. If the buffer does not have sufficent data to restore the header then an IndexOutOfBoundsExceptoin is thrown by the method.

  Parameters:
    `buf` - The buffer to read the data from.
    `offset` - The offset to start reading data.
  Returns:
    The new offset after reading the data.
  Throws:
    `java.lang.IndexOutOfBoundsException` - is thrown if there is not sufficent data in the buffer.

### getNetworkSize

    public static int getNetworkSize()

  Returns the number of bytes required to read/write an icmp header. A header is composed of a fixed size number of byte. This is not expected to change, but this method allows derived classes to query the number of bytes for reading/writing an icmp header. Thus should the standard ever change, the derived class should be able to dynamically handle the change.

  Returns:
    The number of bytes required to read/write an icmp header.

### isEchoReply

    public final boolean isEchoReply()

  Used to test to see if the header is an echo reply message. If it is an echo reply message then true is returned.

  Returns:
    True if the header marks an echo reply.

### isEchoRequest

    public final boolean isEchoRequest()

  Used to test to see if the header is an echo request message. If it is an echo request message then true is returned.

  Returns:
    True if the header marks an echo request.

### toBytes

    public byte[] toBytes()

  Converts the object to a string of bytes.

OpenNMS API 1.2.9

Generated by ranger on May 19 2007 2335.