[][src]Struct domain::base::header::Header

pub struct Header { /* fields omitted */ }

The first part of the header of a DNS message.

This type represents the information contained in the first four octets of the header: the message ID, opcode, rcode, and the various flags. It keeps those four octets in wire representation, i.e., in network byte order. The data is layed out like this:

                                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|Z |AD|CD|   RCODE   |
+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+

Methods are available for accessing each of these fields. For more information on the fields, see these methods in the section Field Access below.

You can create owned values via the new methods or Default trait. However, more often the type will be used via a reference into the octets of an actual message. The functions for_message_slice and for_message_slice_mut create such references from an octets slice.

The basic structure and most of the fields re defined in RFC 1035, except for the AD and CD flags, which are defined in RFC 4035.

Implementations

impl Header[src]

pub fn new() -> Self[src]

Creates a new header.

The new header has all fields as either zero or false. Thus, the opcode will be Opcode::Query and the response code will be Rcode::NoError.

pub fn for_message_slice(s: &[u8]) -> &Header[src]

Creates a header reference from an octets slice of a message.

Panics

This function panics if the slice is less than four octets long.

pub fn for_message_slice_mut(s: &mut [u8]) -> &mut Header[src]

Creates a mutable header reference from an octets slice of a message.

Panics

This function panics if the slice is less than four octets long.

pub fn as_slice(&self) -> &[u8][src]

Returns a reference to the underlying octets slice.

impl Header[src]

pub fn id(self) -> u16[src]

Returns the value of the ID field.

The ID field is an identifier chosen by whoever created a query and is copied into a response by a server. It allows matching incoming responses to their queries.

When choosing an ID for an outgoing message, make sure it is random to avoid spoofing through guessing the message ID. The method set_random_id can be used for this purpose.

pub fn set_id(&mut self, value: u16)[src]

Sets the value of the ID field.

pub fn set_random_id(&mut self)[src]

Sets the value of the ID field to a randomly chosen number.

pub fn qr(self) -> bool[src]

Returns whether the QR bit is set.

The QR bit specifies whether a message is a query (false) or a response (true). In other words, this bit is actually stating whether the message is not a query. So, perhaps it might be good to read ‘QR’ as ‘query response.’

pub fn set_qr(&mut self, set: bool)[src]

Sets the value of the QR bit.

pub fn opcode(self) -> Opcode[src]

Returns the value of the Opcode field.

This field specifies the kind of query a message contains. See the Opcode type for more information on the possible values and their meaning. Normal queries have the variant Opcode::Query which is also the default value when creating a new header.

pub fn set_opcode(&mut self, opcode: Opcode)[src]

Sets the value of the opcode field.

pub fn aa(self) -> bool[src]

Returns whether the AA bit is set.

Using this bit, a name server generating a response states whether it is authoritative for the requested domain name, ie., whether this response is an authoritative answer. The field has no meaning in a query.

pub fn set_aa(&mut self, set: bool)[src]

Sets the value of the AA bit.

pub fn tc(self) -> bool[src]

Returns whether the TC bit is set.

The truncation bit is set if there was more data available then fit into the message. This is typically used when employing datagram transports such as UDP to signal that the answer didn’t fit into a response and the query should be tried again using a stream transport such as TCP.

pub fn set_tc(&mut self, set: bool)[src]

Sets the value of the TC bit.

pub fn rd(self) -> bool[src]

Returns whether the RD bit is set.

The recursion desired bit may be set in a query to ask the name server to try and recursively gather a response if it doesn’t have the data available locally. The bit’s value is copied into the response.

pub fn set_rd(&mut self, set: bool)[src]

Sets the value of the RD bit.

pub fn ra(self) -> bool[src]

Returns whether the RA bit is set.

In a response, the recursion available bit denotes whether the responding name server supports recursion. It has no meaning in a query.

pub fn set_ra(&mut self, set: bool)[src]

Sets the value of the RA bit.

pub fn z(self) -> bool[src]

Returns whether the reserved bit is set.

This bit must be false in all queries and responses.

pub fn set_z(&mut self, set: bool)[src]

Sets the value of the reserved bit.

pub fn ad(self) -> bool[src]

Returns whether the AD bit is set.

The authentic data bit is used by security-aware recursive name servers to indicate that it considers all RRsets in its response are authentic, i.e., have successfully passed DNSSEC validation.

pub fn set_ad(&mut self, set: bool)[src]

Sets the value of the AD bit.

pub fn cd(self) -> bool[src]

Returns whether the CD bit is set.

The checking disabled bit is used by a security-aware resolver to indicate that it does not want upstream name servers to perform verification but rather would like to verify everything itself.

pub fn set_cd(&mut self, set: bool)[src]

Sets the value of the CD bit.

pub fn rcode(self) -> Rcode[src]

Returns the value of the RCODE field.

The response code is used in a response to indicate what happened when processing the query. See the Rcode type for information on possible values and their meaning.

pub fn set_rcode(&mut self, rcode: Rcode)[src]

Sets the value of the RCODE field.

Trait Implementations

impl AsMut<Header> for HeaderSection[src]

impl AsRef<Header> for HeaderSection[src]

impl Clone for Header[src]

impl Copy for Header[src]

impl Debug for Header[src]

impl Default for Header[src]

impl Eq for Header[src]

impl PartialEq<Header> for Header[src]

impl StructuralEq for Header[src]

impl StructuralPartialEq for Header[src]

Auto Trait Implementations

impl RefUnwindSafe for Header

impl Send for Header

impl Sync for Header

impl Unpin for Header

impl UnwindSafe for Header

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

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

The type returned in the event of a conversion error.

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