Giter VIP home page Giter VIP logo

resolv-rs's Introduction

Resolv

DNS resolution via glibc.

Note: If you are only looking up IP addresses for DNS names and don't need other records (MX, TXT, etc), consider other more portable rust libraries like dns-lookup.

This uses libresolv.so which is typically configured via /etc/resolv.conf to do DNS resolution. It allows you to look up DNS resource records of any type (e.g. A, AAAA, MX, TXT, etc), use recursion (if your system's DNS resolver permits it), and perform the DNS search algorithm to complete incomplete names and use your /etc/hosts file.

Example

extern crate resolv;

use resolv::{Resolver, Class, RecordType};
use resolv::record::MX;

fn main() {
    // You must create a mutable resolver object to hold the context.
    let mut resolver = Resolver::new().unwrap();

    // .query() and .search() are the main interfaces to the resolver.
    let mut response = resolver.query(b"gmail.com", Class::IN,
                                      RecordType::MX).unwrap();

    // You can iterate through answers as follows.  You must specify the
    // type of record.  A run-time error will occur if the records
    // decoded are of the wrong type.
    for answer in response.answers::<MX>() {
        println!("{:?}", answer);
    }
}

Limitations

You cannot specify a DNS server separate from editing /etc/resolv.conf for the entire system.

Not all NS record types are supported yet.

The thread-safe interface is used, which may not be available on older systems.

Depending on the version of glibc installed on the system, one of several adapter modules is chosen. It is likely that some systems will require making a new adapter module from one of the existing ones. These are in libresolv-sys/lib.d. Pull requests with additional adapters are welcome.

License

Licensed under either of

at your option.

Contribution

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.

resolv-rs's People

Contributors

mikedilger avatar sjbronner avatar segler-alex avatar smutt avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.