hsdns-1.1Source codeContentsIndex
Network.DNS
PortabilityHaskell 2-pre
Stabilityprovisional
Maintainersimons@cryp.to
Description
An asynchronous DNS resolver. Link your program with the threaded runtime-system when you use this module. In GHC, this is accomplished by specifying -threaded on the command-line.
Synopsis
type Resolver = String -> RRType -> [QueryFlag] -> IO (MVar Answer)
initResolver :: [InitFlag] -> (Resolver -> IO a) -> IO a
resolveA :: Resolver -> HostName -> IO (Either Status [HostAddress])
resolvePTR :: Resolver -> HostAddress -> IO (Either Status [HostName])
resolveMX :: Resolver -> HostName -> IO (Either Status [(HostName, HostAddress)])
query :: (Resolver -> a -> IO (Either Status [b])) -> Resolver -> a -> IO (Maybe [b])
HostName
HostAddress
data InitFlag
= NoEnv
| NoErrPrint
| NoServerWarn
| Debug
| LogPid
| NoAutoSys
| Eintr
| NoSigPipe
| CheckC_EntEx
| CheckC_Freq
data QueryFlag
= Search
| UseVC
| Owner
| QuoteOk_Query
| QuoteOk_CName
| QuoteOk_AnsHost
| QuoteFail_CName
| CName_Loose
| CName_Forbid
data RRType
= A
| MX
| NS
| PTR
newtype Status = StatusCode Int
newtype RRAddr = RRAddr HostAddress
data RRHostAddr = RRHostAddr HostName Status [RRAddr]
data RRIntHostAddr = RRIntHostAddr Int RRHostAddr
data Answer = Answer {
status :: Status
cname :: Maybe String
owner :: Maybe String
expires :: CTime
rrs :: [Response]
}
data Response
= RRA RRAddr
| RRMX Int RRHostAddr
| RRNS RRHostAddr
| RRPTR String
sOK :: Status
sNOMEMORY :: Status
sUNKNOWNRRTYPE :: Status
sSYSTEMFAIL :: Status
sMAX_LOCALFAIL :: Status
sTIMEOUT :: Status
sALLSERVFAIL :: Status
sNORECURSE :: Status
sINVALIDRESPONSE :: Status
sUNKNOWNFORMAT :: Status
sMAX_REMOTEFAIL :: Status
sRCODESERVFAIL :: Status
sRCODEFORMATERROR :: Status
sRCODENOTIMPLEMENTED :: Status
sRCODEREFUSED :: Status
sRCODEUNKNOWN :: Status
sMAX_TEMPFAIL :: Status
sINCONSISTENT :: Status
sPROHIBITEDCNAME :: Status
sANSWERDOMAININVALID :: Status
sANSWERDOMAINTOOLONG :: Status
sINVALIDDATA :: Status
sMAX_MISCONFIG :: Status
sQUERYDOMAINWRONG :: Status
sQUERYDOMAININVALID :: Status
sQUERYDOMAINTOOLONG :: Status
sMAX_MISQUERY :: Status
sNXDOMAIN :: Status
sNODATA :: Status
sMAX_PERMFAIL :: Status
adnsStrerror :: Status -> IO String
adnsErrAbbrev :: Status -> IO String
adnsErrTypeAbbrev :: Status -> IO String
dummyDNS :: Resolver
Documentation
type Resolver = String -> RRType -> [QueryFlag] -> IO (MVar Answer)Source
A Resolver is an IO computation which -- given the name and type of the record to query -- returns an MVar that will eventually contain the Answer from the Domain Name System.
initResolver :: [InitFlag] -> (Resolver -> IO a) -> IO aSource
Run the given IO computation with an Initialized Resolver. Note that resolver functions can be shared, and should be shared between any number of IO threads. You may use multiple resolvers, of course, but doing so defeats the purpose of an asynchronous resolver.
resolveA :: Resolver -> HostName -> IO (Either Status [HostAddress])Source
Resolve a hostname's A records.
resolvePTR :: Resolver -> HostAddress -> IO (Either Status [HostName])Source
Get the PTR records assigned to a host address. Note that although the API allows for a record to have more than one PTR entry, this will actually not happen because the GNU adns library can't handle this case and will return sINCONSISTENT.
resolveMX :: Resolver -> HostName -> IO (Either Status [(HostName, HostAddress)])Source
Resolve the mail exchangers for a hostname. The returned list may contain more than one entry per hostname, in case the host has several A records. The records are returned in the order you should try to contact them as determined by the priority in the RRMX response.
query :: (Resolver -> a -> IO (Either Status [b])) -> Resolver -> a -> IO (Maybe [b])Source

Convenience wrapper that will modify any of the revolveXXX functions above to return Maybe rather than Either. The idea is that Nothing signifies any sort of failure; Just [] signifies sNXDOMAIN; and everything else signifies sOK.

So if you aren't interested in getting accurate Status codes in case of failures. Wrap your DNS queries as follows:

 queryA :: Resolver -> HostName -> IO (Maybe [HostAddress])
 queryA = query resolveA
