module Maskable where
-import Bit
+import qualified Bit as B
import IPv4Address
import Maskbits
import Octet
instance Maskable Octet where
apply_mask _ Maskbits.None = Octet.None
- apply_mask oct (Maskbits maskbits)
- | maskbits == 8 = oct
- | maskbits == 7 = oct { b8 = Zero }
- | maskbits == 6 = oct { b8 = Zero, b7 = Zero }
- | maskbits == 5 = oct { b8 = Zero, b7 = Zero, b6 = Zero }
- | maskbits == 4 = oct { b8 = Zero, b7 = Zero, b6 = Zero, b5 = Zero }
- | maskbits == 3 = oct { b8 = Zero, b7 = Zero, b6 = Zero, b5 = Zero, b4 = Zero }
- | maskbits == 2 = oct { b8 = Zero, b7 = Zero, b6 = Zero, b5 = Zero, b4 = Zero, b3 = Zero }
- | maskbits == 1 = oct { b8 = Zero, b7 = Zero, b6 = Zero, b5 = Zero, b4 = Zero, b3 = Zero, b2 = Zero }
- | maskbits == 0 = min_octet
+ apply_mask Octet.None _ = Octet.None
+ apply_mask oct mask
+ | mask == Eight = oct
+ | mask == Seven = oct { b8 = B.Zero }
+ | mask == Six = oct { b8 = B.Zero, b7 = B.Zero }
+ | mask == Five = oct { b8 = B.Zero, b7 = B.Zero, b6 = B.Zero }
+ | mask == Four = oct { b8 = B.Zero, b7 = B.Zero, b6 = B.Zero, b5 = B.Zero }
+ | mask == Three = oct { b8 = B.Zero, b7 = B.Zero, b6 = B.Zero, b5 = B.Zero, b4 = B.Zero }
+ | mask == Two = oct { b8 = B.Zero, b7 = B.Zero, b6 = B.Zero, b5 = B.Zero, b4 = B.Zero, b3 = B.Zero }
+ | mask == One = oct { b8 = B.Zero, b7 = B.Zero, b6 = B.Zero, b5 = B.Zero, b4 = B.Zero, b3 = B.Zero, b2 = B.Zero }
+ | mask == Zero = min_octet
| otherwise = Octet.None
instance Maskable IPv4Address where
apply_mask _ Maskbits.None = IPv4Address.None
- apply_mask addr (Maskbits mask)
- | mask == 32 = ipv4address_from_octets oct1 oct2 oct3 oct4
- | mask == 31 = ipv4address_from_octets oct1 oct2 oct3 (apply_mask oct4 (Maskbits 1))
- | mask == 30 = ipv4address_from_octets oct1 oct2 oct3 (apply_mask oct4 (Maskbits 2))
- | mask == 29 = ipv4address_from_octets oct1 oct2 oct3 (apply_mask oct4 (Maskbits 3))
- | mask == 28 = ipv4address_from_octets oct1 oct2 oct3 (apply_mask oct4 (Maskbits 4))
- | mask == 27 = ipv4address_from_octets oct1 oct2 oct3 (apply_mask oct4 (Maskbits 5))
- | mask == 26 = ipv4address_from_octets oct1 oct2 oct3 (apply_mask oct4 (Maskbits 6))
- | mask == 25 = ipv4address_from_octets oct1 oct2 oct3 (apply_mask oct4 (Maskbits 7))
- | mask == 24 = ipv4address_from_octets oct1 oct2 oct3 (min_octet)
- | mask == 23 = ipv4address_from_octets oct1 oct2 (apply_mask oct3 (Maskbits 1)) (min_octet)
- | mask == 22 = ipv4address_from_octets oct1 oct2 (apply_mask oct3 (Maskbits 2)) (min_octet)
- | mask == 21 = ipv4address_from_octets oct1 oct2 (apply_mask oct3 (Maskbits 3)) (min_octet)
- | mask == 20 = ipv4address_from_octets oct1 oct2 (apply_mask oct3 (Maskbits 4)) (min_octet)
- | mask == 19 = ipv4address_from_octets oct1 oct2 (apply_mask oct3 (Maskbits 5)) (min_octet)
- | mask == 18 = ipv4address_from_octets oct1 oct2 (apply_mask oct3 (Maskbits 6)) (min_octet)
- | mask == 17 = ipv4address_from_octets oct1 oct2 (apply_mask oct3 (Maskbits 7)) (min_octet)
- | mask == 16 = ipv4address_from_octets oct1 oct2 (min_octet) (min_octet)
- | mask == 15 = ipv4address_from_octets oct1 (apply_mask oct2 (Maskbits 1)) (min_octet) (min_octet)
- | mask == 14 = ipv4address_from_octets oct1 (apply_mask oct2 (Maskbits 2)) (min_octet) (min_octet)
- | mask == 13 = ipv4address_from_octets oct1 (apply_mask oct2 (Maskbits 3)) (min_octet) (min_octet)
- | mask == 12 = ipv4address_from_octets oct1 (apply_mask oct2 (Maskbits 4)) (min_octet) (min_octet)
- | mask == 11 = ipv4address_from_octets oct1 (apply_mask oct2 (Maskbits 5)) (min_octet) (min_octet)
- | mask == 10 = ipv4address_from_octets oct1 (apply_mask oct2 (Maskbits 6)) (min_octet) (min_octet)
- | mask == 9 = ipv4address_from_octets oct1 (apply_mask oct2 (Maskbits 7)) (min_octet) (min_octet)
- | mask == 8 = ipv4address_from_octets oct1 (min_octet) (min_octet) (min_octet)
- | mask == 7 = ipv4address_from_octets (apply_mask oct1 (Maskbits 1)) (min_octet) (min_octet) (min_octet)
- | mask == 6 = ipv4address_from_octets (apply_mask oct1 (Maskbits 2)) (min_octet) (min_octet) (min_octet)
- | mask == 5 = ipv4address_from_octets (apply_mask oct1 (Maskbits 3)) (min_octet) (min_octet) (min_octet)
- | mask == 4 = ipv4address_from_octets (apply_mask oct1 (Maskbits 4)) (min_octet) (min_octet) (min_octet)
- | mask == 3 = ipv4address_from_octets (apply_mask oct1 (Maskbits 5)) (min_octet) (min_octet) (min_octet)
- | mask == 2 = ipv4address_from_octets (apply_mask oct1 (Maskbits 6)) (min_octet) (min_octet) (min_octet)
- | mask == 1 = ipv4address_from_octets (apply_mask oct1 (Maskbits 7)) (min_octet) (min_octet) (min_octet)
- | mask == 0 = ipv4address_from_octets (min_octet) (min_octet) (min_octet) (min_octet)
+ apply_mask addr mask
+ | mask == ThirtyTwo = ipv4address_from_octets oct1 oct2 oct3 oct4
+ | mask == ThirtyOne = ipv4address_from_octets oct1 oct2 oct3 (apply_mask oct4 One)
+ | mask == Thirty = ipv4address_from_octets oct1 oct2 oct3 (apply_mask oct4 Two)
+ | mask == TwentyNine = ipv4address_from_octets oct1 oct2 oct3 (apply_mask oct4 Three)
+ | mask == TwentyEight = ipv4address_from_octets oct1 oct2 oct3 (apply_mask oct4 Four)
+ | mask == TwentySeven = ipv4address_from_octets oct1 oct2 oct3 (apply_mask oct4 Five)
+ | mask == TwentySix = ipv4address_from_octets oct1 oct2 oct3 (apply_mask oct4 Six)
+ | mask == TwentyFive = ipv4address_from_octets oct1 oct2 oct3 (apply_mask oct4 Seven)
+ | mask == TwentyFour = ipv4address_from_octets oct1 oct2 oct3 (min_octet)
+ | mask == TwentyThree = ipv4address_from_octets oct1 oct2 (apply_mask oct3 One) (min_octet)
+ | mask == TwentyTwo = ipv4address_from_octets oct1 oct2 (apply_mask oct3 Two) (min_octet)
+ | mask == TwentyOne = ipv4address_from_octets oct1 oct2 (apply_mask oct3 Three) (min_octet)
+ | mask == Twenty = ipv4address_from_octets oct1 oct2 (apply_mask oct3 Four) (min_octet)
+ | mask == Nineteen = ipv4address_from_octets oct1 oct2 (apply_mask oct3 Five) (min_octet)
+ | mask == Eighteen = ipv4address_from_octets oct1 oct2 (apply_mask oct3 Six) (min_octet)
+ | mask == Seventeen = ipv4address_from_octets oct1 oct2 (apply_mask oct3 Seven) (min_octet)
+ | mask == Sixteen = ipv4address_from_octets oct1 oct2 (min_octet) (min_octet)
+ | mask == Fifteen = ipv4address_from_octets oct1 (apply_mask oct2 One) (min_octet) (min_octet)
+ | mask == Fourteen = ipv4address_from_octets oct1 (apply_mask oct2 Two) (min_octet) (min_octet)
+ | mask == Thirteen = ipv4address_from_octets oct1 (apply_mask oct2 Three) (min_octet) (min_octet)
+ | mask == Twelve = ipv4address_from_octets oct1 (apply_mask oct2 Four) (min_octet) (min_octet)
+ | mask == Eleven = ipv4address_from_octets oct1 (apply_mask oct2 Five) (min_octet) (min_octet)
+ | mask == Ten = ipv4address_from_octets oct1 (apply_mask oct2 Six) (min_octet) (min_octet)
+ | mask == Nine = ipv4address_from_octets oct1 (apply_mask oct2 Seven) (min_octet) (min_octet)
+ | mask == Eight = ipv4address_from_octets oct1 (min_octet) (min_octet) (min_octet)
+ | mask == Seven = ipv4address_from_octets (apply_mask oct1 One) (min_octet) (min_octet) (min_octet)
+ | mask == Six = ipv4address_from_octets (apply_mask oct1 Two) (min_octet) (min_octet) (min_octet)
+ | mask == Five = ipv4address_from_octets (apply_mask oct1 Three) (min_octet) (min_octet) (min_octet)
+ | mask == Four = ipv4address_from_octets (apply_mask oct1 Four) (min_octet) (min_octet) (min_octet)
+ | mask == Three = ipv4address_from_octets (apply_mask oct1 Five) (min_octet) (min_octet) (min_octet)
+ | mask == Two = ipv4address_from_octets (apply_mask oct1 Six) (min_octet) (min_octet) (min_octet)
+ | mask == One = ipv4address_from_octets (apply_mask oct1 Seven) (min_octet) (min_octet) (min_octet)
+ | mask == Zero = ipv4address_from_octets (min_octet) (min_octet) (min_octet) (min_octet)
| otherwise = IPv4Address.None
where
oct1 = (octet1 addr)