xarxa

Crates

git

Versions

default

Flavors

Skip to main content

DnsClient

Struct DnsClient 

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

A DNS client.

Owns a UDP socket inside the Stack, bound to an ephemeral port. Remove it with remove to free the socket.

Implementations§

Source§

impl DnsClient

Source

pub fn new( stack: &mut Stack<'_>, servers: &[IpAddress], ) -> Result<DnsClient, Full>

Create a DNS client.

Creates and binds a UDP socket in stack. Truncates the server list if servers.len() > DNS_MAX_SERVER_COUNT.

Errors:

  • Full if the stack has no room for another UDP socket.
Source

pub fn remove(self, stack: &mut Stack<'_>)

Destroy the client, removing its UDP socket from stack.

Pending queries are cancelled.

Source

pub fn socket(&self) -> UdpHandle

The UDP socket the client sends and receives on.

Use it to set the hop limit. Don’t bind, close or read from it.

Source

pub fn update_servers(&mut self, servers: &[IpAddress])

Update the list of DNS servers, will replace all existing servers

Truncates the server list if servers.len() > DNS_MAX_SERVER_COUNT.

Source

pub fn start_query( &mut self, stack: &mut Stack<'_>, name: &str, query_type: Type, ) -> Result<DnsQueryHandle, StartQueryError>

Start a query.

name is specified in human-friendly format, such as "rust-lang.org". It accepts names both with and without trailing dot, and they’re treated the same (there’s no support for DNS search path).

With the mdns feature, names ending in .local are sent with multicast DNS.

Source

pub fn start_query_raw( &mut self, stack: &mut Stack<'_>, raw_name: &[u8], query_type: Type, mdns: MulticastDns, ) -> Result<DnsQueryHandle, StartQueryError>

Start a query with a raw (wire-format) DNS name, such as b"\x09rust-lang\x03org\x00".

You probably want to use start_query instead.

Source

pub fn get_query_result( &mut self, handle: DnsQueryHandle, ) -> Result<Vec<IpAddress, DNS_MAX_RESULT_COUNT>, GetQueryResultError>

Get the result of a query.

If the query is completed, the query slot is automatically freed.

§Panics

Panics if the handle corresponds to a free slot.

Source

pub fn cancel_query(&mut self, handle: DnsQueryHandle)

Cancels a query, freeing the slot.

§Panics

Panics if the handle corresponds to an already free slot.

Source

pub fn register_query_waker(&mut self, handle: DnsQueryHandle, waker: &Waker)

Assign a waker to a query slot.

The waker will be woken when the query completes, either successfully or failed.

§Panics

Panics if the handle corresponds to an already free slot.

Source

pub fn poll(&mut self, stack: &mut Stack<'_>) -> Instant

Advance the client: process received responses and send due queries.

Uses the time of the last Stack::poll.

Returns the next time poll should be called to retransmit a query, or Instant::MAX if no query is pending. Call it after every Stack::poll, and again when that deadline arrives.

Trait Implementations§

Source§

impl Debug for DnsClient

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 = !

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.