dns-1.0.0: DNS library in Haskell

Safe HaskellNone

Network.DNS.Resolver

Contents

Description

DNS Resolver and generic (lower-level) lookup functions.

Synopsis

Documentation

Configuration for resolver

data FileOrNumericHost Source

Union type for FilePath and HostName. Specify FilePath to "resolv.conf" or numeric IP address in String form.

Warning: Only numeric IP addresses are valid RCHostNames.

Example (using Google's public DNS cache):

>>> let cache = RCHostName "8.8.8.8"

data ResolvConf Source

Type for resolver configuration. The easiest way to construct a ResolvConf object is to modify the defaultResolvConf.

Constructors

ResolvConf 

Fields

resolvInfo :: FileOrNumericHost
 
resolvTimeout :: Int
 
resolvBufsize :: Integer

This field was obsoleted.

defaultResolvConf :: ResolvConfSource

Return a default ResolvConf:

Example (use Google's public DNS cache instead of resolv.conf):

>>> let cache = RCHostName "8.8.8.8"
>>> let rc = defaultResolvConf { resolvInfo = cache }

Intermediate data type for resolver

data ResolvSeed Source

Abstract data type of DNS Resolver seed

makeResolvSeed :: ResolvConf -> IO ResolvSeedSource

Make a ResolvSeed from a ResolvConf.

Examples:

>>> rs <- makeResolvSeed defaultResolvConf

Type and function for resolver

data Resolver Source

Abstract data type of DNS Resolver

Constructors

Resolver 

withResolver :: ResolvSeed -> (Resolver -> IO a) -> IO aSource

Giving a thread-safe Resolver to the function of the second argument. withResolver should be passed to forkIO. For examples, see Network.DNS.Lookup.

Looking up functions

lookup :: Resolver -> Domain -> TYPE -> IO (Either DNSError [RDATA])Source

Look up resource records for a domain, collecting the results from the ANSWER section of the response.

We repeat an example from Network.DNS.Lookup:

>>> let hostname = Data.ByteString.Char8.pack "www.example.com"
>>> rs <- makeResolvSeed defaultResolvConf
>>> withResolver rs $ \resolver -> lookup resolver hostname A
Right [93.184.216.119]

lookupAuth :: Resolver -> Domain -> TYPE -> IO (Either DNSError [RDATA])Source

Look up resource records for a domain, collecting the results from the AUTHORITY section of the response.

lookupRaw :: Resolver -> Domain -> TYPE -> IO (Either DNSError DNSFormat)Source

Look up a name and return the entire DNS Response. Sample output is included below, however it is not tested -- the sequence number is unpredictable (it has to be!).

The example code:

   let hostname = Data.ByteString.Char8.pack "www.example.com"
   rs <- makeResolvSeed defaultResolvConf
   withResolver rs $ resolver -> lookupRaw resolver hostname A

And the (formatted) expected output:

   Right (DNSFormat
           { header = DNSHeader
                        { identifier = 1,
                          flags = DNSFlags
                                    { qOrR = QR_Response,
                                      opcode = OP_STD,
                                      authAnswer = False,
                                      trunCation = False,
                                      recDesired = True,
                                      recAvailable = True,
                                      rcode = NoErr },
                          qdCount = 1,
                          anCount = 1,
                          nsCount = 0,
                          arCount = 0},
             question = [Question { qname = "www.example.com.",
                                    qtype = A}],
             answer = [ResourceRecord {rrname = "www.example.com.",
                                       rrtype = A,
                                       rrttl = 800,
                                       rdlen = 4,
                                       rdata = 93.184.216.119}],
             authority = [],
             additional = []})