pub struct Header { /* private fields */ }
Expand description

Metadata for the Message struct.

RFC 1035, DOMAIN NAMES - IMPLEMENTATION AND SPECIFICATION, November 1987

4.1.1. Header section format

The header contains the following fields

                                   1  1  1  1  1  1
     0  1  2  3  4  5  6  7  8  9  0  1  2  3  4  5
    +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
    |                      ID                       |
    +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
    |QR|   Opcode  |AA|TC|RD|RA|ZZ|AD|CD|   RCODE   |  /// AD and CD from RFC4035
    +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
    |                    QDCOUNT / ZCOUNT           |
    +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
    |                    ANCOUNT / PRCOUNT          |
    +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
    |                    NSCOUNT / UPCOUNT          |
    +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
    |                    ARCOUNT / ADCOUNT          |
    +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+

where

Z               Reserved for future use.  Must be zero in all queries
                and responses.

Implementations§

source§

impl Header

source

pub const fn new() -> Self

A default Header, not very useful.

source

pub fn response_from_request(header: &Self) -> Self

Construct a new header based off the request header. This copies over the RD (recursion-desired) and CD (checking-disabled), as well as the op_code and id of the request.

See https://datatracker.ietf.org/doc/html/rfc6895#section-2

The AA, TC, RD, RA, and CD bits are each theoretically meaningful
   only in queries or only in responses, depending on the bit.  The AD
   bit was only meaningful in responses but is expected to have a
   separate but related meaning in queries (see Section 5.7 of
   [RFC6840]).  Only the RD and CD bits are expected to be copied from
   the query to the response; however, some DNS implementations copy all
   the query header as the initial value of the response header.  Thus,
   any attempt to use a "query" bit with a different meaning in a
   response or to define a query meaning for a "response" bit may be
   dangerous, given the existing implementation.  Meanings for these
   bits may only be assigned by a Standards Action.
source

pub fn len() -> usize

Length of the header, always 12 bytes

source

pub fn set_id(&mut self, id: u16) -> &mut Self

Sets the id of the message, for queries this should be random.

source

pub fn set_message_type(&mut self, message_type: MessageType) -> &mut Self

Sets the message type, Queries and Updates both use Query.

source

pub fn set_op_code(&mut self, op_code: OpCode) -> &mut Self

Set the operation code for the message

source

pub fn set_authoritative(&mut self, authoritative: bool) -> &mut Self

From the server is specifies that it is an authoritative response.

source

pub fn set_truncated(&mut self, truncated: bool) -> &mut Self

Specifies that the records were too large for the payload.

See EDNS or TCP for resolutions to truncation.

source

pub fn set_recursion_desired(&mut self, recursion_desired: bool) -> &mut Self

Specify that the resolver should recursively request data from upstream DNS nodes

source

pub fn set_recursion_available( &mut self, recursion_available: bool ) -> &mut Self

Specifies that recursion is available from this or the remote resolver

source

pub fn set_authentic_data(&mut self, authentic_data: bool) -> &mut Self

Specifies that the data is authentic, i.e. the resolver believes all data to be valid through DNSSEC

source

pub fn set_checking_disabled(&mut self, checking_disabled: bool) -> &mut Self

Used during recursive resolution to specified if a resolver should or should not validate DNSSEC signatures

source

pub fn flags(&self) -> Flags

A method to get all header flags (useful for Display purposes)

source

pub fn set_response_code(&mut self, response_code: ResponseCode) -> &mut Self

The low response code (original response codes before EDNS extensions)

source

pub fn set_query_count(&mut self, query_count: u16) -> &mut Self

Number or query records in the message

source

pub fn set_answer_count(&mut self, answer_count: u16) -> &mut Self

Number of answer records in the message

source

pub fn set_name_server_count(&mut self, name_server_count: u16) -> &mut Self

Number of name server records in the message

source

pub fn set_additional_count(&mut self, additional_count: u16) -> &mut Self

Number of additional records in the message

source

pub fn id(&self) -> u16

ID              A 16 bit identifier assigned by the program that
                generates any kind of query.  This identifier is copied
                the corresponding reply and can be used by the requester
                to match up replies to outstanding queries.
source

pub fn message_type(&self) -> MessageType

QR              A one bit field that specifies whether this message is a
                query (0), or a response (1).
source

pub fn op_code(&self) -> OpCode

OPCODE          A four bit field that specifies kind of query in this
                message.  This value is set by the originator of a query
                and copied into the response.  The values are: <see super::op_code>
source

pub fn authoritative(&self) -> bool

AA              Authoritative Answer - this bit is valid in responses,
                and specifies that the responding name server is an
                authority for the domain name in question section.

                Note that the contents of the answer section may have
                multiple owner names because of aliases.  The AA bit
                corresponds to the name which matches the query name, or
                the first owner name in the answer section.
source

pub fn truncated(&self) -> bool

TC              TrunCation - specifies that this message was truncated
                due to length greater than that permitted on the
                transmission channel.
source

pub fn recursion_desired(&self) -> bool

RD              Recursion Desired - this bit may be set in a query and
                is copied into the response.  If RD is set, it directs
                the name server to pursue the query recursively.
                Recursive query support is optional.
