OpenNMS API 1.2.3

org.opennms.protocols.dns
Class DNSAddressRequest

java.lang.Object
  extended byorg.opennms.protocols.dns.DNSAddressRequest

public class DNSAddressRequest
extends java.lang.Object

 
 The DNSAddressRequest holds a DNS request to lookup the IP address of a host -
 provides for transmitting and receiving the response for this lookup.
 
 NOTES: A DNS request and response has the following fileds header questions
 answers authorities additional information
 
 The header has the following format: id - unique id sent by the client and
 returned by the server in its response 16 bits of flags -
 Query(0)/response(1) flag opcode - that has type of query AA - set if the
 response is an authoritative answer TC - set if response is truncated RD -
 set if recursion is desired RA - set if recursion is available Z - reserved
 bits RCODE - response code
 
 This class checks only for the received response to have the answer(which
 will hold the IP address) - ignores the authorities and additional info
 
 

Author:
Sowmya , OpenNMS

Field Summary
 int CLASS_IN
           Defines the class internet in the domain name system.
private static int globalID
           The global id, used to get the request id.
 java.util.List m_answers
           The list of answers.
 boolean m_authoritative
           True if the answer is authoratitve.
 boolean m_recursive
           True if the message is recursive.
 java.lang.String m_reqHost
           The host to request information from.
 int m_reqID
           The id used to seralize the request.
 boolean m_truncated
           True if the message is truncated.
 int OPCODE_QUERY
           The op code for a query in the header.
 int SHIFT_AUTHORITATIVE
           The offset of the authoritative bit in the header.
 int SHIFT_OPCODE
           The offset of the opcode bits in the header.
 int SHIFT_QUERY
           The offset of the query bit in the header.
 int SHIFT_RECURSE_AVAILABLE
           The offset of the requrse avail bit in the header.
 int SHIFT_RECURSE_PLEASE
           The offset of the recurse req bit in the header.
 int SHIFT_RESERVED
           The offset of the reserved bits in the header.
 int SHIFT_RESPONSE_CODE
           The offset of the response code bits in the header.
 int SHIFT_TRUNCATED
           The offset of the truncated bit in the header.
 int TYPE_ADDR
           Defines the address type.
 
Constructor Summary
DNSAddressRequest(java.lang.String host)
           Constructs a DNSAddressRequest for ths hostname passed.
 
Method Summary
 byte[] buildRequest()
           Builds the address request.
static java.lang.String codeName(int code)
           Returns the code string for the error code recieved.
private  void decodeFlags(int flags)
           Decodes the integer to get the flags - refer header for more info on the flags.
 java.util.List getAnswers()
           Return an enumeration of the recieved answers.
 java.lang.String getHost()
           The hostname that will be request from the DNS box.
 int getRequestID()
           The request id for this particular instance.
 boolean isAuthoritative()
           Returns true if the answer is authoritative.
 boolean isRecursive()
           Returns true if the answer is recursive.
 boolean isTruncated()
           Returns true if the answer is truncated.
 void receiveResponse(byte[] data, int length)
           Extracts the response from the bytearray.
 void verifyResponse(byte[] data, int length)
           This method only goes so far as to decode the flags in the response byte array to verify that a DNS server sent the response.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

CLASS_IN

public final int CLASS_IN

Defines the class internet in the domain name system.

See Also:
Constant Field Values

TYPE_ADDR

public final int TYPE_ADDR

Defines the address type.

See Also:
Constant Field Values

SHIFT_QUERY

public final int SHIFT_QUERY

The offset of the query bit in the header.

See Also:
Constant Field Values

SHIFT_OPCODE

public final int SHIFT_OPCODE

The offset of the opcode bits in the header.

See Also:
Constant Field Values

SHIFT_AUTHORITATIVE

public final int SHIFT_AUTHORITATIVE

The offset of the authoritative bit in the header.

See Also:
Constant Field Values

SHIFT_TRUNCATED

public final int SHIFT_TRUNCATED

The offset of the truncated bit in the header.

See Also:
Constant Field Values

SHIFT_RECURSE_PLEASE

public final int SHIFT_RECURSE_PLEASE

The offset of the recurse req bit in the header.

See Also:
Constant Field Values

SHIFT_RECURSE_AVAILABLE

public final int SHIFT_RECURSE_AVAILABLE

The offset of the requrse avail bit in the header.

See Also:
Constant Field Values

SHIFT_RESERVED

public final int SHIFT_RESERVED

The offset of the reserved bits in the header.

See Also:
Constant Field Values

SHIFT_RESPONSE_CODE

public final int SHIFT_RESPONSE_CODE

The offset of the response code bits in the header.

See Also:
Constant Field Values

OPCODE_QUERY

public final int OPCODE_QUERY

The op code for a query in the header.

See Also:
Constant Field Values

m_reqHost

public java.lang.String m_reqHost

The host to request information from. This would be the nameserver if it supports DNS.


m_reqID

public int m_reqID

The id used to seralize the request. This allows the client (us) and the server (host) to match exchanges.


m_authoritative

public boolean m_authoritative

True if the answer is authoratitve.


m_truncated

public boolean m_truncated

True if the message is truncated.


m_recursive

public boolean m_recursive

True if the message is recursive.


m_answers

public java.util.List m_answers

The list of answers.


globalID

private static int globalID

The global id, used to get the request id.

Constructor Detail

DNSAddressRequest

public DNSAddressRequest(java.lang.String host)

Constructs a DNSAddressRequest for ths hostname passed. The host string that is passed to the address string should be a hostname in "x.y.z" where x, y, and z are strings. This is not suppose to be a dotted decimal address.

Parameters:
host - hostname for which address is to be constructed
Method Detail

decodeFlags

private void decodeFlags(int flags)
                  throws java.io.IOException

Decodes the integer to get the flags - refer header for more info on the flags.

Throws:
java.io.IOException

buildRequest

public byte[] buildRequest()
                    throws java.io.IOException

Builds the address request.

Returns:
A byte array containing the request.
Throws:
java.io.IOException

receiveResponse

public void receiveResponse(byte[] data,
                            int length)
                     throws java.io.IOException

Extracts the response from the bytearray.

Parameters:
data - The byte array containing the response.
length - The length of the byte array.
Throws:
java.io.IOException - Thrown if there is an error while reading the recieved packet

verifyResponse

public void verifyResponse(byte[] data,
                           int length)
                    throws java.io.IOException

This method only goes so far as to decode the flags in the response byte array to verify that a DNS server sent the response.

NOTE: This is really a hack to get around the fact that the receiveResponse() method is not robust enough to handle all possible DNS server responses.

Parameters:
data - The byte array containing the response.
length - The length of the byte array.
Throws:
java.io.IOException - Thrown if there is an error while reading the recieved packet

getAnswers

public java.util.List getAnswers()

Return an enumeration of the recieved answers.

Returns:
The list of received answers.

getRequestID

public int getRequestID()

The request id for this particular instance.


getHost

public java.lang.String getHost()

The hostname that will be request from the DNS box.


isTruncated

public boolean isTruncated()

Returns true if the answer is truncated.


isRecursive

public boolean isRecursive()

Returns true if the answer is recursive.


isAuthoritative

public boolean isAuthoritative()

Returns true if the answer is authoritative.


codeName

public static java.lang.String codeName(int code)

Returns the code string for the error code recieved.

Parameters:
code - The error code.
Returns:
The error string corresponding to the error code

OpenNMS API 1.2.3

Generated by eevans on May 29 2005 2015.