packages feed

hsns 0.5.2 → 0.5.3

raw patch · 3 files changed

+35/−46 lines, 3 filesdep ~pcap

Dependency ranges changed: pcap

Files

Hsns.hs view
@@ -30,7 +30,7 @@     hexadecimal = h } -hsnsVersion = "hsns: the haskell network sniffer, version 0.5.2"+hsnsVersion = "hsns: the haskell network sniffer, version 0.5.3"  formatData :: PacketFmt -> IO () formatData pf = do@@ -48,13 +48,11 @@   -- we output on a 'complete' line (30) and how many   -- we're outputting for this 'incomplete' line (every   -- hex byte is of length 2 plus the trailing space-  if (length x < 10 && length y < 10) then do-        mapM_ (printf "%02.2x ") (fmtHex y)-        let z = 30 - (3 * (length $ fmtHex y)) -        fmtIrregular z-        printf "\t%s\n" x-        return ()-   else return ()+  when (length x < 10 && length y < 10) $ do+    mapM_ (printf "%02.2x ") (fmtHex y)+    let z = 30 - (3 * (length $ fmtHex y)) +    fmtIrregular z+    printf "\t%s\n" x  where   a = ascii pf   h = hexadecimal pf@@ -63,14 +61,12 @@   fmtIrregular :: Int -> IO ()   fmtIrregular z = do     printf "\t"-    if (z-8) > 0 then-      fmtIrregular (z - 8)-     else-      return ()+    if ((z-8) > 0) then fmtIrregular (z - 8) else return () + captcha :: PCap.PktHdr -> Ptr Word8 -> IO () captcha pkth datap = do-  a  <- peekArray (fromIntegral (PCap.caplen pkth)) datap+  a  <- peekArray (fromIntegral (PCap.hdrCaptureLength pkth)) datap   s  <- return $ map (\x -> if (x >= 32 && x <= 126) then x else 46) a   s' <- return $ map (\x -> chr (read $ show x)) s   formatData (initPktFmt s' a)@@ -81,40 +77,33 @@ starter o = do    -- options that don't depend on anything else-  if (help o)    == "True" then putStrLn (usageInfo "hsns: \"filter program\" [OPTIONS]..." options) >> exitWith ExitSuccess -   else return ()-  if (version o) == "True" then (putStrLn hsnsVersion >> (exitWith ExitSuccess)) else return ()   -  if (buffered o) == "True" then hSetBuffering stdout LineBuffering else return ()+  when ((help o) == "True") $ putStrLn (usageInfo "hsns: \"filter program\" [OPTIONS]..." options) >> exitWith ExitSuccess +  when ((version o) == "True") $ (putStrLn hsnsVersion >> (exitWith ExitSuccess))+  when ((buffered o) == "True") $ hSetBuffering stdout LineBuffering    -- list devices   devs <- PCap.findAllDevs   let devnames = map (\i -> (PCap.ifName i)) devs -  if (iflist o)  == "True" then do+  when ((iflist o) == "True") $ do     putStrLn "interfaces:"      mapM_ (printf " -- %s\n") devnames     exitWith ExitSuccess-   else return ()    -- variables that depend on root access   let dev      = (interface o)   net  <- PCap.lookupNet dev   spy  <- PCap.openLive dev (read $ snarflen o) (if (nopromiscuous o) == "True" then True else False) 100000-    -  withForeignPtr spy $ \ptr -> do-    -- set our filter, it must happen in this context as spy is-    -- a ForeignPtr, rather than a Ptr like we need for-    -- setFilter/loop--    if (bpf o) == "" then return () else PCap.setFilter ptr (bpf o) False (PCap.netMask net)-    -- loop and capture-    PCap.loop ptr (read $ count o) captcha-    --print statistics-    s <- PCap.statistics ptr-    putStrLn ("Packets recieved: " ++ (show $ PCap.recv s))-    putStrLn ("Packets dropped: " ++ (show $ PCap.drop s))-    putStrLn ("Packets dropped by interface: " ++ (show $ PCap.ifdrop s))+  -- set filter+  unless (null (bpf o)) $ do PCap.setFilter spy (bpf o) False (PCap.netMask net) +  -- loop and capture+  PCap.loop spy (read $ count o) captcha+  --print statistics+  s <- PCap.statistics spy+  putStrLn ("Packets recieved: " ++ (show $ PCap.statReceived s))+  putStrLn ("Packets dropped: " ++ (show $ PCap.statDropped s))+  putStrLn ("Packets dropped by interface: " ++ (show $ PCap.statIfaceDropped s))   main = do
Options.hs view
@@ -3,15 +3,15 @@ import Data.Maybe  data HsnsOpts = Opts {-          count         :: String, --done-          snarflen      :: String, --done-          interface     :: String, --done-          version       :: String, --done-          nopromiscuous :: String, --done-          iflist        :: String, --done-          buffered      :: String, --done-          help          :: String, --done-          bpf           :: String -- filter string that will be passed to setfilter+          count         :: String, +          snarflen      :: String, +          interface     :: String, +          version       :: String, +          nopromiscuous :: String, +          iflist        :: String, +          buffered      :: String, +          help          :: String, +          bpf           :: String  }  data Flags =
hsns.cabal view
@@ -1,13 +1,13 @@ Name:                hsns-Version:             0.5.2-Description:         a network sniffer written in a purely fun language-Synopsis:            the haskell network sniffer+Version:             0.5.3+Description:         a tiny network sniffer, written in haskell+Synopsis:            a miniature network sniffer Category:            Network License:             BSD3 License-file:        LICENSE Author:              Austin Seipp  Maintainer:          austin@youareinferior.net-Build-Depends:       base,network,pcap+Build-Depends:       base,network,pcap>=0.3.2 Extra-source-files:  README, 		     Options.hs