+ let cidr_strings = splitWs input
+ let cidrs = map readMaybe cidr_strings
+
+ when (any isNothing cidrs) $ do
+ hPutStrLn stderr "ERROR: not valid CIDR notation:"
+
+ -- Output the bad lines, safely.
+ let pairs = zip cidr_strings cidrs
+ let print_pair (x, Nothing) = hPutStrLn stderr (" * " ++ x)
+ print_pair (_, _) = return ()
+
+ mapM_ print_pair pairs
+ exitWith (ExitFailure exit_invalid_cidr)
+
+ -- Filter out only the valid ones.
+ let valid_cidrs = catMaybes cidrs
+
+ case args of
+ Regexed{} -> do
+ let cidrs' = combine_all valid_cidrs
+ let regexes = map (cidr_to_regex (barriers args)) cidrs'
+ putStrLn $ alternate regexes
+ Reduced{} ->
+ mapM_ print (combine_all valid_cidrs)
+ Duped{} ->
+ mapM_ print dupes
+ where
+ dupes = valid_cidrs \\ (combine_all valid_cidrs)
+ Diffed{} -> do
+ mapM_ putStrLn deletions
+ mapM_ putStrLn additions
+ where
+ dupes = valid_cidrs \\ (combine_all valid_cidrs)
+ deletions = map (\s -> '-' : (show s)) dupes
+ newcidrs = (combine_all valid_cidrs) \\ valid_cidrs
+ additions = map (\s -> '+' : (show s)) newcidrs
+ Listed{} -> do
+ let combined_cidrs = combine_all valid_cidrs
+ let addrs = concatMap enumerate combined_cidrs
+ mapM_ print addrs
+ Reversed{} -> do
+ let combined_cidrs = combine_all valid_cidrs
+ let addrs = concatMap enumerate combined_cidrs
+ let addr_bytestrings = map (BS.pack . show) addrs
+ ptrs <- lookup_ptrs addr_bytestrings
+ let pairs = zip addr_bytestrings ptrs
+ mapM_ (putStrLn . show_pair) pairs
+
+ stopGlobalPool
+
+ where
+ show_pair :: (Domain, PTRResult) -> String
+ show_pair (s, eds) =
+ (BS.unpack s) ++ ": " ++ results
+ where
+ space = BS.pack " "
+ results =
+ case eds of
+ -- NameError simply means "not found" so we output nothing.
+ Left NameError -> ""
+ Left err -> "ERROR (" ++ (show err) ++ ")"
+ Right ds -> BS.unpack $ BS.intercalate space ds