Crate cdns_rs

source ·
Expand description

cdns-rs

An implementation of client side DNS query library - a resolver, a set of routines that provide access to the Internet Domain Name System (DNS).

This library provides both: sync and async crates to query remote DNS servers and local hosts file.

This code will be considered stable only when the major part of verion number will reach v 1.x.x

§Limitations

  • This library reads /etc/hosts and partially understands /etc/resolv.conf i.e only ‘nameserver’ option is parsed at the moment.
  • This library does not support TCP query at the moment.
  • The nsswitch.conf is also ignored as this crate at the moment is not pretending to be a glibc/libc replacement.
  • Does not support DNS-over-TLS at the moment
  • Does not support DNSSEC at the moment
  • /etc/resolve.conf is limited to ‘nameserver’

§Supports

Supported GNU/Linux and *BSD (incl OSX, but not guaranteed)

§Layout

Dirs:

  • a_sync - contains all async code
  • sync - contains all sync code Files: /:
  • portable.rs - contains the code which requres porting to other OS. This code usually incompatiable with different UNIX-type OSes.
  • error.rs - an error wrapper and mapper
  • tokenizer.rs - contains simple tokenizer for parsing config files.
  • read_only_cell.rs - an implementation of the once written cell for initialization purposes.
  • cfg_host_parser.rs - a common code for the /etc/host which is used by both sync/async
  • cfg_resolv_parser.rs - a common code for the /etc/resolv.conf which is used by sync/async
  • query.rs - a common code of query
  • query_private.rs - internal items for query construction

/sync/:

  • caches.rs - contains a cached in memory config files like /etc/hosts. If file was modified, the cache controller attempts to reload file during library call from main program. Sync realization of common file.
  • cfg_parsers.rs - contains the confgiration files parsers.
  • common.rs - this file contains all code related to DNS protocol i.e structures, parsing.
  • network.rs - a code which deals with networking part, i.e msg exchange with DNS server.
  • mutex.rs - a local implementaion of mutex for dafu usage in multithreading env. Derived from rust’s mutex implementation.
  • poison.rs - a mutex poison detection derived from rust’s code.
  • query.rs - a file which contains main logic
  • query_polltaps.rs - a pairing of socket with request depending on config
  • query_private.rs - a sync realization of the common file
  • request.rs - a pre-defined requests
  • log.rs - a log facility

Features:

  • feature = “use_async” for asynchronious code (use cdns_rs::a_sync::{…};)
  • feature = “use_sync” for synchronious code (use cdns_rs::sync::{…};)
  • feature = “no_error_output” does not output error
  • feature = “custom_error_output” outputs error to defined output no_error_output and custom_error_output can not be defined simultaniously.

If both no_error_output and custom_error_output are not defined then the errors are output to stderr.

All features can be used simultaniously.

§Usage

i.e cdns-rs = {version = “0.2”, default-features = false, features = [“use_sync”, “no_error_output”]}

By default, both use_async, use_sync, no_error_output features are enabled.

Example:

 
extern crate cdns_rs;
 
use cdns_rs::{QType, QDnsQueriesRes, QDnsQuery, QuerySetup, DnsRdata};
use cdns_rs::sync::QDns;
use cdns_rs::sync::caches::CACHE;
 
fn main() {
 
    println!("Hello, world!");
 
    let resolvers = CACHE.clone_resolve_list().unwrap();
 
    let mut q = QDns::make_empty(resolvers, 1, QuerySetup::default());
    q.add_request(QType::PTR, "127.0.0.1");
 
    let res = q.query().into_inner();
 
    if let Some(dq) = res
    {
        for d in dq
        {
            let resp = d.move_responses();
 
            for r in resp
            {
                match r.rdata
                {
                    DnsRdata::PTR{fqdn} =>
                    {
                        println!("{}", fqdn);
                    },
                    _ => {}
                }
            }
        }
    }
     

Re-exports§

Modules§

Macros§

Traits§

  • Support trait for enabling a few common operation on lazy static values.
  • Used for immutable dereferencing operations, like *v.

Functions§

  • Takes a shared reference to a lazy static and initializes it if it has not been already.