-- Hoogle documentation, generated by Haddock -- See Hoogle, http://www.haskell.org/hoogle/ -- | Asynchronous DNS Resolver -- -- Asynchronous DNS Resolver; requires GNU ADNS to be installed. @package hsdns @version 1.4 -- | Determine the machine's endian. module ADNS.Endian -- | Signify the system's native byte order according to significance of -- bytes from low addresses to high addresses. data Endian -- | byte order: 1234 LittleEndian :: Endian -- | byte order: 4321 BigEndian :: Endian -- | byte order: 3412 PDPEndian :: Endian -- | The endian of this machine, determined at run-time. endian :: Endian -- | Parse a host-ordered 32-bit word into a network-ordered tuple of 8-bit -- words. readWord32 :: Word32 -> (Word8, Word8, Word8, Word) -- | Parse a host-ordered 16-bit word into a network-ordered tuple of 8-bit -- words. readWord16 :: Word16 -> (Word8, Word8) instance Show Endian instance Eq Endian -- | This module provides bindings to GNU ADNS, a domain name resolver -- library written in C. ADNS is available from -- http://www.gnu.org/software/adns/. -- -- You will most likely not need this module directly: ADNS -- provides a simpler API for the Haskell world; this module contains -- mostly marshaling code. module ADNS.Base data OpaqueState type AdnsState = Ptr OpaqueState data OpaqueQuery type Query = Ptr OpaqueQuery data InitFlag -- | do not look at environment NoEnv :: InitFlag -- | never print output to stderr (Debug overrides) NoErrPrint :: InitFlag -- | do not warn to stderr about duff nameservers etc NoServerWarn :: InitFlag -- | enable all output to stderr plus Debug msgs Debug :: InitFlag -- | include process id in diagnostic output LogPid :: InitFlag -- | do not make syscalls at every opportunity NoAutoSys :: InitFlag -- | allow adnsSynch to return eINTR Eintr :: InitFlag -- | application has SIGPIPE set to SIG_IGN, do not protect NoSigPipe :: InitFlag -- | do consistency checks on entry/exit to adns functions CheckC_EntEx :: InitFlag -- | do consistency checks very frequently (slow!) CheckC_Freq :: InitFlag data QueryFlag -- | use the searchlist Search :: QueryFlag -- | use a virtual circuit (TCP connection) UseVC :: QueryFlag -- | fill in the owner field in the answer Owner :: QueryFlag -- | allow special chars in query domain QuoteOk_Query :: QueryFlag -- | allow special chars in CNAME we go via (default) QuoteOk_CName :: QueryFlag -- | allow special chars in things supposed to be hostnames QuoteOk_AnsHost :: QueryFlag -- | refuse if quote-req chars in CNAME we go via QuoteFail_CName :: QueryFlag -- | allow refs to CNAMEs - without, get _s_cname CName_Loose :: QueryFlag -- | don't follow CNAMEs, instead give _s_cname CName_Forbid :: QueryFlag -- | The record types we support. data RRType A :: RRType CNAME :: RRType MX :: RRType NS :: RRType PTR :: RRType NSEC :: RRType RRType :: Int -> RRType -- | 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. newtype Status StatusCode :: Int -> Status 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 -- | 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. sINCONSISTENT :: Status sPROHIBITEDCNAME :: Status sANSWERDOMAININVALID :: Status sANSWERDOMAINTOOLONG :: Status sINVALIDDATA :: Status sMAX_MISCONFIG :: Status newtype RRAddr RRAddr :: HostAddress -> RRAddr sQUERYDOMAINWRONG :: Status sQUERYDOMAININVALID :: Status sQUERYDOMAINTOOLONG :: Status sMAX_MISQUERY :: Status sNXDOMAIN :: Status sNODATA :: Status sMAX_PERMFAIL :: Status -- | 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. data RRHostAddr RRHostAddr :: HostName -> Status -> [RRAddr] -> RRHostAddr -- | Original definition: -- --
--   typedef struct {
--     int i;
--     adns_rr_hostaddr ha;
--   } adns_rr_inthostaddr;
--   
data RRIntHostAddr RRIntHostAddr :: Int -> RRHostAddr -> RRIntHostAddr -- | Original definition: -- --
--   typedef struct {
--     int len;
--     unsigned char *data;
--   } adns_rr_byteblock;
--   
data RRByteblock RRByteblock :: Int -> (Ptr CChar) -> RRByteblock data Answer Answer :: Status -> Maybe String -> Maybe String -> CTime -> [Response] -> Answer -- | Status code for this query. status :: Answer -> Status -- | Always Nothing for CNAME queries cname :: Answer -> Maybe String -- | Only set if Owner was requested for query. owner :: Answer -> Maybe String -- | Only defined if status is sOK, sNXDOMAIN, or -- sNODATA. expires :: Answer -> CTime -- | The list will be empty if an error occured. rrs :: Answer -> [Response] data Response RRA :: RRAddr -> Response RRCNAME :: String -> Response RRMX :: Int -> RRHostAddr -> Response RRNS :: RRHostAddr -> Response RRPTR :: String -> Response RRNSEC :: String -> Response RRUNKNOWN :: String -> Response -- | This function parses the Response union found in Answer. -- It cannot be defined via Storable because it needs to know the -- type of the record to expect. This is, by the way, the function to -- look at, if you want to add support for additional RRType -- records. peekResp :: RRType -> Ptr b -> Int -> Int -> IO [Response] -- | This function parses a FQDN in uncompressed wire format and advances -- the pointer to the next byte after the parsed name. peekFQDNAndAdvance :: Ptr a -> Int -> IO (String, Ptr a) -- | Run the given IO computation with an initialized resolver. As -- of now, the diagnose stream is always set to -- System.IO.stderr. Initialize the library with -- NoErrPrint if you don't wont to see any error output. All -- resources are freed when adnsInit returns. adnsInit :: [InitFlag] -> (AdnsState -> IO a) -> IO a -- | Similar to adnsInit, but reads the resolver configuration from -- a string rather than from /etc/resolv.conf. Supported are the -- usual commands: nameserver, search, domain, -- sortlist, and options. -- -- Additionally, these non-standard commands may be used: -- -- adnsInitCfg :: [InitFlag] -> String -> (AdnsState -> IO a) -> IO a -- | Perform a synchronous query for a record. In case of an I/O error, an -- System.IO.Error.IOException is thrown. If the query fails for -- other reasons, the Status code in the Answer will -- signify that. adnsSynch :: AdnsState -> String -> RRType -> [QueryFlag] -> IO Answer -- | Submit an asynchronous query. The returned Query can be tested -- for completion with adnsCheck. adnsSubmit :: AdnsState -> String -> RRType -> [QueryFlag] -> IO Query -- | Check the status of an asynchronous query. If the query is complete, -- the Answer will be returned. The Query becomes invalid -- after that. adnsCheck :: AdnsState -> Query -> IO (Maybe Answer) -- | Wait for a response to arrive. The returned Query is invalid -- and must not be passed to ADNS again. If Nothing is returned, -- the resolver is empty. adnsWait :: AdnsState -> IO (Maybe (Query, Answer)) -- | Cancel an open Query. adnsCancel :: Query -> IO () -- | Wait for the next Query to become available. adns_wait :: AdnsState -> Ptr Query -> Ptr (Ptr Answer) -> Ptr (Ptr a) -> IO CInt -- | Return the list of all currently open queries. adnsQueries :: AdnsState -> IO [Query] -- | 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! adnsStrerror :: Status -> IO String -- | 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! adnsErrAbbrev :: Status -> IO String -- | 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! adnsErrTypeAbbrev :: Status -> IO String adns_init :: Ptr AdnsState -> CInt -> Ptr CFile -> IO CInt adns_init_strcfg :: Ptr AdnsState -> CInt -> Ptr CFile -> CString -> IO CInt adns_finish :: AdnsState -> IO () adns_submit :: AdnsState -> CString -> CInt -> CInt -> Ptr a -> Ptr Query -> IO CInt adns_check :: AdnsState -> Ptr Query -> Ptr (Ptr Answer) -> Ptr (Ptr a) -> IO CInt adns_synchronous :: AdnsState -> CString -> CInt -> CInt -> Ptr (Ptr Answer) -> IO CInt adns_forallqueries_begin :: AdnsState -> IO () adns_forallqueries_next :: AdnsState -> Ptr (Ptr a) -> IO Query adns_strerror :: CInt -> IO CString adns_errabbrev :: CInt -> IO CString adns_errtypeabbrev :: CInt -> IO CString -- | Internel helper function to handle result passing from ADNS via -- Ptr (Ptr a), and to generate human-readable IO exceptions in -- case of an error. wrapAdns :: (Ptr (Ptr b) -> IO CInt) -> (Ptr (Ptr b) -> IO a) -> IO a -- | Map a list of flags (Enum types) into a CInt suitable -- for adns calls. mkFlags :: (Enum a) => [a] -> CInt instance Show Response instance Show Answer instance Show RRIntHostAddr instance Show RRHostAddr instance Eq RRAddr instance Eq Status instance Show Status instance Read RRType instance Eq QueryFlag instance Bounded QueryFlag instance Show QueryFlag instance Eq InitFlag instance Bounded InitFlag instance Show InitFlag instance Storable Answer instance Storable RRByteblock instance Storable RRIntHostAddr instance Storable RRHostAddr instance Storable RRAddr instance Show RRAddr instance Storable RRType instance Enum RRType instance Show RRType instance Eq RRType instance Enum QueryFlag instance Enum InitFlag -- | This module implements a Haskell DNS Resolver on top of the ADNS -- library. GHC users should compile their code using the -- -threaded runtime system. module ADNS.Resolver -- | 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. type Resolver = String -> RRType -> [QueryFlag] -> IO (MVar Answer) -- | 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. initResolver :: [InitFlag] -> (Resolver -> IO a) -> IO a -- | Print an IP host address as a string suitable for PTR lookups. toPTR :: HostAddress -> String -- | Resolve a hostname's A records. resolveA :: Resolver -> HostName -> IO (Either Status [HostAddress]) -- | 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. resolvePTR :: Resolver -> HostAddress -> IO (Either Status [HostName]) -- | 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. resolveMX :: Resolver -> HostName -> IO (Either Status [(HostName, HostAddress)]) -- | 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 or sNODATA, 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
--   
query :: (Resolver -> a -> IO (Either Status [b])) -> (Resolver -> a -> IO (Maybe [b])) -- | Use this function to disable DNS resolving. It will always return -- (Answer sSYSTEMFAIL Nothing (Just host) (-1) -- []). dummyDNS :: Resolver -- | An asynchronous DNS resolver based on GNU ADNS -- http://www.gnu.org/software/adns/. You should link your program -- with the threaded runtime-system when using this module. In -- GHC, this is accomplished by specifying -threaded on the -- command-line. module ADNS type HostName = String type HostAddress = Word32 -- | 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. type Resolver = String -> RRType -> [QueryFlag] -> IO (MVar Answer) -- | 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. initResolver :: [InitFlag] -> (Resolver -> IO a) -> IO a data InitFlag -- | do not look at environment NoEnv :: InitFlag -- | never print output to stderr (Debug overrides) NoErrPrint :: InitFlag -- | do not warn to stderr about duff nameservers etc NoServerWarn :: InitFlag -- | enable all output to stderr plus Debug msgs Debug :: InitFlag -- | include process id in diagnostic output LogPid :: InitFlag -- | do not make syscalls at every opportunity NoAutoSys :: InitFlag -- | allow adnsSynch to return eINTR Eintr :: InitFlag -- | application has SIGPIPE set to SIG_IGN, do not protect NoSigPipe :: InitFlag -- | do consistency checks on entry/exit to adns functions CheckC_EntEx :: InitFlag -- | do consistency checks very frequently (slow!) CheckC_Freq :: InitFlag queryA :: Resolver -> HostName -> IO (Maybe [HostAddress]) queryPTR :: Resolver -> HostAddress -> IO (Maybe [HostName]) queryMX :: Resolver -> HostName -> IO (Maybe [(HostName, HostAddress)]) -- | Use this function to disable DNS resolving. It will always return -- (Answer sSYSTEMFAIL Nothing (Just host) (-1) -- []). dummyDNS :: Resolver