dns_parser

Struct Builder

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

Allows to build a DNS packet

Both query and answer packets may be built with this interface, although, much of functionality is not implemented yet.

Implementations§

Source§

impl Builder

Source

pub fn new_query(id: u16, recursion: bool) -> Builder

Creates a new query

Initially all sections are empty. You’re expected to fill the questions section with add_question

Source

pub fn add_question( &mut self, qname: &str, prefer_unicast: bool, qtype: QueryType, qclass: QueryClass, ) -> &mut Builder

Adds a question to the packet

§Panics
  • Answers, nameservers or additional section has already been written
  • There are already 65535 questions in the buffer.
  • When name is invalid
Source

pub fn build(self) -> Result<Vec<u8>, Vec<u8>>

Returns the final packet

When packet is not truncated method returns Ok(packet). If packet is truncated the method returns Err(packet). In both cases the packet is fully valid.

In the server implementation you may use x.build().unwrap_or_else(|x| x).

In the client implementation it’s probably unwise to send truncated packet, as it doesn’t make sense. Even panicking may be more appropriate.

Trait Implementations§

Source§

impl Debug for Builder

Source§

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

Formats the value using the given formatter. Read more

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> 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, 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.