packages feed

maccatcher 2.0.0 → 2.1.0

raw patch · 3 files changed

+75/−37 lines, 3 filesPVP ok

version bump matches the API change (PVP)

API changes (from Hackage documentation)

- System.Info.MAC.Fetch: fetchMACs :: IO [MAC]
- System.Info.MAC.Fetch: parseMAC :: Parser t -> Parser t' -> Char -> Parser (Maybe MAC)
- System.Info.MAC.Fetch: parseMACs :: Parser t -> Parser t' -> Char -> Parser [MAC]
+ System.Info.MAC: nic :: IO (Maybe (String, MAC))
+ System.Info.MAC: nics :: IO [(String, MAC)]
+ System.Info.MAC.Fetch: fetchNICs :: IO [(String, MAC)]
+ System.Info.MAC.Fetch: parseNIC_ifconfig :: Parser (Maybe (String, MAC))
+ System.Info.MAC.Fetch: parseNIC_ipconfig :: Parser (Maybe (String, MAC))
+ System.Info.MAC.Fetch: parseNICs :: Parser (Maybe (String, MAC)) -> Parser [(String, MAC)]
- System.Info.MAC: refresh :: IO [MAC]
+ System.Info.MAC: refresh :: IO [(String, MAC)]
- System.Info.MAC.Fetch: ifconfig :: Parser [MAC]
+ System.Info.MAC.Fetch: ifconfig :: Parser [(String, MAC)]
- System.Info.MAC.Fetch: ipconfig :: Parser [MAC]
+ System.Info.MAC.Fetch: ipconfig :: Parser [(String, MAC)]

Files

System/Info/MAC.hs view
@@ -6,9 +6,11 @@   module System.Info.MAC-  ( refresh-  , mac+  ( mac   , macs+  , nic+  , nics+  , refresh   ) where  import Data.MAC@@ -21,15 +23,6 @@ import Control.Applicative  -{-| Explicitly re-run the MAC catching operation.- -}-refresh                     ::  IO [MAC]-refresh                      =  do-  res                       <-  fetchMACs-  writeIORef fetched res-  return res-- {-| Fetch MAC address, using a cached value if it is available.  -} mac                         ::  IO (Maybe MAC)@@ -39,10 +32,31 @@ {-| Fetch MAC addresses, using a cached value if it is available.  -} macs                        ::  IO [MAC]-macs                         =  do+macs                         =  map snd <$> nics+++{-| Fetch a name-MAC pair, using a cached value if it is available.+ -}+nic                         ::  IO (Maybe (String, MAC))+nic                          =  listToMaybe <$> nics+++{-| Fetch name-MAC pairs, using a cached value if it is available.+ -}+nics                        ::  IO [(String, MAC)]+nics                         =  do   val                       <-  readIORef fetched   case val of [ ]           ->  refresh               _:_           ->  return val+++{-| Explicitly re-run the MAC reading operation.+ -}+refresh                     ::  IO [(String, MAC)]+refresh                      =  do+  res                       <-  fetchNICs+  writeIORef fetched res+  return res   {-# NOINLINE fetched #-}
System/Info/MAC/Fetch.hs view
@@ -1,3 +1,5 @@+{-# LANGUAGE TupleSections+  #-} {-| System specific routines for determing the MAC address and macros to help     sort things out at compile time.  -}@@ -8,7 +10,7 @@ import Data.MAC  import Control.Monad-import Control.Applicative+import Control.Applicative ((<$>)) import Data.List import Data.Maybe import System.Process@@ -17,10 +19,10 @@ import Text.ParserCombinators.Parsec  -{-| Obtain a list of all available MACs.+{-| Obtain a list containing the name and MAC of all NICs.  -}-fetchMACs                   ::  IO [MAC]-fetchMACs                    =  parser <$> i_config+fetchNICs                   ::  IO [(String, MAC)]+fetchNICs                    =  parser <$> i_config   {-| Run @ifconfig@ or @ipconfig@, as appropriate, capturing its output.@@ -37,42 +39,57 @@       | otherwise            =  "ifconfig"  + parser | os == "mingw32"     =  parse' "ipconfig" ipconfig-       | otherwise           =  parse' "ifconfig" ifconfig+       | otherwise           =  parse' "ifconfig" ifconfig . ("\n\n" ++)  -{-| Parses the output of Windows @ipconfig@.+{-| Parses the output of Linux or BSD @ifconfig@.  -}-ipconfig                    ::  Parser [MAC]-ipconfig                     =  parseMACs ((try . string) "Physical Address")-                                          (manyAnyTill (char ':') >> spaces)-                                          '-'+ifconfig                    ::  Parser [(String, MAC)]+ifconfig                     =  parseNICs parseNIC_ifconfig  -{-| Parses the output of Linux or BSD @ifconfig@.+{-| Parses the output of Windows @ipconfig@.  -}-ifconfig                    ::  Parser [MAC]-ifconfig                     =  parseMACs markers spaces ':'+ipconfig                    ::  Parser [(String, MAC)]+ipconfig                     =  parseNICs parseNIC_ipconfig+++parseNIC_ifconfig           ::  Parser (Maybe (String, MAC))+parseNIC_ifconfig            =  do+  name                      <-  many1 alphaNum+  skipManyTill (satisfy (/= '\n')) markers+  char ' '+  ((name,) <$>) <$> parseMAC ':'  where   markers = choice $ map (try . string) [ "ether", "HWaddr" ]  -parseMAC :: Parser t -> Parser t' -> Char -> Parser (Maybe MAC)-parseMAC preamble fill c     =  do-  preamble-  fill-  maybeMAC . intercalate ":" <$> sepHex (char c)+parseNIC_ipconfig           ::  Parser (Maybe (String, MAC))+parseNIC_ipconfig            =  do+  name                      <-  do string "Ethernet adapter "+                                   manyTill (satisfy (/= '\n')) (char ':')+  (skipManyAnyTill . choice) [ try (nl >> nl) >> unexpected "\\r\\n\\r\\n"+                             , (try . string) "Physical Address" ]+  manyTill (satisfy (/= '\n')) (char ':')+  char ' '+  ((name,) <$>) <$> parseMAC '-'  -parseMACs                   ::  Parser t -> Parser t' -> Char -> Parser [MAC]-parseMACs preamble fill c    =  catMaybes <$> parseMACs'+parseNICs :: Parser (Maybe (String, MAC)) -> Parser [(String, MAC)]+parseNICs p                  =  catMaybes <$> parseNICs'  where-  parseMACs' = -    (skipManyTill anyChar . choice) [ eof >> return []-                                    , do m <- parseMAC preamble fill c-                                         (m:) <$> parseMACs' ]+  parseNICs'                 =  (skipManyAnyTill . choice)+                                          [ eof >> return []+                                          , do try (nl >> nl)+                                               nic <- p+                                               (nic:) <$> parseNICs' ]  +parseMAC sepChar = maybeMAC . intercalate ":" <$> sepHex (char sepChar)++ parse'                      ::  String -> Parser [t] -> String -> [t] parse' source parser         =  either (const []) id . parse parser source @@ -91,4 +108,11 @@   skipManyTill p end           =  choice [try end, p >> skipManyTill p end]+++skipManyAnyTill              =  skipManyTill anyChar+++nl                           =  many (char '\r') >> char '\n'+ 
maccatcher.cabal view
@@ -1,5 +1,5 @@ name:               maccatcher-version:            2.0.0+version:            2.1.0 category:           Text license:            BSD3 license-file:       LICENSE