org.opennms.protocols.icmpd
Class DataRecvMessage

java.lang.Object
  |
  +--org.opennms.protocols.icmpd.MessageHeader
        |
        +--org.opennms.protocols.icmpd.DataRecvMessage

public final class DataRecvMessage
extends MessageHeader

The message class for receiving ICMP infomation from the icmp daemon. The basic message begins with an eight byte header. The header consist of a type, code, sequence number, length, and reserved field. The remain fields are specific to the received message.

 +--------+--------+----------------+
 | Type   |  Code  |     Sequence # |
 +--------+--------+----------------+
 |    Length       |   IP Hdr Len   |
 +-----------------+----------------+
 |             IP HEADER            |
 |                                  |
 +----------------------------------+
 |        ICMP MESSAGE LENGTH       |
 +----------------------------------+
 |           ICMP DATA              |
 |                                  |
 +----------------------------------+
 


Field Summary
static byte CODE
          The class code
private  byte[] m_icmp
           
private  int m_icmpLen
           
private  byte[] m_ipHeader
           
static byte TYPE
          The class type.
 
Fields inherited from class org.opennms.protocols.icmpd.MessageHeader
m_code, m_length, m_reserved, m_sequence, m_type, sm_seq, TYPE_CONTROL, TYPE_DATA
 
Constructor Summary
  DataRecvMessage()
          Constructs a default message with a blank IP header and no data.
  DataRecvMessage(byte[] header, byte[] icmp)
          Constructs a new received message with the specified header and icmp data.
(package private) DataRecvMessage(MessageHeader hdr, InputStream istream)
          Constructs a new data recevied object with the specified header and reads the remaining information from the input stream.
 
Method Summary
private  void calculateLength()
          calcuates the length of the packet based on the encapsulate data.
 byte[] getICMPData()
          Returns the array of bytes that is the ICMP message.
 int getICMPLength()
          Returns the length of valid data in the ICMP byte array.
 byte[] getIPHeader()
          Returns the array of information that is the IP header.
 int getIPHeaderLength()
          Returns the true length of the IP header
 void setICMPData(byte[] buf)
          Sets the current ICMP data encapsulated within the object equal to the passed data.
 void setIPHeader(byte[] buf)
          Sets the IP Header data.
(package private)  void write(OutputStream ostream)
          Writes the object to the output stream in a format that can be read by the ICMP daemon.
 
Methods inherited from class org.opennms.protocols.icmpd.MessageHeader
align4, getCode, getLength, getSequence, getType, makeInt, makeShort, nextSequenceId, read, setSequence
 
Methods inherited from class java.lang.Object
, clone, equals, finalize, getClass, hashCode, notify, notifyAll, registerNatives, toString, wait, wait, wait
 

Field Detail

m_ipHeader

private byte[] m_ipHeader

m_icmp

private byte[] m_icmp

m_icmpLen

private int m_icmpLen

TYPE

public static final byte TYPE
The class type.

CODE

public static final byte CODE
The class code
Constructor Detail

DataRecvMessage

public DataRecvMessage()
Constructs a default message with a blank IP header and no data.

DataRecvMessage

DataRecvMessage(MessageHeader hdr,
                InputStream istream)
          throws IOException
Constructs a new data recevied object with the specified header and reads the remaining information from the input stream.
Parameters:
hdr - The header to use in this message
istream - The input stream to get the rest of data.
Throws:
IOException - Thrown if an error occurs reading from the stream.
IllegalArgumentException - Thrown if the type or code in the passed header are not correct.

DataRecvMessage

public DataRecvMessage(byte[] header,
                       byte[] icmp)
Constructs a new received message with the specified header and icmp data.
Parameters:
header - The IP header data
icmp - The ICMP data
Method Detail

getIPHeaderLength

public int getIPHeaderLength()
Returns the true length of the IP header

getIPHeader

public byte[] getIPHeader()
Returns the array of information that is the IP header. The buffer is aligned to be a multiple of four. The true length of valid data is returned via a call to getIPHeaderLength()
Returns:
The IP Header bytes
See Also:
getIPHeaderLength()

setIPHeader

public void setIPHeader(byte[] buf)
Sets the IP Header data. The length is set to the length of the passed array.
Parameters:
buf - The IP Header data.

getICMPLength

public int getICMPLength()
Returns the length of valid data in the ICMP byte array.
See Also:
getICMPData()

getICMPData

public byte[] getICMPData()
Returns the array of bytes that is the ICMP message. The array size is a multiple of 4 and the length of valid data is available via a call to getICMPLength()
Returns:
The ICMP message
See Also:
getICMPLength()

setICMPData

public void setICMPData(byte[] buf)
Sets the current ICMP data encapsulated within the object equal to the passed data. The length is set to the length of the byte array.
Parameters:
buf - The icmp message.

calculateLength

private void calculateLength()
calcuates the length of the packet based on the encapsulate data.

write

void write(OutputStream ostream)
     throws IOException
Writes the object to the output stream in a format that can be read by the ICMP daemon.
Overrides:
write in class MessageHeader
Parameters:
ostream - The output stream
Throws:
IOException - Thrown if an error occurs with the output stream.