#dns-resolver #dns #dns-queries #async-dns #c-ares #dns-query #dns-lookup

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

#676 in Asynchronous

Download history 1/week @ 2024-07-18 31/week @ 2024-07-25 6/week @ 2024-08-01 7/week @ 2024-09-19 2/week @ 2024-09-26

357 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

~3–11MB
~138K SLoC