HostName
HostAddress
data InitFlag Source
Constructors
NoEnvdo not look at environment
NoErrPrintnever print output to stderr (Debug overrides)
NoServerWarndo not warn to stderr about duff nameservers etc
Debugenable all output to stderr plus Debug msgs
LogPidinclude process id in diagnostic output
NoAutoSysdo not make syscalls at every opportunity
Eintrallow adnsSynch to return eINTR
NoSigPipeapplication has SIGPIPE set to SIG_IGN, do not protect
CheckC_EntExdo consistency checks on entry/exit to adns functions
CheckC_Freqdo consistency checks very frequently (slow!)
show/hide Instances
data QueryFlag Source
Constructors
Searchuse the searchlist
UseVCuse a virtual circuit (TCP connection)
Ownerfill in the owner field in the answer
QuoteOk_Queryallow special chars in query domain
QuoteOk_CNameallow special chars in CNAME we go via (default)
QuoteOk_AnsHostallow special chars in things supposed to be hostnames
QuoteFail_CNamerefuse if quote-req chars in CNAME we go via
CName_Looseallow refs to CNAMEs - without, get _s_cname
CName_Forbiddon't follow CNAMEs, instead give _s_cname
show/hide Instances
data RRType Source
The record types we support.
Constructors
A
MX
NS
PTR
show/hide Instances
newtype Status Source
The status codes recognized by ADNS vary in different versions of the library. So instead of providing an Enum, the Status type contains the numeric value as returned by ADNS itself. For common status codes, helper functions like sOK or sNXDOMAIN are provided. The functions adnsErrTypeAbbrev, adnsErrAbbrev, and adnsStrerror can also be used to map these codes into human readable strings.
Constructors
StatusCode Int
show/hide Instances
newtype RRAddr Source
Constructors
RRAddr HostAddress
show/hide Instances
data RRHostAddr Source

Original definition:

    typedef struct {
      char *host;
      adns_status astatus;
      int naddrs; /* temp fail => -1, perm fail => 0, s_ok => >0
      adns_rr_addr *addrs;
    } adns_rr_hostaddr;

The naddrs field is not available in RRHostAddr because I couldn't see how that information wouldn't be available in the astatus field too. If I missed anything, please let me know.

Note: The data type should probably contain HostAddress rather than RRAddr. I'm using the former only because it has nicer output with show. poke is not defined.

Constructors
RRHostAddr HostName Status [RRAddr]
show/hide Instances
data RRIntHostAddr Source

Original definition:

    typedef struct {
      int i;
      adns_rr_hostaddr ha;
    } adns_rr_inthostaddr;
Constructors
RRIntHostAddr Int RRHostAddr
show/hide Instances
data Answer Source
Constructors
Answer
status :: StatusStatus code for this query.
cname :: Maybe StringAlways Nothing for CNAME queries (which are not supported yet anyway).
owner :: Maybe StringOnly set if Owner was requested for query.
expires :: CTimeOnly defined if status is sOK, sNXDOMAIN, or sNODATA.
rrs :: [Response]The list will be empty if an error occured.
show/hide Instances
data Response Source
Constructors
RRA RRAddr
RRMX Int RRHostAddr
RRNS RRHostAddr
RRPTR String
show/hide Instances
sOK :: StatusSource
sNOMEMORY :: StatusSource
sUNKNOWNRRTYPE :: StatusSource
sSYSTEMFAIL :: StatusSource
sMAX_LOCALFAIL :: StatusSource
sTIMEOUT :: StatusSource
sALLSERVFAIL :: StatusSource
sNORECURSE :: StatusSource
sINVALIDRESPONSE :: StatusSource
sUNKNOWNFORMAT :: StatusSource
sMAX_REMOTEFAIL :: StatusSource
sRCODESERVFAIL :: StatusSource
sRCODEFORMATERROR :: StatusSource
sRCODENOTIMPLEMENTED :: StatusSource
sRCODEREFUSED :: StatusSource
sRCODEUNKNOWN :: StatusSource
sMAX_TEMPFAIL :: StatusSource
sINCONSISTENT :: StatusSource

Original definition:

    typedef struct {
      int len;
      union {
        struct sockaddr sa;
        struct sockaddr_in inet;
      } addr;
    } adns_rr_addr;

Note: Anything but sockaddr_in will cause peek to call fail, when marshaling this structure. poke is not defined.

sPROHIBITEDCNAME :: StatusSource
sANSWERDOMAININVALID :: StatusSource
sANSWERDOMAINTOOLONG :: StatusSource
sINVALIDDATA :: StatusSource
sMAX_MISCONFIG :: StatusSource
sQUERYDOMAINWRONG :: StatusSource
sQUERYDOMAININVALID :: StatusSource
sQUERYDOMAINTOOLONG :: StatusSource
sMAX_MISQUERY :: StatusSource
sNXDOMAIN :: StatusSource
sNODATA :: StatusSource
sMAX_PERMFAIL :: StatusSource
adnsStrerror :: Status -> IO StringSource

Map a Status code to a human-readable error description. For example:

    *ADNS> adnsStrerror sNXDOMAIN >>= print
    "No such domain"

Use this function with great care: It will crash the process when called with a status code that ADNS doesn't know about. So use it only to print values you got from the resolver!

adnsErrAbbrev :: Status -> IO StringSource
Map a Status code to a short error name. Don't use this function to print a status code unless you've obtained it from the resolver!
adnsErrTypeAbbrev :: Status -> IO StringSource
Map a Status code to a short description of the type of error. Don't use this function to print a status code unless you've obtained it from the resolver!
dummyDNS :: ResolverSource
Use this function to disable DNS resolving. It will always return (Answer sSYSTEMFAIL Nothing (Just host) (-1) []).
Produced by Haddock version 2.4.2