-module IPv4Address where
+module IPv4Address
+( ipv4address_from_octets,
+ IPv4Address(None),
+ Maskbits,
+ max_octet1,
+ max_octet2,
+ max_octet3,
+ max_octet4,
+ min_octet1,
+ min_octet2,
+ min_octet3,
+ min_octet4
+)
+ where
import Bit
import Octet
type Maskbits = Int
-data IPv4Address = IPv4Address { octet1 :: Octet,
- octet2 :: Octet,
- octet3 :: Octet,
- octet4 :: Octet }
+data IPv4Address = None | IPv4Address { octet1 :: Octet,
+ octet2 :: Octet,
+ octet3 :: Octet,
+ octet4 :: Octet }
deriving (Eq, Show)
+-- We don't export our constructor so this function is the only
+-- way to construct an address from octets. As a result, we can
+-- return IPv4Address.None in response to being passed one of more
+-- Octet.None octets.
+ipv4address_from_octets :: Octet -> Octet -> Octet -> Octet -> IPv4Address
+ipv4address_from_octets oct1 oct2 oct3 oct4
+ | or [oct1 == Octet.None,
+ oct2 == Octet.None,
+ oct3 == Octet.None,
+ oct4 == Octet.None] = IPv4Address.None
+ | otherwise = IPv4Address oct1 oct2 oct3 oct4
+
+
min_address :: IPv4Address -> Maskbits -> IPv4Address
min_address addr mask
| mask == 32 = IPv4Address oct1 oct2 oct3 oct4