Package de.measite.minidns
Class DNSMessage
- java.lang.Object
-
- de.measite.minidns.DNSMessage
-
public class DNSMessage extends java.lang.ObjectA 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 classDNSMessage.OPCODESymbolic DNS Opcode values.static classDNSMessage.RESPONSE_CODEPossible DNS reply codes.
-
Field Summary
Fields Modifier and Type Field Description protected Record[]additionalResourceRecordsAdditional resousrce records.protected Record[]answersThe answers section content.protected booleanauthenticDataTrue if the server regarded the response as authentic.protected booleanauthoritativeAnswerTrue if this is a authorative response.protected booleancheckDisabledTrue if the server should not check the replies.protected intidThe DNS message id.protected Record[]nameserverRecordsThe nameserver records.protected DNSMessage.OPCODEopcodeThe DNS message opcode.protected booleanqueryTrue if this is a query.protected Question[]questionsThe question section content.protected longreceiveTimestampThe receive timestamp of this message.protected booleanrecursionAvailableTrue if recursion is possible.protected booleanrecursionDesiredTrue if the server should recurse.protected DNSMessage.RESPONSE_CODEresponseCodeThe response code of this dns message.protected booleantruncatedTrue 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.intgetId()Retrieve the current DNS message id.Record[]getNameserverRecords()Retrieve the nameserver records of this DNS message.DNSMessage.OPCODEgetOpcode()Retrieve the opcode of this message.Question[]getQuestions()Retrieve the question section of this message.longgetReceiveTimestamp()Get the receive timestamp if this message was created via parse.DNSMessage.RESPONSE_CODEgetResponseCode()Retrieve the response code of this message.booleanisAuthenticData()Retrieve the authentic data flag of this message.booleanisAuthoritativeAnswer()True if the DNS message is an authoritative answer.booleanisCheckDisabled()Check if checks are disabled.booleanisQuery()Retrieve the query type (true or false;booleanisRecursionAvailable()Retrieve the recursion available flag of this DNS message.booleanisRecursionDesired()Check if this message preferes recursion.booleanisTruncated()Retrieve the truncation status of this message.static DNSMessageparse(byte[] data)Build a DNS Message based on a binary DNS message.voidsetAuthenticData(boolean authenticData)Set the authentic data flag on this DNS message.voidsetAuthoritativeAnswer(boolean authoritativeAnswer)Set the authoritative answer flag.voidsetCheckDisabled(boolean checkDisabled)Change the check status of this packet.voidsetId(int id)Set the current DNS message id.voidsetQuery(boolean query)Set the query status of this message.voidsetQuestions(Question... questions)Set the question part of this message.voidsetRecursionAvailable(boolean recursionAvailable)Set the recursion available flog from this DNS message.voidsetRecursionDesired(boolean recursionDesired)Set the recursion desired flag on this message.voidsetTruncated(boolean truncated)Set the truncation bit on this DNS message.byte[]toArray()Generate a binary dns packet out of this message.java.lang.StringtoString()
-
-
-
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.IOExceptionGenerate 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:
toStringin classjava.lang.Object
-
-