Expand description

The Resolver is responsible for performing recursive queries to lookup domain names.

This is a 100% in process DNS resolver. It does not use the Host OS’ resolver. If what is desired is to use the Host OS’ resolver, generally in the system’s libc, then the std::net::ToSocketAddrs variant over &str should be used.

Unlike the trust-dns-client, this tries to provide a simpler interface to perform DNS queries. For update options, i.e. Dynamic DNS, the trust-dns-client crate must be used instead. The Resolver library is capable of searching multiple domains (this can be disabled by using an FQDN during lookup), dual-stack IPv4/IPv6 lookups, performing chained CNAME lookups, and features connection metric tracking for attempting to pick the best upstream DNS resolver.

Use AsyncResolver for performing DNS queries. AsyncResolver is a async-std based async resolver, and can be used inside any asyn-std based system.

This as best as possible attempts to abide by the DNS RFCs, please file issues at https://github.com/bluejekyll/trust-dns.

Usage

Declare dependency

[dependency]
async-std-resolver = "*"

Using the async-std Resolver

For more advanced asynchronous usage, the AsyncResolver is integrated with async-std.

use std::net::*;
use async_std::prelude::*;
use async_std_resolver::{resolver, config};

#[async_std::main]
async fn main() {
  // Construct a new Resolver with default configuration options
  let resolver = resolver(
    config::ResolverConfig::default(),
    config::ResolverOpts::default(),
  ).await.expect("failed to connect resolver");

  // Lookup the IP addresses associated with a name.
  // This returns a future that will lookup the IP addresses, it must be run in the Core to
  //  to get the actual result.
  let mut response = resolver.lookup_ip("www.example.com.").await.unwrap();

  // There can be many addresses associated with the name,
  //  this can return IPv4 and/or IPv6 addresses
  let address = response.iter().next().expect("no addresses returned!");
  if address.is_ipv4() {
    assert_eq!(address, IpAddr::V4(Ipv4Addr::new(93, 184, 216, 34)));
  } else {
    assert_eq!(address, IpAddr::V6(Ipv6Addr::new(0x2606, 0x2800, 0x220, 0x1, 0x248, 0x1893, 0x25c8, 0x1946)));
  }
}

Using the host system config

On Unix systems, the /etc/resolv.conf can be used for configuration. Not all options specified in the host systems resolv.conf are applicable or compatible with this software. In addition there may be additional options supported which the host system does not. Example:

use std::net::*;
use async_std::prelude::*;
use async_std_resolver::{resolver_from_system_conf, config};

#[async_std::main]
async fn main() {
  // Use the host OS'es `/etc/resolv.conf`
  let resolver = resolver_from_system_conf().await.unwrap();
  let response = resolver.lookup_ip("www.example.com.").await.unwrap();
}

Re-exports

pub use trust_dns_resolver::proto;

Modules

Configuration for a resolver

Lookup result from a resolution of ipv4 and ipv6 records with a Resolver.

LookupIp result from a resolution of ipv4 and ipv6 records with a Resolver.

Structs

The error type for errors that get returned in the crate

Functions

Construct a new async-std based AsyncResolver with the provided configuration.

Constructs a new async-std based Resolver with the system configuration.

Type Definitions

AsyncStd default connection

AsyncStd default connection provider

An AsyncResolver used with async_std