Crate c_ares_resolver

source ·
Expand description

DNS resolvers built on c-ares, for asynchronous DNS requests.

This crate provides three resolver types - the Resolver, the FutureResolver, and the BlockingResolver:

  • The Resolver is the thinnest wrapper around the underlying c-ares library. It returns answers via callbacks. The other resolvers are built on top of this.

  • The FutureResolver returns answers as futures::Futures.

  • The BlockingResolver isn’t asynchronous at all - as the name suggests, it blocks until the lookup completes.

On all resolvers:

  • methods like query_xxx correspond to the c-ares function ares_query, which “initiates a single-question DNS query”.

  • methods like search_xxx correspond to the c-ares function ares_search, which “initiates a series of single-question DNS queries … using the channel’s search domains as well as a host alias file given by the HOSTALIAS environment variable”.

See c-ares documentation for more details.

Example

extern crate c_ares_resolver;
extern crate futures;
extern crate tokio;
use std::error::Error;
use futures::future::Future;

fn main() {
    let resolver = c_ares_resolver::FutureResolver::new().unwrap();
    let query = resolver
        .query_a("google.com")
        .map_err(|e| println!("Lookup failed with error '{}'", e.description()))
        .map(|result| println!("{}", result));
    tokio::run(query);
}

Further examples showing how to use the library can be found here.

Structs

A blocking DNS resolver.
The type of future returned by methods on the FutureResolver.
An asynchronous DNS resolver, which returns results as futures::Futures.
An owned version of c_ares::HostResults.
An owned version of c_ares::NameInfoResult.
Used to configure the behaviour of the resolver.
An asynchronous DNS resolver, which returns results via callbacks.

Enums

Error codes that the library might return.