.IP \fB\-\-server\fR,\ \fB-s\fR
Use the given DNS server rather than the resolvers listed in
/etc/resolv.conf. Either an IP address or a hostname will work.
+.IP \fB\-\-timeout\fR,\ \fB-t\fR
+The number of seconds to wait for an answer from DNS (default: 15).
.SH EXAMPLES
.IP \[bu] 2
name: haeredes
-version: 0.1
+version: 0.2
cabal-version: >= 1.8
author: Michael Orlitzky
maintainer: Michael Orlitzky <michael@orlitzky.com>
CommandLine
DNS
ExitCodes
+ Timeout
ghc-options:
-Wall
import Paths_haeredes (version)
import Data.Version (showVersion)
+import Timeout (Timeout(..))
+
-- | Description of the 'NS' mode.
ns_description :: String
ns_description =
"IP address or hostname of server to query " ++
"(will use resolv.conf if not specified)"
+-- | Help string for the --timeout flag.
+timeout_help :: String
+timeout_help =
+ "Query timeout, in seconds (default: " ++ defstr ++ ")"
+ where
+ defstr = show $ seconds (def :: Timeout)
+
-- | The Args type represents the possible command-line options. The
-- duplication here seems necessary; CmdArgs' magic requires us to
-- define some things explicitly.
data Args =
NS { no_append_root :: Bool,
server :: Maybe String,
+ timeout :: Timeout,
delegates :: [String] } |
MX { no_append_root :: Bool,
server :: Maybe String,
+ timeout :: Timeout,
delegates :: [String] }
deriving (Data, Show, Typeable)
&= typ "HOST"
&= help server_help,
+ timeout = def
+ &= groupname "Common flags"
+ &= typ "SECONDS"
+ &= help timeout_help,
+
delegates = def
&= args
&= typ "DELEGATES" }
&= typ "IP"
&= help server_help,
+ timeout = def
+ &= groupname "Common flags"
+ &= typ "SECONDS"
+ &= help timeout_help,
+
delegates = def
&= args
&= typ "DELEGATES" }
import Network.DNS (
Domain,
FileOrNumericHost(RCHostName),
- ResolvConf(resolvInfo),
+ ResolvConf(resolvInfo, resolvTimeout),
defaultResolvConf,
makeResolvSeed,
withResolver )
normalize_case,
resolve_address )
import ExitCodes (exit_bad_server)
+import Timeout (Timeout(..))
-- | Report results for this LookupResult. If there's a Nothing in the
let nrml_domains = map normalize_function raw_domains
let nrml_delegates = map normalize_function raw_delegates
- rc <- case (server cfg) of
- Nothing -> return defaultResolvConf
- Just s -> do
- s' <- resolve_address s
- case s' of
- Nothing -> do
- hPutStrLn stderr ("Bad DNS server or lookup error: " ++ s)
- exitWith (ExitFailure exit_bad_server)
- Just s'' ->
- return $ defaultResolvConf { resolvInfo =
- RCHostName (show s'') }
-
+ rc' <- case (server cfg) of
+ Nothing -> return defaultResolvConf
+ Just s -> do
+ s' <- resolve_address s
+ case s' of
+ Nothing -> do
+ hPutStrLn stderr ("Bad DNS server or lookup error: " ++ s)
+ exitWith (ExitFailure exit_bad_server)
+ Just s'' ->
+ return $ defaultResolvConf { resolvInfo =
+ RCHostName (show s'') }
+
+ -- Set the timeout from the command line. The resolvTimeout field is
+ -- in microseconds, so we multiply by one million.
+ let rc = rc' { resolvTimeout = 1000 * 1000 * (seconds $ timeout cfg) }
rs <- makeResolvSeed rc
let lookup_function = case cfg of
--- /dev/null
+{-# LANGUAGE DeriveDataTypeable #-}
+
+-- | A newtype around the DNS query timeout, in seconds. Needed for
+-- the 'Default' instance.
+--
+module Timeout
+where
+
+import Data.Data (Data)
+import System.Console.CmdArgs.Default (Default(..))
+import Data.Typeable (Typeable)
+
+newtype Timeout =
+ Timeout { seconds :: Int }
+ deriving (Data, Show, Typeable)
+
+instance Default Timeout where
+ def = Timeout 15