X-Git-Url: https://gitweb.michael.orlitzky.com/?a=blobdiff_plain;f=src%2FIPv4Address.hs;h=7c5d80deb6d00fd60a324fa82a916aaff233317f;hb=ebe1475e977790ce14eb31e4a75d82e413590bc9;hp=3d6b1bbc2980107ae15d3d9da3ccd521b5cd2c9c;hpb=efae8ede78e938ce92379614428c498c4beccc44;p=hath.git diff --git a/src/IPv4Address.hs b/src/IPv4Address.hs index 3d6b1bb..7c5d80d 100644 --- a/src/IPv4Address.hs +++ b/src/IPv4Address.hs @@ -1,17 +1,43 @@ -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