--- /dev/null
+module Maskbits
+( Maskbits(..),
+ maskbits_from_string
+) where
+
+-- A type representing the number of bits in a CIDR netmask.
+data Maskbits = None | Maskbits Int
+ deriving (Eq, Show)
+
+
+-- There are only 32 bits in an IPv4 address, so there
+-- can't be more bits than that in the mask.
+maskbits_from_int :: Int -> Maskbits
+maskbits_from_int x | (x < 0) || (x > 32) = None
+ | otherwise = Maskbits x
+
+
+maskbits_from_string :: String -> Maskbits
+maskbits_from_string s =
+ case (reads s :: [(Int, String)]) of
+ [] -> None
+ x:_ -> maskbits_from_int (fst x)