7 -- A type representing the number of bits in a CIDR netmask.
45 instance Show Maskbits where
70 show TwentyThree = "23"
71 show TwentyFour = "24"
72 show TwentyFive = "25"
74 show TwentySeven = "27"
75 show TwentyEight = "28"
76 show TwentyNine = "29"
83 -- There are only 32 bits in an IPv4 address, so there
84 -- can't be more bits than that in the mask.
85 maskbits_from_int :: Int -> Maskbits
86 maskbits_from_int 0 = Zero
87 maskbits_from_int 1 = One
88 maskbits_from_int 2 = Two
89 maskbits_from_int 3 = Three
90 maskbits_from_int 4 = Four
91 maskbits_from_int 5 = Five
92 maskbits_from_int 6 = Six
93 maskbits_from_int 7 = Seven
94 maskbits_from_int 8 = Eight
95 maskbits_from_int 9 = Nine
96 maskbits_from_int 10 = Ten
97 maskbits_from_int 11 = Eleven
98 maskbits_from_int 12 = Twelve
99 maskbits_from_int 13 = Thirteen
100 maskbits_from_int 14 = Fourteen
101 maskbits_from_int 15 = Fifteen
102 maskbits_from_int 16 = Sixteen
103 maskbits_from_int 17 = Seventeen
104 maskbits_from_int 18 = Eighteen
105 maskbits_from_int 19 = Nineteen
106 maskbits_from_int 20 = Twenty
107 maskbits_from_int 21 = TwentyOne
108 maskbits_from_int 22 = TwentyTwo
109 maskbits_from_int 23 = TwentyThree
110 maskbits_from_int 24 = TwentyFour
111 maskbits_from_int 25 = TwentyFive
112 maskbits_from_int 26 = TwentySix
113 maskbits_from_int 27 = TwentySeven
114 maskbits_from_int 28 = TwentyEight
115 maskbits_from_int 29 = TwentyNine
116 maskbits_from_int 30 = Thirty
117 maskbits_from_int 31 = ThirtyOne
118 maskbits_from_int 32 = ThirtyTwo
119 maskbits_from_int _ = None
122 maskbits_from_string :: String -> Maskbits
123 maskbits_from_string s =
124 case (reads s :: [(Int, String)]) of
126 x:_ -> maskbits_from_int (fst x)
130 decrement :: Maskbits -> Maskbits
131 decrement None = None
132 decrement Zero = None
135 decrement Three = Two
136 decrement Four = Three
137 decrement Five = Four
139 decrement Seven = Six
140 decrement Eight = Seven
141 decrement Nine = Eight
143 decrement Eleven = Ten
144 decrement Twelve = Eleven
145 decrement Thirteen = Twelve
146 decrement Fourteen = Thirteen
147 decrement Fifteen = Fourteen
148 decrement Sixteen = Fifteen
149 decrement Seventeen = Sixteen
150 decrement Eighteen = Seventeen
151 decrement Nineteen = Eighteen
152 decrement Twenty = Nineteen
153 decrement TwentyOne = Twenty
154 decrement TwentyTwo = TwentyOne
155 decrement TwentyThree = TwentyTwo
156 decrement TwentyFour = TwentyThree
157 decrement TwentyFive = TwentyFour
158 decrement TwentySix = TwentyFive
159 decrement TwentySeven = TwentySix
160 decrement TwentyEight = TwentySeven
161 decrement TwentyNine = TwentyEight
162 decrement Thirty = TwentyNine
163 decrement ThirtyOne = Thirty
164 decrement ThirtyTwo = ThirtyOne