Struct trust_dns::op::message::Message [] [src]

pub struct Message { /* fields omitted */ }

The basic request and response datastructure, used for all DNS protocols.


4.1. Format

All communications inside of the domain protocol are carried in a single
format called a message.  The top level format of message is divided
into 5 sections (some of which are empty in certain cases) shown below:

    |        Header            |
    |  Question / Zone         | the question for the name server
    |   Answer  / Prerequisite | RRs answering the question
    | Authority / Update       | RRs pointing toward an authority
    |      Additional          | RRs holding additional information

The header section is always present.  The header includes fields that
specify which of the remaining sections are present, and also specify
whether the message is a query or a response, a standard query or some
other opcode, etc.

The names of the sections after the header are derived from their use in
standard queries.  The question section contains fields that describe a
question to a name server.  These fields are a query type (QTYPE), a
query class (QCLASS), and a query domain name (QNAME).  The last three
sections have the same format: a possibly empty list of concatenated
resource records (RRs).  The answer section contains RRs that answer the
question; the authority section contains RRs that point toward an
authoritative name server; the additional records section contains RRs
which relate to the query, but are not strictly answers for the

By default Message is a Query. Use the Message::as_update() to create and update, or Message::new_update()


impl Message

Returns a new "empty" Message

Returns a Message constructed with error details to return to a client


  • id - message id should match the request message id
  • op_code - operation of the request
  • response_code - the error code for the response

Truncates a Message, this blindly removes all response fields and sets trucation to true

see Header::set_id

see Header::set_message_type

see Header::set_op_code

see Header::set_authoritative

see Header::set_truncated

see Header::set_recursion_desired

see Header::set_recursion_available

see Header::set_authentic_data

see Header::set_checking_disabled

see Header::set_response_code

Add a query to the Message, either the query response from the server, or the request Query.


Adds a slice of Queries to the message

Adds an iterator over a set of Queries to be added to the message

Add an answer to the Message


Add an entire set of Answers

Add all the records from the iterator to the answers section of the Message

Sets the answers to the specified set of Records.


Will panic if answer records are already associated to the message.

Add a name server record to the Message


Adds a set of name server records to the message

Add all the records in the Iterator to the name server section of the message

Sets the name_servers to the specified set of Records.


Will panic if name_servers records are already associated to the message.

A an addtional Record to the message

Sets the additional to the specified set of Records.


Will panic if additional records are already associated to the message.

Add the EDNS section the the Message

Add a SIG0 record, i.e. sign this message

This must be don't only after all records have been associated. Generally this will be handled by the client and not need to be used directly

see Header::id()

see Header::message_type()

see Header::op_code()

see Header::authoritative()

see Header::truncated()

see Header::recursion_desired()

see Header::recursion_available()

see Header::authentic_data()

see Header::checking_disabled()

Return value

The ResponseCode, if this is an EDNS message then this will join the section from the OPT record to create the EDNS ResponseCode

Question        Carries the query name and other query parameters.

Answer          Carries RRs which directly answer the query.

Removes all the answers from the Message

Authority       Carries RRs which describe other authoritative servers.
                May optionally carry the SOA RR for the authoritative
                data in the answer section.

Remove the name servers from the Message

Additional      Carries RRs which may be helpful in using the RRs in the
                other sections.

Remove the additional Records from the Message

RFC 6891, EDNS(0) Extensions, April 2013

6.1.1.  Basic Elements

 An OPT pseudo-RR (sometimes called a meta-RR) MAY be added to the
 additional data section of a request.

 The OPT RR has RR type 41.

 If an OPT record is present in a received request, compliant
 responders MUST include an OPT record in their respective responses.

 An OPT record does not carry any DNS data.  It is used only to
 contain control information pertaining to the question-and-answer
 sequence of a specific transaction.  OPT RRs MUST NOT be cached,
 forwarded, or stored in or loaded from master files.

 The OPT RR MAY be placed anywhere within the additional data section.
 When an OPT RR is included within any DNS message, it MUST be the
 only OPT RR in that message.  If a query message with more than one
 OPT RR is received, a FORMERR (RCODE=1) MUST be returned.  The
 placement flexibility for the OPT RR does not override the need for
 the TSIG or SIG(0) RRs to be the last in the additional section
 whenever they are present.

Return value

Returns the EDNS record if it was found in the additional section.

If edns is_none, this will create a new default Edns.

Return value

the max payload value as it's defined in the EDNS section.

Return value

the version as defined in the EDNS record

Decodes a message from the buffer.

Encodes the Message into a buffer

Sign the message, i.e. add a SIG0 record to this Message.

Subsequent to calling this, the Message should not change.

Trait Implementations

impl Clone for Message

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

impl Debug for Message

Formats the value using the given formatter.

impl PartialEq for Message

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

impl UpdateMessage for Message

to reduce errors in using the Message struct as an Update, this will do the call throughs to properly do that.

see Header::id

Adds the zone section, i.e. would be

Add the pre-requisite records Read more


Add all pre-requisites to the UpdateMessage

Add all the Records from the Iterator to the pre-reqisites section

Add the Record to be updated


Add the set of Records to be updated

Add the Records from the Iterator to the updates section

Add Records to the additional Section of hte UpdateMessage

Returns the Zones to be updated, generally should only be one.

Returns the pre-requisites

Returns the records to be updated

Returns the additonal records

This is used to authenticate update messages. Read more

Signs the UpdateMessage, used to validate the authenticity and authorization of UpdateMessage

impl BinSerializable<Message> for Message

Read the type from the stream

Write the type to the stream