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
Modifier and Type | Field and 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 and Description |
---|
DNSAddressRequest(String host)
Constructs a DNSAddressRequest for ths hostname passed.
|
Modifier and Type | Method and 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.
|
public static final int CLASS_IN
Defines the class internet in the domain name system.
public static final int TYPE_ADDR
Defines the address type.
public static final int SHIFT_QUERY
The offset of the query bit in the header.
public static final int SHIFT_OPCODE
The offset of the opcode bits in the header.
public static final int SHIFT_AUTHORITATIVE
The offset of the authoritative bit in the header.
public static final int SHIFT_TRUNCATED
The offset of the truncated bit in the header.
public static final int SHIFT_RECURSE_PLEASE
The offset of the recurse req bit in the header.
public static final int SHIFT_RECURSE_AVAILABLE
The offset of the requrse avail bit in the header.
public static final int SHIFT_RESERVED
The offset of the reserved bits in the header.
public static final int SHIFT_RESPONSE_CODE
The offset of the response code bits in the header.
public static final int OPCODE_QUERY
The op code for a query in the header.
public String m_reqHost
The host to request information from. This would be the nameserver if it supports DNS.
public int m_reqID
The id used to seralize the request. This allows the client (us) and the server (host) to match exchanges.
public boolean m_authoritative
True if the answer is authoratitve.
public boolean m_truncated
True if the message is truncated.
public boolean m_recursive
True if the message is recursive.
public List<DNSAddressRR> m_answers
The list of answers.
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.
host
- hostname for which address is to be constructedpublic byte[] buildRequest() throws IOException
Builds the address request.
IOException
- if any.public void receiveResponse(byte[] data, int length) throws IOException
Extracts the response from the bytearray.
data
- The byte array containing the response.length
- The length of the byte array.IOException
- Thrown if there is an error while reading the recieved
packetIOException
- if any.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.
data
- The byte array containing the response.length
- The length of the byte array.IOException
- Thrown if there is an error while reading the recieved
packetIOException
- if any.public List<DNSAddressRR> getAnswers()
Return an enumeration of the recieved answers.
public int getRequestID()
The request id for this particular instance.
public String getHost()
The hostname that will be request from the DNS box.
String
object.public boolean isTruncated()
Returns true if the answer is truncated.
public boolean isRecursive()
Returns true if the answer is recursive.
public boolean isAuthoritative()
Returns true if the answer is authoritative.
public static String codeName(int code)
Returns the code string for the error code recieved.
code
- The error code.Copyright © 2021. All rights reserved.