Class DNSAddressRequest
- java.lang.Object
-
- org.opennms.netmgt.provision.support.dns.DNSAddressRequest
-
public class DNSAddressRequest extends 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
-
-
Field Summary
Fields Modifier and Type Field Description static int
CLASS_IN
Defines the class internet in the domain name system.List<DNSAddressRR>
m_answers
The list of answers.boolean
m_authoritative
True if the answer is authoratitve.boolean
m_recursive
True if the message is recursive.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.static int
OPCODE_QUERY
The op code for a query in the header.static int
SHIFT_AUTHORITATIVE
The offset of the authoritative bit in the header.static int
SHIFT_OPCODE
The offset of the opcode bits in the header.static int
SHIFT_QUERY
The offset of the query bit in the header.static int
SHIFT_RECURSE_AVAILABLE
The offset of the requrse avail bit in the header.static int
SHIFT_RECURSE_PLEASE
The offset of the recurse req bit in the header.static int
SHIFT_RESERVED
The offset of the reserved bits in the header.static int
SHIFT_RESPONSE_CODE
The offset of the response code bits in the header.static int
SHIFT_TRUNCATED
The offset of the truncated bit in the header.static int
TYPE_ADDR
Defines the address type.
-
Constructor Summary
Constructors Constructor Description DNSAddressRequest(String host)
Constructs a DNSAddressRequest for ths hostname passed.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description byte[]
buildRequest()
Builds the address request.static String
codeName(int code)
Returns the code string for the error code recieved.List<DNSAddressRR>
getAnswers()
Return an enumeration of the recieved answers.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.
-
-
-
Field Detail
-
CLASS_IN
public static final int CLASS_IN
Defines the class internet in the domain name system.
- See Also:
- Constant Field Values
-
TYPE_ADDR
public static final int TYPE_ADDR
Defines the address type.
- See Also:
- Constant Field Values
-
SHIFT_QUERY
public static final int SHIFT_QUERY
The offset of the query bit in the header.
- See Also:
- Constant Field Values
-
SHIFT_OPCODE
public static final int SHIFT_OPCODE
The offset of the opcode bits in the header.
- See Also:
- Constant Field Values
-
SHIFT_AUTHORITATIVE
public static final int SHIFT_AUTHORITATIVE
The offset of the authoritative bit in the header.
- See Also:
- Constant Field Values
-
SHIFT_TRUNCATED
public static final int SHIFT_TRUNCATED
The offset of the truncated bit in the header.
- See Also:
- Constant Field Values
-
SHIFT_RECURSE_PLEASE
public static final int SHIFT_RECURSE_PLEASE
The offset of the recurse req bit in the header.
- See Also:
- Constant Field Values
-
SHIFT_RECURSE_AVAILABLE
public static final int SHIFT_RECURSE_AVAILABLE
The offset of the requrse avail bit in the header.
- See Also:
- Constant Field Values
-
SHIFT_RESERVED
public static final int SHIFT_RESERVED
The offset of the reserved bits in the header.
- See Also:
- Constant Field Values
-
SHIFT_RESPONSE_CODE
public static final int SHIFT_RESPONSE_CODE
The offset of the response code bits in the header.
- See Also:
- Constant Field Values
-
OPCODE_QUERY
public static final int OPCODE_QUERY
The op code for a query in the header.
- See Also:
- Constant Field Values
-
m_reqHost
public 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 List<DNSAddressRR> m_answers
The list of answers.
-
-
Constructor Detail
-
DNSAddressRequest
public DNSAddressRequest(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
-
buildRequest
public byte[] buildRequest() throws IOException
Builds the address request.
- Returns:
- A byte array containing the request.
- Throws:
IOException
- if any.
-
receiveResponse
public void receiveResponse(byte[] data, int length) throws IOException
Extracts the response from the bytearray.
- Parameters:
data
- The byte array containing the response.length
- The length of the byte array.- Throws:
IOException
- Thrown if there is an error while reading the recieved packetIOException
- if any.
-
verifyResponse
public void verifyResponse(byte[] data, int length) throws 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:
IOException
- Thrown if there is an error while reading the recieved packetIOException
- if any.
-
getAnswers
public List<DNSAddressRR> 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.
- Returns:
- a int.
-
getHost
public String getHost()
The hostname that will be request from the DNS box.
- Returns:
- a
String
object.
-
isTruncated
public boolean isTruncated()
Returns true if the answer is truncated.
- Returns:
- a boolean.
-
isRecursive
public boolean isRecursive()
Returns true if the answer is recursive.
- Returns:
- a boolean.
-
isAuthoritative
public boolean isAuthoritative()
Returns true if the answer is authoritative.
- Returns:
- a boolean.
-
codeName
public static 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
-
-