Package org.minidns.dnsmessage
Class DnsMessage
java.lang.Object
org.minidns.dnsmessage.DnsMessage
A DNS message as defined by RFC 1035. The message consists of a header and
 4 sections: question, answer, nameserver and addition resource record
 section.
 A message can either be parsed (
DnsMessage(byte[])) or serialized
 (toArray()).- See Also:
 
- 
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic final classstatic enumSymbolic DNS Opcode values.static enumPossible DNS response codes. - 
Field Summary
FieldsModifier and TypeFieldDescriptionThe additional section.The answers section records.final booleanTrue if the server regarded the response as authentic.final booleanTrue if this is a authorative response.The Authority Section.final booleanTrue if the server should not perform DNSSEC validation before returning the result.final intThe DNS message id.final DnsMessage.OPCODEThe DNS message opcode.final intfinal booleanThe QR flag of the DNS message header.The question section content.final longThe receive timestamp.final booleanTrue if recursion is possible.final booleanTrue if the server should recurse.final DnsMessage.RESPONSE_CODEThe response code of this dns message.final booleanTrue if message is truncated. - 
Constructor Summary
ConstructorsModifierConstructorDescriptionDnsMessage(byte[] data) Build a DNS Message based on a binary DNS message.protectedDnsMessage(DnsMessage.Builder builder)  - 
Method Summary
Modifier and TypeMethodDescriptionasDatagram(InetAddress address, int port) Format the DnsMessage object in a way suitable for terminal output.static DnsMessage.Builderbuilder()(package private) intCopy the records found in the answer section into a new list.Copy the records found in the authority section into a new list.Copy the questions found in the question section.booleanfilterAdditionalSectionBy(Class<D> type) filterAnswerSectionBy(Class<D> type) filterAuthoritySectionBy(Class<D> type) longGet the minimum TTL from all answers in seconds.getEdns()getFirstOfTypeFromAdditionalSection(Class<D> type) getFirstOfTypeFromAnswerSection(Class<D> type) getFirstOfTypeFromAuthoritySection(Class<D> type) getResponseBuilder(DnsMessage.RESPONSE_CODE responseCode) inthashCode()booleanCheck if the EDNS DO (DNSSEC OK) flag is set.byte[]toArray()Generate a binary dns packet out of this message.toString()voidwriteTo(OutputStream outputStream) voidwriteTo(OutputStream outputStream, boolean writeLength)  
- 
Field Details
- 
id
public final int idThe DNS message id. - 
opcode
The DNS message opcode. - 
responseCode
The response code of this dns message. - 
qr
public final boolean qrThe QR flag of the DNS message header. Note that this will betrueif the message is a response andfalseif it is a query.- See Also:
 
 - 
authoritativeAnswer
public final boolean authoritativeAnswerTrue if this is a authorative response. If set, the responding nameserver is an authority for the domain name in the question section. Note that the answer section may have multiple owner names because of aliases. This flag corresponds to the name which matches the query name, or the first owner name in the query section.- See Also:
 
 - 
truncated
public final boolean truncatedTrue if message is truncated. Then TCP should be used. - 
recursionDesired
public final boolean recursionDesiredTrue if the server should recurse. - 
recursionAvailable
public final boolean recursionAvailableTrue if recursion is possible. - 
authenticData
public final boolean authenticDataTrue if the server regarded the response as authentic. - 
checkingDisabled
public final boolean checkingDisabledTrue if the server should not perform DNSSEC validation before returning the result. - 
questions
The question section content. Usually there will be only one question.This list is unmodifiable.
 - 
answerSection
The answers section records. Note that it is not guaranteed that all records found in this section will be direct answers to the question in the query. If DNSSEC is used, then this section also contains the RRSIG record.This list is unmodifiable.
 - 
authoritySection
The Authority Section. Note that it is not guaranteed that this section only contains nameserver records. If DNSSEC is used, then this section could also contain a NSEC(3) record.This list is unmodifiable.
 - 
additionalSection
The additional section. It eventually contains RRs which relate to the query.This list is unmodifiable.
 - 
optRrPosition
public final int optRrPosition - 
receiveTimestamp
public final long receiveTimestampThe receive timestamp. Set only if this message was created via parse. This should be used to evaluate TTLs. 
 - 
 - 
Constructor Details
- 
DnsMessage
 - 
DnsMessage
Build a DNS Message based on a binary DNS message.- Parameters:
 data- The DNS message data.- Throws:
 IOException- On read errors.
 
 - 
 - 
Method Details
- 
toArray
public byte[] toArray()Generate a binary dns packet out of this message.- Returns:
 - byte[] the binary representation.
 
 - 
asDatagram
 - 
writeTo
- Throws:
 IOException
 - 
writeTo
- Throws:
 IOException
 - 
getInByteBuffer
 - 
calculateHeaderBitmap
int calculateHeaderBitmap() - 
getQuestion
 - 
copyQuestions
Copy the questions found in the question section.- Returns:
 - a copy of the question section questions.
 - See Also:
 
 - 
copyAnswers
Copy the records found in the answer section into a new list.- Returns:
 - a copy of the answer section records.
 - See Also:
 
 - 
copyAuthority
Copy the records found in the authority section into a new list.- Returns:
 - a copy of the authority section records.
 - See Also:
 
 - 
getEdns
 - 
getOptPseudoRecord
 - 
isDnssecOk
public boolean isDnssecOk()Check if the EDNS DO (DNSSEC OK) flag is set.- Returns:
 - true if the DO flag is set.
 
 - 
toString
 - 
asTerminalOutput
Format the DnsMessage object in a way suitable for terminal output. The format is loosely based on the output provided bydig.- Returns:
 - This message as a String suitable for terminal output.
 
 - 
getAnswersFor
 - 
getAnswersMinTtl
public long getAnswersMinTtl()Get the minimum TTL from all answers in seconds.- Returns:
 - the minimum TTL from all answers in seconds.
 
 - 
asBuilder
 - 
asNormalizedVersion
 - 
getResponseBuilder
 - 
hashCode
public int hashCode() - 
filterAnswerSectionBy
 - 
filterAuthoritySectionBy
 - 
filterAdditionalSectionBy
 - 
getFirstOfTypeFromAnswerSection
 - 
getFirstOfTypeFromAuthoritySection
 - 
getFirstOfTypeFromAdditionalSection
 - 
equals
 - 
builder
 
 -