+import Control.Concurrent.ParallelIO.Global (
+ parallel,
+ stopGlobalPool )
+import Control.Monad (unless)
+import qualified Data.ByteString.Char8 as BS (
+ getContents,
+ pack,
+ words )
+import Data.List ((\\))
+import Data.String.Utils (join)
+import Network.DNS (
+ Domain,
+ FileOrNumericHost(RCHostName),
+ ResolvConf(resolvInfo, resolvTimeout),
+ defaultResolvConf,
+ makeResolvSeed,
+ withResolver )
+import System.Exit (ExitCode(..), exitWith)
+import System.IO (hPutStrLn, stderr)
+
+
+import CommandLine (Args(..), get_args)
+import DNS (
+ LookupResult,
+ lookupMX',
+ lookupNS',
+ normalize,
+ normalize_case,
+ resolve_address )
+import ExitCodes (exit_bad_server)
+import Timeout (Timeout(..))
+
+
+-- | Report results for this LookupResult. If there's a Nothing in the
+-- second component, there were no query results, so we report that
+-- the domain was not delegated. If there were some results and
+-- there are leftovers (after "cleaning"), we report those as well.
+report :: LookupResult -> IO ()
+report (d, Nothing) =
+ putStrLn $ "Domain " ++ (show d) ++ " not delegated."
+report (d, Just leftovers) =
+ unless (null leftovers) $
+ putStrLn $ "Domain " ++
+ (show d) ++
+ " delegates somewhere else: " ++
+ (join " " (map show leftovers))
+
+
+-- | "Clean" a lookup result by subtracting out the list of delegates.
+-- There shouldn't be anything left over. If there were no lookup
+-- results, we leave the Nothing in place so that 'report' can
+-- pattern match on it.
+clean :: [Domain] -- ^ List of delegates, @ds@
+ -> LookupResult
+ -> LookupResult
+clean _ p@(_, Nothing) = p
+clean delgts (d, Just targets) =
+ (d, Just $ targets \\ delgts)
+
+
+