#dns #c-ares #futures

mini-c-ares-resolver

An asynchronous DNS resolver, backed by mini-c-ares

4 releases

0.2.2 Oct 10, 2023
0.2.1 Sep 18, 2023
0.2.0 Aug 28, 2023
0.1.0 Jul 31, 2023

#3 in #c-ares

Download history 153/week @ 2023-07-29 3/week @ 2023-08-05 1/week @ 2023-08-12 1/week @ 2023-08-19 124/week @ 2023-08-26 214/week @ 2023-09-02 312/week @ 2023-09-09 200/week @ 2023-09-16 40/week @ 2023-09-23 2/week @ 2023-09-30 188/week @ 2023-10-07 229/week @ 2023-10-14 178/week @ 2023-10-21 198/week @ 2023-10-28 221/week @ 2023-11-04

888 downloads per month

MIT license

58KB
978 lines

mini-c-ares-resolver

A fork of c-ares-resolver, which use mini-c-ares instead of 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.

Documentation

API documentation is here.

Contributing

Contributions should be sent to c-ares-resolver.


lib.rs:

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.

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

use futures_executor::block_on;

fn main() {
    let resolver = mini_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 examples showing how to use the library can be found here.

Dependencies

~1–10MB
~109K SLoC