Struct trust_dns_proto::op::message::Message [−][src]
pub struct Message { /* fields omitted */ }
The basic request and response datastructure, used for all DNS protocols.
RFC 1035, DOMAIN NAMES - IMPLEMENTATION AND SPECIFICATION, November 1987
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
question.
By default Message is a Query. Use the Message::as_update() to create and update, or Message::new_update()
Methods
impl Message
[src]
impl Message
pub fn new() -> Self
[src]
pub fn new() -> Self
Returns a new "empty" Message
pub fn error_msg(
id: u16,
op_code: OpCode,
response_code: ResponseCode
) -> Message
[src]
pub fn error_msg(
id: u16,
op_code: OpCode,
response_code: ResponseCode
) -> Message
Returns a Message constructed with error details to return to a client
Arguments
id
- message id should match the request message idop_code
- operation of the requestresponse_code
- the error code for the response
pub fn truncate(&self) -> Self
[src]
pub fn truncate(&self) -> Self
Truncates a Message, this blindly removes all response fields and sets trucation to true
pub fn set_id(&mut self, id: u16) -> &mut Self
[src]
pub fn set_id(&mut self, id: u16) -> &mut Self
see Header::set_id
pub fn set_message_type(&mut self, message_type: MessageType) -> &mut Self
[src]
pub fn set_message_type(&mut self, message_type: MessageType) -> &mut Self
see Header::set_message_type
pub fn set_op_code(&mut self, op_code: OpCode) -> &mut Self
[src]
pub fn set_op_code(&mut self, op_code: OpCode) -> &mut Self
see Header::set_op_code
see Header::set_authoritative
pub fn set_truncated(&mut self, truncated: bool) -> &mut Self
[src]
pub fn set_truncated(&mut self, truncated: bool) -> &mut Self
see Header::set_truncated
pub fn set_recursion_desired(&mut self, recursion_desired: bool) -> &mut Self
[src]
pub fn set_recursion_desired(&mut self, recursion_desired: bool) -> &mut Self
see Header::set_recursion_desired
pub fn set_recursion_available(
&mut self,
recursion_available: bool
) -> &mut Self
[src]
pub fn set_recursion_available(
&mut self,
recursion_available: bool
) -> &mut Self
see Header::set_recursion_available
pub fn set_authentic_data(&mut self, authentic_data: bool) -> &mut Self
[src]
pub fn set_authentic_data(&mut self, authentic_data: bool) -> &mut Self
see Header::set_authentic_data
pub fn set_checking_disabled(&mut self, checking_disabled: bool) -> &mut Self
[src]
pub fn set_checking_disabled(&mut self, checking_disabled: bool) -> &mut Self
see Header::set_checking_disabled
pub fn set_response_code(&mut self, response_code: ResponseCode) -> &mut Self
[src]
pub fn set_response_code(&mut self, response_code: ResponseCode) -> &mut Self
see Header::set_response_code
pub fn add_query(&mut self, query: Query) -> &mut Self
[src]
pub fn add_query(&mut self, query: Query) -> &mut Self
Add a query to the Message, either the query response from the server, or the request Query.
pub fn add_queries<Q, I>(&mut self, queries: Q) -> &mut Self where
Q: IntoIterator<Item = Query, IntoIter = I>,
I: Iterator<Item = Query>,
[src]
pub fn add_queries<Q, I>(&mut self, queries: Q) -> &mut Self where
Q: IntoIterator<Item = Query, IntoIter = I>,
I: Iterator<Item = Query>,
Adds an iterator over a set of Queries to be added to the message
pub fn add_answer(&mut self, record: Record) -> &mut Self
[src]
pub fn add_answer(&mut self, record: Record) -> &mut Self
Add an answer to the Message
pub fn add_answers<R, I>(&mut self, records: R) -> &mut Self where
R: IntoIterator<Item = Record, IntoIter = I>,
I: Iterator<Item = Record>,
[src]
pub fn add_answers<R, I>(&mut self, records: R) -> &mut Self where
R: IntoIterator<Item = Record, IntoIter = I>,
I: Iterator<Item = Record>,
Add all the records from the iterator to the answers section of the Message
pub fn insert_answers(&mut self, records: Vec<Record>)
[src]
pub fn insert_answers(&mut self, records: Vec<Record>)
Sets the answers to the specified set of Records.
Panics
Will panic if answer records are already associated to the message.
pub fn add_name_server(&mut self, record: Record) -> &mut Self
[src]
pub fn add_name_server(&mut self, record: Record) -> &mut Self
Add a name server record to the Message
pub fn add_name_servers<R, I>(&mut self, records: R) -> &mut Self where
R: IntoIterator<Item = Record, IntoIter = I>,
I: Iterator<Item = Record>,
[src]
pub fn add_name_servers<R, I>(&mut self, records: R) -> &mut Self where
R: IntoIterator<Item = Record, IntoIter = I>,
I: Iterator<Item = Record>,
Add all the records in the Iterator to the name server section of the message
pub fn insert_name_servers(&mut self, records: Vec<Record>)
[src]
pub fn insert_name_servers(&mut self, records: Vec<Record>)
Sets the name_servers to the specified set of Records.
Panics
Will panic if name_servers records are already associated to the message.
pub fn add_additional(&mut self, record: Record) -> &mut Self
[src]
pub fn add_additional(&mut self, record: Record) -> &mut Self
A an addtional Record to the message
pub fn insert_additionals(&mut self, records: Vec<Record>)
[src]
pub fn insert_additionals(&mut self, records: Vec<Record>)
Sets the additional to the specified set of Records.
Panics
Will panic if additional records are already associated to the message.
pub fn set_edns(&mut self, edns: Edns) -> &mut Self
[src]
pub fn set_edns(&mut self, edns: Edns) -> &mut Self
Add the EDNS section the the Message
pub fn id(&self) -> u16
[src]
pub fn id(&self) -> u16
see Header::id()
pub fn message_type(&self) -> MessageType
[src]
pub fn message_type(&self) -> MessageType
see Header::message_type()
pub fn op_code(&self) -> OpCode
[src]
pub fn op_code(&self) -> OpCode
see Header::op_code()
see Header::authoritative()
pub fn truncated(&self) -> bool
[src]
pub fn truncated(&self) -> bool
see Header::truncated()
pub fn recursion_desired(&self) -> bool
[src]
pub fn recursion_desired(&self) -> bool
see Header::recursion_desired()
pub fn recursion_available(&self) -> bool
[src]
pub fn recursion_available(&self) -> bool
see Header::recursion_available()
pub fn authentic_data(&self) -> bool
[src]
pub fn authentic_data(&self) -> bool
see Header::authentic_data()
pub fn checking_disabled(&self) -> bool
[src]
pub fn checking_disabled(&self) -> bool
see Header::checking_disabled()
pub fn response_code(&self) -> ResponseCode
[src]
pub fn response_code(&self) -> ResponseCode
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
pub fn queries(&self) -> &[Query]
[src]
pub fn queries(&self) -> &[Query]
Question Carries the query name and other query parameters.
pub fn answers(&self) -> &[Record]
[src]
pub fn answers(&self) -> &[Record]
Answer Carries RRs which directly answer the query.
pub fn take_answers(&mut self) -> Vec<Record>
[src]
pub fn take_answers(&mut self) -> Vec<Record>
Removes all the answers from the Message
pub fn name_servers(&self) -> &[Record]
[src]
pub fn name_servers(&self) -> &[Record]
Authority Carries RRs which describe other authoritative servers.
May optionally carry the SOA RR for the authoritative
data in the answer section.
pub fn take_name_servers(&mut self) -> Vec<Record>
[src]
pub fn take_name_servers(&mut self) -> Vec<Record>
Remove the name servers from the Message
pub fn additionals(&self) -> &[Record]
[src]
pub fn additionals(&self) -> &[Record]
Additional Carries RRs which may be helpful in using the RRs in the
other sections.
pub fn take_additionals(&mut self) -> Vec<Record>
[src]
pub fn take_additionals(&mut self) -> Vec<Record>
Remove the additional Records from the Message
pub fn edns(&self) -> Option<&Edns>
[src]
pub fn edns(&self) -> Option<&Edns>
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.
pub fn edns_mut(&mut self) -> &mut Edns
[src]
pub fn edns_mut(&mut self) -> &mut Edns
If edns is_none, this will create a new default Edns.
pub fn max_payload(&self) -> u16
[src]
pub fn max_payload(&self) -> u16
Return value
the max payload value as it's defined in the EDNS section.
pub fn version(&self) -> u8
[src]
pub fn version(&self) -> u8
Return value
the version as defined in the EDNS record
pub fn sig0(&self) -> &[Record]
[src]
pub fn sig0(&self) -> &[Record]
RFC 2535, Domain Name System Security Extensions, March 1999
A DNS request may be optionally signed by including one or more SIGs
at the end of the query. Such SIGs are identified by having a "type
covered" field of zero. They sign the preceding DNS request message
including DNS header but not including the IP header or any request
SIGs at the end and before the request RR counts have been adjusted
for the inclusions of any request SIG(s).
Return value
The sig0, i.e. signed record, for verifying the sending and package integrity
pub fn read_queries(
decoder: &mut BinDecoder,
count: usize
) -> ProtoResult<Vec<Query>>
[src]
pub fn read_queries(
decoder: &mut BinDecoder,
count: usize
) -> ProtoResult<Vec<Query>>
Attempts to read the specified number of Query
s
pub fn read_records(
decoder: &mut BinDecoder,
count: usize,
is_additional: bool
) -> ProtoResult<(Vec<Record>, Option<Edns>, Vec<Record>)>
[src]
pub fn read_records(
decoder: &mut BinDecoder,
count: usize,
is_additional: bool
) -> ProtoResult<(Vec<Record>, Option<Edns>, Vec<Record>)>
Attempts to read the specified number of records
Returns
This returns a tuple of first standard Records, then a possibly associated Edns, and then finally any optionally associated SIG0 records.
pub fn from_vec(buffer: &[u8]) -> ProtoResult<Message>
[src]
pub fn from_vec(buffer: &[u8]) -> ProtoResult<Message>
Decodes a message from the buffer.
pub fn to_vec(&self) -> Result<Vec<u8>, ProtoError>
[src]
pub fn to_vec(&self) -> Result<Vec<u8>, ProtoError>
Encodes the Message into a buffer
pub fn finalize<MF: MessageFinalizer>(
&mut self,
finalizer: &MF,
inception_time: u32
) -> ProtoResult<()>
[src]
pub fn finalize<MF: MessageFinalizer>(
&mut self,
finalizer: &MF,
inception_time: u32
) -> ProtoResult<()>
Finalize the message prior to sending.
Subsequent to calling this, the Message should not change.
Trait Implementations
impl Clone for Message
[src]
impl Clone for Message
fn clone(&self) -> Message
[src]
fn clone(&self) -> Message
Returns a copy of the value. Read more
fn clone_from(&mut self, source: &Self)
1.0.0[src]
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from source
. Read more
impl Debug for Message
[src]
impl Debug for Message
fn fmt(&self, f: &mut Formatter) -> Result
[src]
fn fmt(&self, f: &mut Formatter) -> Result
Formats the value using the given formatter. Read more
impl PartialEq for Message
[src]
impl PartialEq for Message
fn eq(&self, other: &Message) -> bool
[src]
fn eq(&self, other: &Message) -> bool
This method tests for self
and other
values to be equal, and is used by ==
. Read more
fn ne(&self, other: &Message) -> bool
[src]
fn ne(&self, other: &Message) -> bool
This method tests for !=
.
impl Default for Message
[src]
impl Default for Message
impl EncodableMessage for Message
[src]
impl EncodableMessage for Message
fn header(&self) -> &Header
[src]
fn header(&self) -> &Header
The Header associated with this Message
fn queries_len(&self) -> usize
[src]
fn queries_len(&self) -> usize
return the length of the set of queries
fn emit_queries(&self, encoder: &mut BinEncoder) -> ProtoResult<()>
[src]
fn emit_queries(&self, encoder: &mut BinEncoder) -> ProtoResult<()>
Emit the queries section of the EncodableMessage, if there are none, it's acceptable to return Ok(())
fn answers_len(&self) -> usize
[src]
fn answers_len(&self) -> usize
return the length of the set of queries
fn emit_answers(&self, encoder: &mut BinEncoder) -> ProtoResult<()>
[src]
fn emit_answers(&self, encoder: &mut BinEncoder) -> ProtoResult<()>
Emit the answers section of the EncodableMessage, if there are none, it's acceptable to return Ok(())
fn name_servers_len(&self) -> usize
[src]
fn name_servers_len(&self) -> usize
return the length of the set of queries
fn emit_name_servers(&self, encoder: &mut BinEncoder) -> ProtoResult<()>
[src]
fn emit_name_servers(&self, encoder: &mut BinEncoder) -> ProtoResult<()>
Emit the name_servers section of the EncodableMessage, if there are none, it's acceptable to return Ok(())
fn additionals_len(&self) -> usize
[src]
fn additionals_len(&self) -> usize
return the length of the set of queries
fn emit_additionals(&self, encoder: &mut BinEncoder) -> ProtoResult<()>
[src]
fn emit_additionals(&self, encoder: &mut BinEncoder) -> ProtoResult<()>
Emit the additionals section of the EncodableMessage, if there are none, it's acceptable to return Ok(())
fn edns(&self) -> Option<&Edns>
[src]
fn edns(&self) -> Option<&Edns>
Extended DNS options associated with this message
fn sig0(&self) -> &[Record]
[src]
fn sig0(&self) -> &[Record]
Any SIG0 records for signed messages
fn update_header_counts(&self, include_sig0: bool) -> Header
[src]
fn update_header_counts(&self, include_sig0: bool) -> Header
Returns a new Header with accurate counts for each Message section
impl<'r> BinDecodable<'r> for Message
[src]
impl<'r> BinDecodable<'r> for Message
fn read(decoder: &mut BinDecoder<'r>) -> ProtoResult<Self>
[src]
fn read(decoder: &mut BinDecoder<'r>) -> ProtoResult<Self>
Read the type from the stream
fn from_bytes(bytes: &'r [u8]) -> ProtoResult<Self>
[src]
fn from_bytes(bytes: &'r [u8]) -> ProtoResult<Self>
Returns the object in binary form
impl Into<DnsRequest> for Message
[src]
impl Into<DnsRequest> for Message
fn into(self) -> DnsRequest
[src]
fn into(self) -> DnsRequest
Performs the conversion.
impl From<DnsResponse> for Message
[src]
impl From<DnsResponse> for Message
fn from(response: DnsResponse) -> Message
[src]
fn from(response: DnsResponse) -> Message
Performs the conversion.
impl From<Message> for DnsResponse
[src]
impl From<Message> for DnsResponse
fn from(message: Message) -> DnsResponse
[src]
fn from(message: Message) -> DnsResponse
Performs the conversion.