Package de.measite.minidns
Class DNSMessage
- java.lang.Object
-
- de.measite.minidns.DNSMessage
-
public class DNSMessage extends java.lang.Object
A DNS message as defined by rfc1035. The message consists of a header and 4 sections: question, answer, nameserver and addition resource record section. A message can either be parsed (parse(byte[])
) or serialized (toArray()
).
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
DNSMessage.OPCODE
Symbolic DNS Opcode values.static class
DNSMessage.RESPONSE_CODE
Possible DNS reply codes.
-
Field Summary
Fields Modifier and Type Field Description protected Record[]
additionalResourceRecords
Additional resousrce records.protected Record[]
answers
The answers section content.protected boolean
authenticData
True if the server regarded the response as authentic.protected boolean
authoritativeAnswer
True if this is a authorative response.protected boolean
checkDisabled
True if the server should not check the replies.protected int
id
The DNS message id.protected Record[]
nameserverRecords
The nameserver records.protected DNSMessage.OPCODE
opcode
The DNS message opcode.protected boolean
query
True if this is a query.protected Question[]
questions
The question section content.protected long
receiveTimestamp
The receive timestamp of this message.protected boolean
recursionAvailable
True if recursion is possible.protected boolean
recursionDesired
True if the server should recurse.protected DNSMessage.RESPONSE_CODE
responseCode
The response code of this dns message.protected boolean
truncated
True on truncate, tcp should be used.
-
Constructor Summary
Constructors Constructor Description DNSMessage()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description Record[]
getAdditionalResourceRecords()
Retrieve the additional resource records attached to this DNS message.Record[]
getAnswers()
Retrieve the answer records of this DNS message.int
getId()
Retrieve the current DNS message id.Record[]
getNameserverRecords()
Retrieve the nameserver records of this DNS message.DNSMessage.OPCODE
getOpcode()
Retrieve the opcode of this message.Question[]
getQuestions()
Retrieve the question section of this message.long
getReceiveTimestamp()
Get the receive timestamp if this message was created via parse.DNSMessage.RESPONSE_CODE
getResponseCode()
Retrieve the response code of this message.boolean
isAuthenticData()
Retrieve the authentic data flag of this message.boolean
isAuthoritativeAnswer()
True if the DNS message is an authoritative answer.boolean
isCheckDisabled()
Check if checks are disabled.boolean
isQuery()
Retrieve the query type (true or false;boolean
isRecursionAvailable()
Retrieve the recursion available flag of this DNS message.boolean
isRecursionDesired()
Check if this message preferes recursion.boolean
isTruncated()
Retrieve the truncation status of this message.static DNSMessage
parse(byte[] data)
Build a DNS Message based on a binary DNS message.void
setAuthenticData(boolean authenticData)
Set the authentic data flag on this DNS message.void
setAuthoritativeAnswer(boolean authoritativeAnswer)
Set the authoritative answer flag.void
setCheckDisabled(boolean checkDisabled)
Change the check status of this packet.void
setId(int id)
Set the current DNS message id.void
setQuery(boolean query)
Set the query status of this message.void
setQuestions(Question... questions)
Set the question part of this message.void
setRecursionAvailable(boolean recursionAvailable)
Set the recursion available flog from this DNS message.void
setRecursionDesired(boolean recursionDesired)
Set the recursion desired flag on this message.void
setTruncated(boolean truncated)
Set the truncation bit on this DNS message.byte[]
toArray()
Generate a binary dns packet out of this message.java.lang.String
toString()
-
-
-
Field Detail
-
id
protected int id
The DNS message id.
-
opcode
protected DNSMessage.OPCODE opcode
The DNS message opcode.
-
responseCode
protected DNSMessage.RESPONSE_CODE responseCode
The response code of this dns message.
-
query
protected boolean query
True if this is a query.
-
authoritativeAnswer
protected boolean authoritativeAnswer
True if this is a authorative response.
-
truncated
protected boolean truncated
True on truncate, tcp should be used.
-
recursionDesired
protected boolean recursionDesired
True if the server should recurse.
-
recursionAvailable
protected boolean recursionAvailable
True if recursion is possible.
-
authenticData
protected boolean authenticData
True if the server regarded the response as authentic.
-
checkDisabled
protected boolean checkDisabled
True if the server should not check the replies.
-
questions
protected Question[] questions
The question section content.
-
answers
protected Record[] answers
The answers section content.
-
nameserverRecords
protected Record[] nameserverRecords
The nameserver records.
-
additionalResourceRecords
protected Record[] additionalResourceRecords
Additional resousrce records.
-
receiveTimestamp
protected long receiveTimestamp
The receive timestamp of this message.
-
-
Method Detail
-
getId
public int getId()
Retrieve the current DNS message id.- Returns:
- The current DNS message id.
-
setId
public void setId(int id)
Set the current DNS message id.- Parameters:
id
- The new DNS message id.
-
getReceiveTimestamp
public long getReceiveTimestamp()
Get the receive timestamp if this message was created via parse. This should be used to evaluate TTLs.- Returns:
- The receive timestamp in milliseconds.
-
isQuery
public boolean isQuery()
Retrieve the query type (true or false;- Returns:
- True if this DNS message is a query.
-
setQuery
public void setQuery(boolean query)
Set the query status of this message.- Parameters:
query
- The new query status.
-
isAuthoritativeAnswer
public boolean isAuthoritativeAnswer()
True if the DNS message is an authoritative answer.- Returns:
- True if this an authoritative DNS message.
-
setAuthoritativeAnswer
public void setAuthoritativeAnswer(boolean authoritativeAnswer)
Set the authoritative answer flag.- Parameters:
authoritativeAnswer
- Tge new authoritative answer value.
-
isTruncated
public boolean isTruncated()
Retrieve the truncation status of this message. True means that the client should try a tcp lookup.- Returns:
- True if this message was truncated.
-
setTruncated
public void setTruncated(boolean truncated)
Set the truncation bit on this DNS message.- Parameters:
truncated
- The new truncated bit status.
-
isRecursionDesired
public boolean isRecursionDesired()
Check if this message preferes recursion.- Returns:
- True if recursion is desired.
-
setRecursionDesired
public void setRecursionDesired(boolean recursionDesired)
Set the recursion desired flag on this message.- Parameters:
recursionDesired
- The new recusrion setting.
-
isRecursionAvailable
public boolean isRecursionAvailable()
Retrieve the recursion available flag of this DNS message.- Returns:
- The recursion available flag of this message.
-
setRecursionAvailable
public void setRecursionAvailable(boolean recursionAvailable)
Set the recursion available flog from this DNS message.- Parameters:
recursionAvailable
- The new recursion available status.
-
isAuthenticData
public boolean isAuthenticData()
Retrieve the authentic data flag of this message.- Returns:
- The authentic data flag.
-
setAuthenticData
public void setAuthenticData(boolean authenticData)
Set the authentic data flag on this DNS message.- Parameters:
authenticData
- The new authentic data flag value.
-
isCheckDisabled
public boolean isCheckDisabled()
Check if checks are disabled.- Returns:
- The status of the CheckDisabled flag.
-
setCheckDisabled
public void setCheckDisabled(boolean checkDisabled)
Change the check status of this packet.- Parameters:
checkDisabled
- The new check disabled value.
-
toArray
public byte[] toArray() throws java.io.IOException
Generate a binary dns packet out of this message.- Returns:
- byte[] the binary representation.
- Throws:
java.io.IOException
- Should never happen.
-
parse
public static DNSMessage parse(byte[] data) throws java.io.IOException
Build a DNS Message based on a binary DNS message.- Parameters:
data
- The DNS message data.- Returns:
- Parsed DNSMessage message.
- Throws:
java.io.IOException
- On read errors.
-
setQuestions
public void setQuestions(Question... questions)
Set the question part of this message.- Parameters:
questions
- The questions.
-
getOpcode
public DNSMessage.OPCODE getOpcode()
Retrieve the opcode of this message.- Returns:
- The opcode of this message.
-
getResponseCode
public DNSMessage.RESPONSE_CODE getResponseCode()
Retrieve the response code of this message.- Returns:
- The response code.
-
getQuestions
public Question[] getQuestions()
Retrieve the question section of this message.- Returns:
- The DNS question section.
-
getAnswers
public Record[] getAnswers()
Retrieve the answer records of this DNS message.- Returns:
- The answer section of this DNS message.
-
getNameserverRecords
public Record[] getNameserverRecords()
Retrieve the nameserver records of this DNS message.- Returns:
- The nameserver section of this DNS message.
-
getAdditionalResourceRecords
public Record[] getAdditionalResourceRecords()
Retrieve the additional resource records attached to this DNS message.- Returns:
- The additional resource record section of this DNS message.
-
toString
public java.lang.String toString()
- Overrides:
toString
in classjava.lang.Object
-
-