From ac6042568d7c10b3d9d070fb3c4b1864256e51ac Mon Sep 17 00:00:00 2001 From: Michael Orlitzky Date: Sun, 2 May 2010 17:04:37 -0400 Subject: [PATCH] Added the Maskbits module and type. --- src/Maskbits.hs | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 src/Maskbits.hs diff --git a/src/Maskbits.hs b/src/Maskbits.hs new file mode 100644 index 0000000..cb4ab89 --- /dev/null +++ b/src/Maskbits.hs @@ -0,0 +1,22 @@ +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) -- 2.43.2