Crate resolv [] [src]

This library consists of a high-level interface to Gnu libc's (glibc) libresolv DNS resolver. 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, all via your operating system (glibc, not the kernel).

The lower level library, libresolv-sys, was generated from glibc version 2.23 on linux, using the newer thread-safe function calls. It may not work on older version of glibc, or on other operating systems. Pull-requests which improve portability are appreciated.

Example

extern crate resolv;

use resolv::{Resolver, Class, RecordType, Section, Record};
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();

    // .get_section_count() returns the number of records in that
    // section of the response.  There are four sections, but we
    // usually care about `Section::Answer`
    for i in 0..response.get_section_count(Section::Answer) {

        // As records are strongly typed, you must know what you are
        // looking for.  If you assign into the wrong type, a run-time
        // error `WrongRRType` will be returned.
        let mx: Record<MX> = response.get_record(Section::Answer, i)
                             .unwrap();

       println!("{:?}", mx);
    }
}

Reexports

pub use record::{Record, RecordType};

Modules

error
record

Structs

Flags
RecordItems

An iterator to iterate through DNS records

Resolver
Response

Enums

Class

DNS Class.

ResolverOption

Options for the Resolver

Section