c-ares-resolver 0.4.2

An asynchronous DNS resolver, backed by c-ares.

Crate c_ares_resolver [] [src]

A convenient wrapper for the c-ares library.

The c-ares crate provides a safe wrapper around the underlying C library, but it's relatively hard work to use: the user needs to drive the polling of file descriptors according to c-ares demands, which likely involves writing something close to a full-blown event loop.

This crate does that hard work for you so that the presented API is much more straightforward. Simply create a Resolver, and make your query - providing a callback to be called when the query completes.

This crate also provides a FutureResolver. Queries on this object return futures::Future objects, and don't use callbacks.

(The API on the FutureResolver isn't quite as complete as on the Resolver. For some types of query, the values returned by c-ares do not have a long enough lifetime to be returned in a Future. The relevant functions are not supported by the FutureResolver.)

On both 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".

See c-ares documentation for more details.

Example

extern crate c_ares_resolver;
extern crate tokio_core;

fn main() {
    let resolver = c_ares_resolver::FutureResolver::new().unwrap();
    let query = resolver.query_a("google.com");
    let mut event_loop = tokio_core::reactor::Core::new().unwrap();
    let result = event_loop.run(query).unwrap();
    println!("{}", result);
}

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

Structs

FutureResolver

An asynchronous DNS resolver, which returns results as futures::Futures.

Options

Used to configure the behaviour of the resolver.

Resolver

An asynchronous DNS resolver.

Enums

Error

Error codes that the library might return.

Type Definitions

CAresFuture

The type of future returned by methods on the FutureResolver.