embedded_nal_async

Trait Dns

Source
pub trait Dns {
    type Error: Debug;

    // Required methods
    async fn get_host_by_name(
        &self,
        host: &str,
        addr_type: AddrType,
    ) -> Result<IpAddr, Self::Error>;
    async fn get_host_by_address(
        &self,
        addr: IpAddr,
        result: &mut [u8],
    ) -> Result<usize, Self::Error>;
}
Expand description

This trait is an extension trait for TcpStack and UdpStack for dns resolutions. It does not handle every DNS record type, but is meant as an embedded alternative to ToSocketAddrs, and is as such meant to resolve an ip address from a hostname, or a hostname from an ip address. This means that it only deals in host address records A (IPv4) and AAAA (IPv6).

Required Associated Types§

Source

type Error: Debug

The type returned when we have an error

Required Methods§

Source

async fn get_host_by_name( &self, host: &str, addr_type: AddrType, ) -> Result<IpAddr, Self::Error>

Resolve the first ip address of a host, given its hostname and a desired address record type to look for

Source

async fn get_host_by_address( &self, addr: IpAddr, result: &mut [u8], ) -> Result<usize, Self::Error>

Resolve the hostname of a host, given its ip address.

The hostname is stored at the beginning of result, the length is returned.

If the buffer is too small to hold the domain name, an error should be returned.

Note: A fully qualified domain name (FQDN), has a maximum length of 255 bytes according to rfc1035. Therefore, you can pass a 255-byte long buffer to guarantee it’ll always be large enough.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementations on Foreign Types§

Source§

impl<T: Dns> Dns for &T

Source§

type Error = <T as Dns>::Error

Source§

async fn get_host_by_name( &self, host: &str, addr_type: AddrType, ) -> Result<IpAddr, Self::Error>

Source§

async fn get_host_by_address( &self, addr: IpAddr, result: &mut [u8], ) -> Result<usize, Self::Error>

Implementors§