module Options where import System.Console.GetOpt import Data.Maybe data HsnsOpts = Opts { count :: String, snarflen :: String, interface :: String, version :: String, nopromiscuous :: String, iflist :: String, buffered :: String, help :: String, bpf :: String } data Flags = Count String | -- amount of packets to take, must be String in constructor, that's how getOpt returns it IfList | -- List the available interfaces Listen String | -- Listen on the specified interface LineBuffered | -- Turn on Line buffering NoPromiscuous | -- Don't go into promiscuous mode. SnarfLen String | -- Amount of data to snarf, default is 68 Version | -- version number Help -- help info options :: [OptDescr Flags] options = [ Option ['h','?'] ["help"] (NoArg Help) "print this help information" ,Option ['c'] ["count"] (ReqArg Count "NUM") "take in NUM packets, default is 5, 0 means unlimited" ,Option ['D'] ["iflist"] (NoArg IfList) "list interfaces that can be captured upon" ,Option ['i'] ["interface"] (ReqArg Listen "INT") "listen on interface INT, defaults to eth0" ,Option ['l'] ["linebuffered"] (NoArg LineBuffered) "make output line-buffered" ,Option ['p'] ["nopromiscuous"] (NoArg NoPromiscuous) "do not go into promiscuous mode" ,Option ['s'] ["snarf"] (ReqArg SnarfLen "LEN") "change snarf length from default 68 to LEN" ,Option ['V'] ["version"] (NoArg Version) "output version number and exit"] hsnsOptions :: [String] -> IO ([Flags],[String]) hsnsOptions av = do case getOpt Permute options av of (o,n,[]) -> return (o,n) (_,_,e) -> ioError (userError (concat e ++ usageInfo header options)) where header = "usage: hsns \"[PACKET FILTER]\" [OPTIONS...]"