source

pub fn recursion_available(&self) -> bool

RA              Recursion Available - this be is set or cleared in a
                response, and denotes whether recursive query support is
                available in the name server.
source

pub fn authentic_data(&self) -> bool

RFC 4035, DNSSEC Resource Records, March 2005


3.1.6.  The AD and CD Bits in an Authoritative Response

  The CD and AD bits are designed for use in communication between
  security-aware resolvers and security-aware recursive name servers.
  These bits are for the most part not relevant to query processing by
  security-aware authoritative name servers.

  A security-aware name server does not perform signature validation
  for authoritative data during query processing, even when the CD bit
  is clear.  A security-aware name server SHOULD clear the CD bit when
  composing an authoritative response.

  A security-aware name server MUST NOT set the AD bit in a response
  unless the name server considers all RRsets in the Answer and
  Authority sections of the response to be authentic.  A security-aware
  name server's local policy MAY consider data from an authoritative
  zone to be authentic without further validation.  However, the name
  server MUST NOT do so unless the name server obtained the
  authoritative zone via secure means (such as a secure zone transfer
  mechanism) and MUST NOT do so unless this behavior has been
  configured explicitly.

  A security-aware name server that supports recursion MUST follow the
  rules for the CD and AD bits given in Section 3.2 when generating a
  response that involves data obtained via recursion.
source

pub fn checking_disabled(&self) -> bool

see is_authentic_data()

source

pub fn response_code(&self) -> ResponseCode

RCODE           Response code - this 4 bit field is set as part of
                responses.  The values have the following
                interpretation: <see super::response_code>
source

pub fn query_count(&self) -> u16

QDCOUNT         an unsigned 16 bit integer specifying the number of
                entries in the question section.
Return value

If this is a query, this will return the number of queries in the query section of the

source

pub fn answer_count(&self) -> u16

ANCOUNT         an unsigned 16 bit integer specifying the number of
                resource records in the answer section.
Return value

For query responses this is the number of records in the answer section, should be 0 for requests, for updates this is the count of prerequisite records.

source

pub fn name_server_count(&self) -> u16

for queries this is the nameservers which are authorities for the SOA of the Record for updates this is the update record count

NSCOUNT         an unsigned 16 bit integer specifying the number of name
                server resource records in the authority records
                section.
Return value

For query responses this is the number of authorities, or nameservers, in the name server section, for updates this is the number of update records being sent.

source

pub fn additional_count(&self) -> u16

ARCOUNT         an unsigned 16 bit integer specifying the number of
                resource records in the additional records section.
Return value

This is the additional record section count, this section may include EDNS options.

Trait Implementations§

source§

impl<'r> BinDecodable<'r> for Header

source§

fn read(decoder: &mut BinDecoder<'r>) -> ProtoResult<Self>

Read the type from the stream
source§

fn from_bytes(bytes: &'r [u8]) -> ProtoResult<Self>

Returns the object in binary form
source§

impl BinEncodable for Header

source§

fn emit(&self, encoder: &mut BinEncoder<'_>) -> ProtoResult<()>

Write the type to the stream
source§

fn to_bytes(&self) -> ProtoResult<Vec<u8>>

Returns the object in binary form
source§

impl Clone for Header

source§

fn clone(&self) -> Header

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl Debug for Header

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl Default for Header

source§

fn default() -> Self

Returns the “default value” for a type. Read more
source§

impl Display for Header

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>

Formats the value using the given formatter. Read more
source§

impl Hash for Header

source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · source§

fn hash_slice<H>(data: &[Self], state: &mut H)where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
source§

impl PartialEq for Header

source§

fn eq(&self, other: &Header) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl PartialOrd for Header

source§

fn partial_cmp(&self, other: &Header) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 · source§

fn lt(&self, other: &Rhs) -> bool

This method tests less than (for self and other) and is used by the < operator. Read more
1.0.0 · source§

fn le(&self, other: &Rhs) -> bool

This method tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 · source§

fn gt(&self, other: &Rhs) -> bool

This method tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 · source§

fn ge(&self, other: &Rhs) -> bool

This method tests greater than or equal to (for self and other) and is used by the >= operator. Read more
source§

impl Copy for Header

source§

impl Eq for Header

source§

impl StructuralEq for Header

source§

impl StructuralPartialEq for Header

Auto Trait Implementations§

Blanket Implementations§

source§

impl<T> Any for Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for Twhere T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
§

impl<Q, K> Equivalent<K> for Qwhere Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. Read more
§

impl<Q, K> Equivalent<K> for Qwhere Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

§

fn equivalent(&self, key: &K) -> bool

Compare self to key and return true if they are equal.
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T> Instrument for T

source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
source§

impl<T, U> Into<U> for Twhere U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T> ToOwned for Twhere T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

impl<T> ToString for Twhere T: Display + ?Sized,

source§

default fn to_string(&self) -> String

Converts the given value to a String. Read more
source§

impl<T, U> TryFrom<U> for Twhere U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for Twhere U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
§

impl<V, T> VZip<V> for Twhere V: MultiLane<T>,

§

fn vzip(self) -> V

source§

impl<T> WithSubscriber for T

source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more