#c-ares #dns #future

c-ares-resolver

An asynchronous DNS resolver, backed by c-ares

38 stable releases (10 major)

10.1.0 Oct 10, 2024
9.0.0 Jun 7, 2024
8.5.1 May 26, 2024
8.3.0 Feb 23, 2024
0.2.0 Nov 20, 2016

#112 in Asynchronous

Download history 987/week @ 2024-12-15 402/week @ 2024-12-22 651/week @ 2024-12-29 945/week @ 2025-01-05 935/week @ 2025-01-12 749/week @ 2025-01-19 903/week @ 2025-01-26 938/week @ 2025-02-02 1239/week @ 2025-02-09 1069/week @ 2025-02-16 642/week @ 2025-02-23 935/week @ 2025-03-02 928/week @ 2025-03-09 660/week @ 2025-03-16 1018/week @ 2025-03-23 864/week @ 2025-03-30

3,603 downloads per month
Used in 9 crates (3 directly)

MIT license

70KB
1K SLoC

c-ares-resolver

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 std::future::Futures.
  • The BlockingResolver isn't asynchronous at all - as the name suggests, it blocks until the lookup completes.

Crates.io Build Status

Documentation

API documentation is here.

Setting the feature build-cmake will cause the c-ares library to be built using cmake. This is significantly faster than the default autotools build on unix platforms: so if it works for you, you should probably prefer it.

Examples

extern crate c_ares_resolver;
extern crate futures_executor;
use futures_executor::block_on;

fn main() {
    let resolver = c_ares_resolver::FutureResolver::new().unwrap();
    let query = resolver.query_a("google.com");
    let response = block_on(query);
    match response {
        Ok(result) => println!("{}", result),
        Err(e) => println!("Lookup failed with error '{}'", e)
    }
}

Further example programs can be found here.

Contributing

Contributions are welcome. Please send pull requests!

Dependencies

~5–14MB
~216K SLoC