Struct Header

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

The first part of the header of a DNS message.

This type represents the information contained in the first four bytes of the header: the message ID, opcode, rcode, and the various flags.

The type’s data contains such a header in its wire format which 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. See Field Access below.

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§

Source§

impl Header

§Creation and Conversion

Source

pub fn new() -> Self

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.

Source

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

Creates a header reference from a byte slice of a message.

§Panics

This function panics if the byte slice is too short.

Source

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

Creates a mutable header reference from a byte slice of a message.

§Panics

This function panics if the byte slice is too short.

Source

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

Returns a reference to the underlying bytes slice.

Source§

impl Header

§Field Access

Source

pub fn id(self) -> u16

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.

Source

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

Sets the value of the ID field.

Source

pub fn set_random_id(&mut self)

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

This uses rand::random which may not be good enough.

Source

pub fn qr(self) -> bool

Returns whether the QR bit is set.

The QR bit specifies whether this 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.’

Source

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

Sets the value of the QR bit.

Source

pub fn opcode(self) -> Opcode

Returns the value of the Opcode field.

This field specifies the kind of query this 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 value set when creating a new header.

Source

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

Sets the value of the opcode field.

Source

pub fn aa(self) -> bool

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.

Source

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

Sets the value of the AA bit.

Source

pub fn tc(self) -> bool

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 to try again using a stream transport such as TCP.

Source

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

Sets the value of the TC bit.

Source

pub fn rd(self) -> bool

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.

Source

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

Sets the value of the RD bit.

Source

pub fn ra(self) -> bool

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.

Source

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

Sets the value of the RA bit.

Source

pub fn z(self) -> bool

Returns whether the reserved bit is set.

This bit must be false in all queries and responses.

Source

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

Sets the value of the reserved bit.

Source

pub fn ad(self) -> bool

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 to be authentic.

Source

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

Sets the value of the AD bit.

Source

pub fn cd(self) -> bool

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.

Source

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

Sets the value of the CD bit.

Source

pub fn rcode(self) -> Rcode

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.

Source

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

Sets the value of the RCODE field.

Trait Implementations§

Source§

impl Clone for Header

Source§

fn clone(&self) -> Header

Returns a duplicate 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() -> Header

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

impl PartialEq for Header

Source§

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

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

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

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl Copy for Header

Source§

impl Eq for Header

Source§

impl StructuralPartialEq for Header

Auto Trait Implementations§

§

impl Freeze for Header

§

impl RefUnwindSafe for Header

§

impl Send for Header

§

impl Sync for Header

§

impl Unpin for Header

§

impl UnwindSafe for Header

Blanket Implementations§

Source§

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

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

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

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

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

Source§

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

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where 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 T
where T: Clone,

Source§

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, U> TryFrom<U> for T
where U: Into<T>,

Source§

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 T
where U: TryFrom<T>,

Source§

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.