domain::base::header

Struct HeaderCounts

source
pub struct HeaderCounts { /* private fields */ }
Expand description

The section count part of the header section of a DNS message.

This part consists of four 16 bit counters for the number of entries in the four sections of a DNS message. The type contains the sequence of these for values in wire format, i.e., in network byte order.

The counters are arranged in the same order as the sections themselves: QDCOUNT for the question section, ANCOUNT for the answer section, NSCOUNT for the authority section, and ARCOUNT for the additional section. These are defined in RFC 1035.

Like with the other header part, you can create an owned value via the new method or the Default trait or can get a reference to the value atop a message slice via for_message_slice or for_message_slice_mut.

For each field there are three methods for getting, setting, and incrementing.

RFC 2136 defines the UPDATE method and reuses the four section for different purposes. Here the counters are ZOCOUNT for the zone section, PRCOUNT for the prerequisite section, UPCOUNT for the update section, and ADCOUNT for the additional section. The type has convenience methods for these fields as well so you don’t have to remember which is which.

Implementations§

source§

impl HeaderCounts

§Creation and Conversion

source

pub fn new() -> Self

Creates a new value with all counters set to zero.

source

pub fn for_message_slice(message: &[u8]) -> &Self

Creates a header counts reference from the octets slice of a message.

The slice message mut be the whole message, i.e., start with the bytes of the Header.

§Panics

This function panics if the octets slice is shorter than 24 octets.

source

pub fn for_message_slice_mut(message: &mut [u8]) -> &mut Self

Creates a mutable counts reference from the octets slice of a message.

The slice message mut be the whole message, i.e., start with the bytes of the Header.

§Panics

This function panics if the octets slice is shorter than 24 octets.

source

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

Returns a reference to the raw octets slice of the header counts.

source

pub fn as_slice_mut(&mut self) -> &mut [u8]

Returns a mutable reference to the octets slice of the header counts.

source

pub fn set(&mut self, counts: HeaderCounts)

Sets the counts to those from counts.

source§

impl HeaderCounts

§Field Access

source

pub fn qdcount(self) -> u16

Returns the value of the QDCOUNT field.

This field contains the number of questions in the first section of the message, normally the question section.

source

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

Sets the value of the QDCOUNT field.

source

pub fn inc_qdcount(&mut self) -> Result<(), CountOverflow>

Increases the value of the QDCOUNT field by one.

If increasing the counter would result in an overflow, returns an error.

source

pub fn dec_qdcount(&mut self)

Decreases the value of the QDCOUNT field by one.

§Panics

This method panics if the count is already zero.

source

pub fn ancount(self) -> u16

Returns the value of the ANCOUNT field.

This field contains the number of resource records in the second section of the message, normally the answer section.

source

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

Sets the value of the ANCOUNT field.

source

pub fn inc_ancount(&mut self) -> Result<(), CountOverflow>

Increases the value of the ANCOUNT field by one.

If increasing the counter would result in an overflow, returns an error.

source

pub fn dec_ancount(&mut self)

Decreases the value of the ANCOUNT field by one.

§Panics

This method panics if the count is already zero.

source

pub fn nscount(self) -> u16

Returns the value of the NSCOUNT field.

This field contains the number of resource records in the third section of the message, normally the authority section.

source

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

Sets the value of the NSCOUNT field.

source

pub fn inc_nscount(&mut self) -> Result<(), CountOverflow>

Increases the value of the NSCOUNT field by one.

If increasing the counter would result in an overflow, returns an error.

source

pub fn dec_nscount(&mut self)

Decreases the value of the NSCOUNT field by one.

§Panics

This method panics if the count is already zero.

source

pub fn arcount(self) -> u16

Returns the value of the ARCOUNT field.

This field contains the number of resource records in the fourth section of the message, normally the additional section.

source

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

Sets the value of the ARCOUNT field.

source

pub fn inc_arcount(&mut self) -> Result<(), CountOverflow>

Increases the value of the ARCOUNT field by one.

If increasing the counter would result in an overflow, returns an error.

source

pub fn dec_arcount(&mut self)

Decreases the value of the ARCOUNT field by one.

§Panics

This method panics if the count is already zero.

source

pub fn zocount(self) -> u16

Returns the value of the ZOCOUNT field.

This is the same as the qdcount(). It is used in UPDATE queries where the first section is the zone section.

source

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

Sets the value of the ZOCOUNT field.

source

pub fn prcount(self) -> u16

Returns the value of the PRCOUNT field.

This is the same as the ancount(). It is used in UPDATE queries where the first section is the prerequisite section.

source

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

Sete the value of the PRCOUNT field.

source

pub fn upcount(self) -> u16

Returns the value of the UPCOUNT field.

This is the same as the nscount(). It is used in UPDATE queries where the first section is the update section.

source

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

Sets the value of the UPCOUNT field.

source

pub fn adcount(self) -> u16

Returns the value of the ADCOUNT field.

This is the same as the arcount(). It is used in UPDATE queries where the first section is the additional section.

source

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

Sets the value of the ADCOUNT field.

Trait Implementations§

source§

impl AsMut<HeaderCounts> for HeaderSection

source§

fn as_mut(&mut self) -> &mut HeaderCounts

Converts this type into a mutable reference of the (usually inferred) input type.
source§

impl AsRef<HeaderCounts> for HeaderSection

source§

fn as_ref(&self) -> &HeaderCounts

Converts this type into a shared reference of the (usually inferred) input type.
source§

impl Clone for HeaderCounts

source§

fn clone(&self) -> HeaderCounts

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 HeaderCounts

source§

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

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

impl Default for HeaderCounts

source§

fn default() -> HeaderCounts

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

impl PartialEq for HeaderCounts

source§

fn eq(&self, other: &HeaderCounts) -> 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 HeaderCounts

source§

impl Eq for HeaderCounts

source§

impl StructuralPartialEq for HeaderCounts

Auto Trait Implementations§

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, dst: *mut T)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dst. Read more
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 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<Source, Target> OctetsInto<Target> for Source
where Target: OctetsFrom<Source>,

source§

type Error = <Target as OctetsFrom<Source>>::Error

source§

fn try_octets_into( self, ) -> Result<Target, <Source as OctetsInto<Target>>::Error>

Performs the conversion.
source§

fn octets_into(self) -> Target
where Self::Error: Into<Infallible>,

Performs an infallible conversion.
source§

impl<T> Pointable for T

source§

const ALIGN: usize = _

The alignment of pointer.
source§

type Init = T

The type for initializers.
source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
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.
source§

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

source§

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