From: Michael Orlitzky Date: Sun, 2 May 2010 19:23:48 +0000 (-0400) Subject: Added a None constructor for Cidr. X-Git-Tag: 0.0.1~79 X-Git-Url: https://gitweb.michael.orlitzky.com/?a=commitdiff_plain;h=9b1ce7fe8f4dc65230b223f4156760e2b9c7f098;p=hath.git Added a None constructor for Cidr. Return Cidr.None when we are passed an invalid IPv4Address. --- diff --git a/src/Cidr.hs b/src/Cidr.hs index efd3ae0..4bb3d48 100644 --- a/src/Cidr.hs +++ b/src/Cidr.hs @@ -11,8 +11,8 @@ import ListUtils import Octet -data Cidr = Cidr { ipv4address :: IPv4Address, - maskbits :: Maskbits } +data Cidr = None | Cidr { ipv4address :: IPv4Address, + maskbits :: Maskbits } deriving (Eq, Show) -- Will return True if the passed String is in CIDR notation, False @@ -34,9 +34,11 @@ octets_from_string s = map read (take 4 (splitWith (`elem` "./") s)) cidr_from_string :: String -> Cidr -cidr_from_string s = Cidr addr mbits +cidr_from_string s + | addr == IPv4Address.None = Cidr.None + | otherwise = Cidr addr mbits where - addr = IPv4Address (oct1) (oct2) (oct3) (oct4) + addr = ipv4address_from_octets (oct1) (oct2) (oct3) (oct4) oct1 = octet_from_int (octs !! 0) oct2 = octet_from_int (octs !! 1) oct3 = octet_from_int (octs !! 2)