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
is what should be used. As of the initial release, trust-dns-resolver
it does not currently support search paths or ndot recursive lookups. It only supports FQDN, where the name must be specified with the final dot, e.g. www.example.com.
. This limitation will be removed in future releases.
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
crate must be used directly.
There are two types for performing DNS queries, Resolver
and ResolverFuture
. Resolver
is the easiest to work with, it is a wrapper around ResolverFuture
. ResolverFuture
is a Tokio
based async resolver, and can be used inside any Tokio
based system.
Notes on current limitations: DNSSec is not yet supported in the Resolver, use the trust-dns
Client if DNSSec validation is needed. Many standard system options and configurations are not yet supported. The host system /etc/resolv.conf
is not yet being used. Recursion is not yet built, i.e. CNAME chains will not be fully resolved if an address is not returned, though many upstream resolvers will perform this making it a none blocking issue.
This as best as possible attempts to abide by the the DNS RFCs, please file issues at https://github.com/bluejekyll/trust-dns .
Usage
Declare dependency
[]
= "^0.1"
Extern the crate for usage in the library
extern crate trust_dns_resolver;
Using the Synchronous Resolver
This uses the default configuration. Currently this sets the google resolvers as the upstream resolvers.
use *;
use Resolver;
use *;
// Construct a new Resolver with default configuration options
let mut resolver = new.unwrap;
// Lookup the IP addresses associated with a name.
// NOTE: do not forget the final dot, as the resolver does not yet support search paths.
let mut response = resolver.lookup_ip.unwrap;
// There can be many addresses associated with the name,
// this can return IPv4 and/or IPv6 addresses
let address = response.next.expect;
if address.is_ipv4 else
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 *;
# use Resolver;
// Use the host OS'es `/etc/resolv.conf`
let mut resolver = from_system_conf.unwrap;
let mut response = resolver.lookup_ip.unwrap;
Using the Tokio/Async Resolver
For more advanced asynchronous usage, the ResolverFuture is integrated with Tokio. In fact, the ResolverFuture is used by the synchronous Resolver for all lookups.
# extern crate futures;
# extern crate tokio_core;
# extern crate trust_dns_resolver;
#
Generally after a lookup in an asynchornous context, there would probably be a connection made to a server, for example:
let result = io_loop..;
It's beyond the scope of these examples to show how to deal with connection failures and looping etc. But if you wanted to say try a different address from the result set after a connection failure, it will be necessary to create a type that implements the Future
trait. Inside the Future::poll
method would be the place to implement a loop over the different IP addresses.