java.lang.Object
org.minidns.dnsmessage.DnsMessage.Builder
- Enclosing class:
DnsMessage
Builder class for constructing DNS messages.
Provides a fluent API for building DNS messages with various sections and flags configured step by step.
Provides a fluent API for building DNS messages with various sections and flags configured step by step.
Field Summary
FieldsModifier and TypeFieldDescriptionThe additional section records.The answer section records.private booleanTrue if the server considers the data authentic (DNSSEC).private booleanTrue if the response is authoritative.The authority section records.private booleanTrue if DNSSEC validation should be skipped.private Edns.BuilderBuilder for the EDNS OPT pseudo-record, or null if not used.private intThe DNS message ID.private DnsMessage.OPCODEThe DNS message opcode.private booleanTrue if this is a response (QR flag), false if it is a query.The question section records.private longThe timestamp when the message was received, or -1 if not set.private booleanTrue if the server supports recursion.private booleanTrue if recursion was requested.private DnsMessage.RESPONSE_CODEThe DNS response code.private booleanTrue if the message was truncated.Constructor Summary
ConstructorsModifierConstructorDescriptionprivateBuilder()Creates a new empty Builder.privateBuilder(DnsMessage message) Creates a Builder initialized from an existing DNS message.Method Summary
Modifier and TypeMethodDescriptionaddAdditionalResourceRecord(Record<? extends Data> record) Append a record to the additional section.addAdditionalResourceRecords(List<Record<? extends Data>> records) Append records to the additional section.Append a record to the answer section.addAnswers(Collection<Record<? extends Data>> records) Append records to the answer section.addNameserverRecords(Record<? extends Data> record) Append a record to the authority section.addQuestion(Question question) Append a question to the question section.build()Build the DNS message from the state of this builder.voidcopyFlagsFrom(DnsMessage dnsMessage) Copy the header flags of the given message.Retrieve the additional section records.Retrieve the answer section records.Get theEdnsbuilder.setAdditionalResourceRecords(Collection<Record<? extends Data>> records) Replace the additional section by a copy of the given records.setAnswers(Collection<Record<? extends Data>> records) Replace the answer section by a copy of the given records.setAuthenticData(boolean authenticData) Set the authentic data flag on this DNS message.setAuthoritativeAnswer(boolean authoritativeAnswer) Set the authoritative answer flag.setCheckingDisabled(boolean checkingDisabled) /** Change the check status of this packet.setId(int id) Set the current DNS message id.setNameserverRecords(Collection<Record<? extends Data>> records) Replace the authority section by a copy of the given records.setOpcode(DnsMessage.OPCODE opcode) Set the opcode of the DNS message header.setQrFlag(boolean query) Set the QR flag.setQuestion(Question question) Set the question part of this message.setQuestions(List<Question> questions) Set the question part of this message.setReceiveTimestamp(long receiveTimestamp) Set the time at which the message was received.setRecursionAvailable(boolean recursionAvailable) Set the recursion available flog from this DNS message.setRecursionDesired(boolean recursionDesired) Set the recursion desired flag on this message.setResponseCode(DnsMessage.RESPONSE_CODE responseCode) Set the response code of the DNS message header.setTruncated(boolean truncated) Set the truncation bit on this DNS message.toString()Renders the builder's accumulated state as a readable message summary.private voidAppends this record to the string builder.
Field Details
id
private int idThe DNS message ID.opcode
The DNS message opcode.responseCode
The DNS response code.query
private boolean queryTrue if this is a response (QR flag), false if it is a query.authoritativeAnswer
private boolean authoritativeAnswerTrue if the response is authoritative.truncated
private boolean truncatedTrue if the message was truncated.recursionDesired
private boolean recursionDesiredTrue if recursion was requested.recursionAvailable
private boolean recursionAvailableTrue if the server supports recursion.authenticData
private boolean authenticDataTrue if the server considers the data authentic (DNSSEC).checkingDisabled
private boolean checkingDisabledTrue if DNSSEC validation should be skipped.receiveTimestamp
private long receiveTimestampThe timestamp when the message was received, or -1 if not set.questions
answerSection
authoritySection
additionalSection
ednsBuilder
Builder for the EDNS OPT pseudo-record, or null if not used.
Constructor Details
Builder
private Builder()Creates a new empty Builder.Builder
Creates a Builder initialized from an existing DNS message.- Parameters:
message- the DNS message to copy values from
Method Details
setId
Set the current DNS message id.- Parameters:
id- The new DNS message id.- Returns:
- a reference to this builder.
setOpcode
Set the opcode of the DNS message header.- Parameters:
opcode- the operation this message requests.- Returns:
- a reference to this builder.
setResponseCode
Set the response code of the DNS message header.- Parameters:
responseCode- the status of the DNS exchange to report.- Returns:
- a reference to this builder.
setQrFlag
Set the QR flag. Note that this will betrueif the message is a response andfalseif it is a query.- Parameters:
query- The new QR flag status.- Returns:
- a reference to this builder.
setAuthoritativeAnswer
Set the authoritative answer flag.- Parameters:
authoritativeAnswer- Tge new authoritative answer value.- Returns:
- a reference to this builder.
setTruncated
Set the truncation bit on this DNS message.- Parameters:
truncated- The new truncated bit status.- Returns:
- a reference to this builder.
setRecursionDesired
Set the recursion desired flag on this message.- Parameters:
recursionDesired- The new recursion setting.- Returns:
- a reference to this builder.
setRecursionAvailable
Set the recursion available flog from this DNS message.- Parameters:
recursionAvailable- The new recursion available status.- Returns:
- a reference to this builder.
setAuthenticData
Set the authentic data flag on this DNS message.- Parameters:
authenticData- The new authentic data flag value.- Returns:
- a reference to this builder.
setCheckingDisabled
/** Change the check status of this packet.- Parameters:
checkingDisabled- The new check disabled value.- Returns:
- a reference to this builder.
copyFlagsFrom
Copy the header flags of the given message.- Parameters:
dnsMessage- the message to copy the QR, TC, RD, RA, AD and CD flags from; its AD bit also becomes the AA flag.
setReceiveTimestamp
Set the time at which the message was received.- Parameters:
receiveTimestamp- the receive time in milliseconds since the epoch, or -1 if the message was not received.- Returns:
- a reference to this builder.
addQuestion
Append a question to the question section.- Parameters:
question- the question to append.- Returns:
- a reference to this builder.
setQuestions
Set the question part of this message.- Parameters:
questions- questions this message asks, replacing any already set- Returns:
- a reference to this builder.
setQuestion
Set the question part of this message.- Parameters:
question- the single question this message asks- Returns:
- a reference to this builder.
addAnswer
Append a record to the answer section.- Parameters:
answer- the record to append to the answer section.- Returns:
- a reference to this builder.
addAnswers
Append records to the answer section.- Parameters:
records- the records to append to the answer section.- Returns:
- a reference to this builder.
setAnswers
Replace the answer section by a copy of the given records.- Parameters:
records- the records the new answer section consists of.- Returns:
- a reference to this builder.
getAnswers
addNameserverRecords
Append a record to the authority section.- Parameters:
record- the record to append to the authority section.- Returns:
- a reference to this builder.
setNameserverRecords
Replace the authority section by a copy of the given records.- Parameters:
records- the records the new authority section consists of.- Returns:
- a reference to this builder.
setAdditionalResourceRecords
Replace the additional section by a copy of the given records.- Parameters:
records- the records the new additional section consists of.- Returns:
- a reference to this builder.
addAdditionalResourceRecord
Append a record to the additional section.- Parameters:
record- the record to append to the additional section.- Returns:
- a reference to this builder.
addAdditionalResourceRecords
Append records to the additional section.- Parameters:
records- the records to append to the additional section.- Returns:
- a reference to this builder.
getAdditionalResourceRecords
getEdnsBuilder
Get theEdnsbuilder. If no builder has been set so far, then a new one will be created.The EDNS record can be used to announce the supported size of UDP payload as well as additional flags.
Note that some networks and firewalls are known to block big UDP payloads. 1280 should be a reasonable value, everything below 512 is treated as 512 and should work on all networks.
- Returns:
- a EDNS builder.
build
Build the DNS message from the state of this builder.- Returns:
- a message holding the header flags and the sections of this builder.
writeToStringBuilder
Appends this record to the string builder.- Parameters:
sb- the builder to append to
toString