-- Hoogle documentation, generated by Haddock -- See Hoogle, http://www.haskell.org/hoogle/ -- | Asynchronous DNS Resolver; requires the GNU ADNS library to be -- installed. @package hsdns @version 1.1 -- | A foreign function interface to the POSIX system call -- poll(2). Your program should link the threaded runtime-system -- when using this module in blocking fashion. module System.Posix.Poll -- | The marshaled version of: -- --
-- struct pollfd
-- {
-- int fd; /* file descriptor */
-- short events; /* requested events */
-- short revents; /* returned events */
-- };
--
data Pollfd
Pollfd :: Fd -> CShort -> CShort -> Pollfd
-- | Marshaled Enum representing the various poll(2) flags.
data PollFlag
-- | there is data to read
PollIn :: PollFlag
-- | there is urgent data to read
PollPri :: PollFlag
-- | writing now will not block
PollOut :: PollFlag
-- | error condition
PollErr :: PollFlag
-- | hung up
PollHup :: PollFlag
-- | invalid request: fd not open
PollNVal :: PollFlag
-- | The system routine poll(2) may block, obviously; so it is
-- declared as a "safe" FFI call. In the threaded runtime-system,
-- this means that a blocking invocation of poll will not block
-- any other execution threads. Thus, you should link your programs with
-- -threaded when you use this module. Further details can be
-- found at
-- http://www.haskell.org//pipermail/glasgow-haskell-users/2005-February/007762.html.
--
-- In the non-threaded runtime-system, using poll in blocking
-- fashion will block all other threads too.
poll :: Ptr Pollfd -> CUInt -> CInt -> IO CInt
instance Eq PollFlag
instance Bounded PollFlag
instance Show PollFlag
instance Show Pollfd
instance Enum PollFlag
instance Storable Pollfd
-- | A foreign function interface to gettimeofday(2).
module System.Posix.GetTimeOfDay
-- | Marshaling for C's struct timeval.
data Timeval
Timeval :: CTime -> Int32 -> Timeval
-- | Not really implemented by anyone; so we provide just a place-holder.
-- Pass nullPtr to gettimeofday.
data Timezone
-- | Write the current time as a Timeval. The time is returned in
-- local time, no time zone correction takes place. Signals errors with
-- throwErrno.
getTimeOfDay :: Ptr Timeval -> IO ()
-- | The gettimeofday(2) system call.
gettimeofday :: Ptr Timeval -> Ptr Timezone -> IO CInt
instance Storable Timeval
-- | Find out the machine's endian at runtime.
module Data.Endian
-- | Definitions for 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.
ourEndian :: Endian
instance Show Endian
instance Eq Endian
-- | Tools for manipulating IP addresses.
module Network.IP.Address
-- | Split up an IP address in network byte-order.
ha2tpl :: HostAddress -> (Int, Int, Int, Int)
-- | Turn a 32-bit IP address into a string suitable for Network.DNS.PTR
-- lookups in the Domain Name System.
ha2ptr :: HostAddress -> String
-- | This module provides bindings to GNU ADNS, a domain name resolver
-- library written in C. Its source code, among other things, is
-- available at http://www.gnu.org/software/adns/.
--
-- You will most likely not need this module directly; Network.DNS
-- provides a much nicer interface from the Haskell world; this module
-- contains mostly marshaling code.
module Network.DNS.ADNS
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
MX :: RRType
NS :: RRType
PTR :: 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
data Answer
Answer :: Status -> Maybe String -> Maybe String -> CTime -> [Response] -> Answer
-- | Status code for this query.
status :: Answer -> Status
-- | Always Nothing for CNAME queries (which are not
-- supported yet anyway).
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
RRMX :: Int -> RRHostAddr -> Response
RRNS :: RRHostAddr -> Response
RRPTR :: 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]
-- | 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:
--
-- -- *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 Eq RRType instance Bounded RRType instance Show RRType instance Eq QueryFlag instance Bounded QueryFlag instance Show QueryFlag instance Eq InitFlag instance Bounded InitFlag instance Show InitFlag instance Storable Answer instance Storable RRIntHostAddr instance Storable RRHostAddr instance Storable RRAddr instance Show RRAddr instance Storable RRType instance Enum RRType instance Enum QueryFlag instance Enum InitFlag -- | This module provides a poll-based I/O scheduler for -- Network.DNS.ADNS. See the test.hs program included in -- the distribution for an example of how to use this 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. module Network.DNS.PollResolver -- | 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 -- | 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; 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 -- | The internal state of the resolver is stored in an MVar so that -- it is shared (and synchronized) between any number of concurrent -- IO threads. data ResolverState RState :: AdnsState -> ForeignPtr Pollfd -> Int -> [(Query, MVar Answer)] -> ResolverState -- | opaque ADNS state adns :: ResolverState -> AdnsState -- | array for poll(2) pollfds :: ResolverState -> ForeignPtr Pollfd -- | size of the array capacity :: ResolverState -> Int -- | currently open queries queries :: ResolverState -> [(Query, MVar Answer)] -- | Submit a DNS query to the resolver and check whether we have a running -- resolveLoop thread already. If we don't, start one with -- forkIO. Make sure you link the threaded RTS so that the main -- loop will not block other threads. resolve :: MVar ResolverState -> Resolver -- | Loop until all open queries have been resolved. Uses poll -- internally to avoid busy-polling the ADNS sockets. resolveLoop :: MVar ResolverState -> IO () -- | 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. module Network.DNS -- | 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 -- | 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; 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])) 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 MX :: RRType NS :: RRType PTR :: 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 newtype RRAddr RRAddr :: HostAddress -> RRAddr -- | 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
data Answer
Answer :: Status -> Maybe String -> Maybe String -> CTime -> [Response] -> Answer
-- | Status code for this query.
status :: Answer -> Status
-- | Always Nothing for CNAME queries (which are not
-- supported yet anyway).
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
RRMX :: Int -> RRHostAddr -> Response
RRNS :: RRHostAddr -> Response
RRPTR :: String -> Response
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
sQUERYDOMAINWRONG :: Status
sQUERYDOMAININVALID :: Status
sQUERYDOMAINTOOLONG :: Status
sMAX_MISQUERY :: Status
sNXDOMAIN :: Status
sNODATA :: Status
sMAX_PERMFAIL :: Status
-- | 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 -- | Use this function to disable DNS resolving. It will always return -- (Answer sSYSTEMFAIL Nothing (Just host) (-1) -- []). dummyDNS :: Resolver