X-Git-Url: http://gitweb.michael.orlitzky.com/?a=blobdiff_plain;f=src%2FCidr.hs;h=b5b3f744fd56651848387d7e010766bd328adb19;hb=18a81546e7c4ad10574918efb08b2e104e911d73;hp=cdfef9a73c255af75c3f2e6fa0e73d3a8fc4f7ec;hpb=3c9316fed6fd100be9a5e1f8d72db6534fb163cd;p=hath.git diff --git a/src/Cidr.hs b/src/Cidr.hs index cdfef9a..b5b3f74 100644 --- a/src/Cidr.hs +++ b/src/Cidr.hs @@ -8,6 +8,7 @@ module Cidr combine_all, contains, contains_proper, + enumerate, max_octet1, max_octet2, max_octet3, @@ -29,6 +30,7 @@ import Test.Framework (Test, testGroup) import Test.Framework.Providers.HUnit (testCase) import Test.Framework.Providers.QuickCheck2 (testProperty) import Test.QuickCheck (Arbitrary(..), Gen, Property, (==>)) +import Text.Read (readMaybe) import qualified Bit as B import IPv4Address @@ -77,7 +79,7 @@ maskbits_from_cidr_string s -- of its octets (as Ints). octets_from_cidr_string :: String -> [Octet] octets_from_cidr_string s = - mapMaybe octet_from_string (take 4 (splitOneOf "./" s)) + mapMaybe readMaybe (take 4 (splitOneOf "./" s)) -- | Return Nothing if we can't parse both maskbits and octets from @@ -254,7 +256,8 @@ adjacent cidr1 cidr2 mbits2 = maskbits cidr2 - +enumerate :: Cidr -> [IPv4Address] +enumerate cidr = [(min_host cidr)..(max_host cidr)] -- HUnit Tests