#dns-resolver #dns-client #dns #resolver #client-side #async #dns-query

cdns-rs

A native Sync/Async Rust implementation of client DNS resolver

7 releases

0.2.6 Mar 24, 2024
0.2.5 Mar 24, 2024
0.2.2 Jan 10, 2022
0.1.1 Nov 7, 2021

#516 in Network programming

Download history 10/week @ 2024-02-19 4/week @ 2024-02-26 4/week @ 2024-03-11 107/week @ 2024-03-18 218/week @ 2024-03-25 165/week @ 2024-04-01

494 downloads per month
Used in ipfw-rs

MPL-2.0 license

350KB
8K SLoC

CDns-rs

v 0.2 unstable

An implementation of client side DNS query library which also is able to look for host name in /etc/hosts.
Also it is able to /etc/resolv.conf and uses options from this file to configure itself. So it acts like libc's gethostbyname(3) or gethostbyaddr(3). The configuration can be overriden.

This library supports both async and sync code. At the moment async part is not available because:

  • it is based on the sync realization because async code is based on sync code and sync code is unstable at the moment
  • it requires proper porting from sync, because sync uses poll(2) to achieve the parallel name resolution

Supported

  • Sending and receiving responses via TCP/UDP
  • Reacting on the message truncated event by trying TCP
  • Parsing /etc/hosts (all options)
  • Partial parsing /etc/resolve.conf (all options)
  • Async and Sync code (separate implementations) At the moment async is not available!
  • Parallel and non parallel nameserver quries

ToDo

  • Parse /etc/nsswitch.conf
  • DNSSEC
  • DNS-over-TLS
  • OPT_NO_CHECK_NAMES
  • resolv.conf (search, domain, sortlist)

Usage:

  • see ./examples/
  • see shortcuts.rs

Simple Example:

use cdns_rs::sync::{QDns, QuerySetup, QType, request, caches::CACHE};

fn main()
{
    // a, aaaa
    let res_a = request::resolve_fqdn("protonmail.com", None).unwrap();

    println!("A/AAAA:");
    for a in res_a
    {
        println!("\t{}", a);
    }
}

Custom query:

use cdns_rs::sync::{QDns, QuerySetup, QType, request, caches::CACHE};

fn main()
{
    // soa
    let mut dns_req = 
        QDns::make_empty(resolvers, 1, QuerySetup::default());

    dns_req.add_request(QType::SOA, "protonmail.com");

    // sending request and receiving results
    let res = dns_req.query();


    println!("SOA:");
    if res.is_results() == true
    {
        let inner = res.into_inner().unwrap();

        for i in inner
        {
            for r in i.get_responses()
            {
                println!("\t{}", r);
            }
        }
    }
    else
    {
        println!("\tNo SOA found!")
    }
}

Dependencies

~5–16MB
~171K SLoC