From: Michael Orlitzky Date: Sat, 28 Aug 2010 06:08:40 +0000 (-0400) Subject: Don't use min_address or min_octet in the apply_mask functions. Now that apply_mask... X-Git-Tag: 0.0.1~18 X-Git-Url: https://gitweb.michael.orlitzky.com/?a=commitdiff_plain;h=e2cb918f1808f7f54cc742418050d49b424848c5;p=hath.git Don't use min_address or min_octet in the apply_mask functions. Now that apply_mask accepts a mask bit, we no longer necessarily want the minimum. --- diff --git a/src/IPv4Address.hs b/src/IPv4Address.hs index 6d1e56e..575ce0d 100644 --- a/src/IPv4Address.hs +++ b/src/IPv4Address.hs @@ -61,46 +61,79 @@ instance Maskable IPv4Address where | mask == TwentySeven = addr { octet4 = (apply_mask oct4 Three bit) } | mask == TwentySix = addr { octet4 = (apply_mask oct4 Two bit) } | mask == TwentyFive = addr { octet4 = (apply_mask oct4 One bit) } - | mask == TwentyFour = addr { octet4 = min_octet } + | mask == TwentyFour = addr { octet4 = (apply_mask oct4 Zero bit) } | mask == TwentyThree = addr { octet3 = (apply_mask oct3 Seven bit), - octet4 = min_octet } + octet4 = (apply_mask oct4 Zero bit) } | mask == TwentyTwo = addr { octet3 = (apply_mask oct3 Six bit), - octet4 = min_octet } + octet4 = (apply_mask oct4 Zero bit) } | mask == TwentyOne = addr { octet3 = (apply_mask oct3 Five bit), - octet4 = min_octet } + octet4 = (apply_mask oct4 Zero bit) } | mask == Twenty = addr { octet3 = (apply_mask oct3 Four bit), - octet4 = min_octet } + octet4 = (apply_mask oct4 Zero bit) } | mask == Nineteen = addr { octet3 = (apply_mask oct3 Three bit), - octet4 = min_octet } + octet4 = (apply_mask oct4 Zero bit) } | mask == Eighteen = addr { octet3 = (apply_mask oct3 Two bit), - octet4 = min_octet } + octet4 = (apply_mask oct4 Zero bit) } | mask == Seventeen = addr { octet3 = (apply_mask oct3 One bit), - octet4 = min_octet } - | mask == Sixteen = addr { octet3 = min_octet, - octet4 = min_octet } - | mask == Fifteen = min_address { octet1 = oct1, - octet2 = (apply_mask oct2 Seven bit) } - | mask == Fourteen = min_address { octet1 = oct1, - octet2 = (apply_mask oct2 Six bit) } - | mask == Thirteen = min_address { octet1 = oct1, - octet2 = (apply_mask oct2 Five bit) } - | mask == Twelve = min_address { octet1 = oct1, - octet2 = (apply_mask oct2 Four bit) } - | mask == Eleven = min_address { octet1 = oct1, - octet2 = (apply_mask oct2 Three bit) } - | mask == Ten = min_address { octet1 = oct1, - octet2 = (apply_mask oct2 Two bit) } - | mask == Nine = min_address { octet1 = oct1, - octet2 = (apply_mask oct2 One bit) } - | mask == Eight = min_address { octet1 = oct1 } - | mask == Seven = min_address { octet1 = (apply_mask oct1 Seven bit) } - | mask == Six = min_address { octet1 = (apply_mask oct1 Six bit) } - | mask == Five = min_address { octet1 = (apply_mask oct1 Five bit) } - | mask == Four = min_address { octet1 = (apply_mask oct1 Four bit) } - | mask == Three = min_address { octet1 = (apply_mask oct1 Three bit) } - | mask == Two = min_address { octet1 = (apply_mask oct1 Two bit) } - | mask == One = min_address { octet1 = (apply_mask oct1 One bit) } - | mask == Zero = min_address + octet4 = (apply_mask oct4 Zero bit) } + | mask == Sixteen = addr { octet3 = (apply_mask oct3 Zero bit), + octet4 = (apply_mask oct4 Zero bit) } + | mask == Fifteen = addr { octet2 = (apply_mask oct2 Seven bit), + octet3 = (apply_mask oct3 Zero bit), + octet4 = (apply_mask oct4 Zero bit) } + | mask == Fourteen = addr { octet2 = (apply_mask oct2 Six bit), + octet3 = (apply_mask oct3 Zero bit), + octet4 = (apply_mask oct4 Zero bit)} + | mask == Thirteen = addr { octet2 = (apply_mask oct2 Five bit), + octet3 = (apply_mask oct3 Zero bit), + octet4 = (apply_mask oct4 Zero bit)} + | mask == Twelve = addr { octet2 = (apply_mask oct2 Four bit), + octet3 = (apply_mask oct3 Zero bit), + octet4 = (apply_mask oct4 Zero bit)} + | mask == Eleven = addr { octet2 = (apply_mask oct2 Three bit), + octet3 = (apply_mask oct3 Zero bit), + octet4 = (apply_mask oct4 Zero bit)} + | mask == Ten = addr { octet2 = (apply_mask oct2 Two bit), + octet3 = (apply_mask oct3 Zero bit), + octet4 = (apply_mask oct4 Zero bit)} + | mask == Nine = addr { octet2 = (apply_mask oct2 One bit), + octet3 = (apply_mask oct3 Zero bit), + octet4 = (apply_mask oct4 Zero bit)} + | mask == Eight = addr { octet2 = (apply_mask oct2 Zero bit), + octet3 = (apply_mask oct3 Zero bit), + octet4 = (apply_mask oct4 Zero bit)} + | mask == Seven = addr { octet1 = (apply_mask oct1 Seven bit), + octet2 = (apply_mask oct2 Zero bit), + octet3 = (apply_mask oct3 Zero bit), + octet4 = (apply_mask oct4 Zero bit)} + | mask == Six = addr { octet1 = (apply_mask oct1 Six bit), + octet2 = (apply_mask oct2 Zero bit), + octet3 = (apply_mask oct3 Zero bit), + octet4 = (apply_mask oct4 Zero bit)} + | mask == Five = addr { octet1 = (apply_mask oct1 Five bit), + octet2 = (apply_mask oct2 Zero bit), + octet3 = (apply_mask oct3 Zero bit), + octet4 = (apply_mask oct4 Zero bit)} + | mask == Four = addr { octet1 = (apply_mask oct1 Four bit), + octet2 = (apply_mask oct2 Zero bit), + octet3 = (apply_mask oct3 Zero bit), + octet4 = (apply_mask oct4 Zero bit)} + | mask == Three = addr { octet1 = (apply_mask oct1 Three bit), + octet2 = (apply_mask oct2 Zero bit), + octet3 = (apply_mask oct3 Zero bit), + octet4 = (apply_mask oct4 Zero bit)} + | mask == Two = addr { octet1 = (apply_mask oct1 Two bit), + octet2 = (apply_mask oct2 Zero bit), + octet3 = (apply_mask oct3 Zero bit), + octet4 = (apply_mask oct4 Zero bit)} + | mask == One = addr { octet1 = (apply_mask oct1 One bit), + octet2 = (apply_mask oct2 Zero bit), + octet3 = (apply_mask oct3 Zero bit), + octet4 = (apply_mask oct4 Zero bit)} + | mask == Zero = addr { octet1 = (apply_mask oct1 Zero bit), + octet2 = (apply_mask oct2 Zero bit), + octet3 = (apply_mask oct3 Zero bit), + octet4 = (apply_mask oct4 Zero bit)} | otherwise = IPv4Address.None where oct1 = (octet1 addr) diff --git a/src/Octet.hs b/src/Octet.hs index d80b796..98fcb02 100644 --- a/src/Octet.hs +++ b/src/Octet.hs @@ -53,7 +53,7 @@ instance Maskable Octet where | mask == Three = oct { b8 = bit, b7 = bit, b6 = bit, b5 = bit, b4 = bit } | mask == Two = oct { b8 = bit, b7 = bit, b6 = bit, b5 = bit, b4 = bit, b3 = bit } | mask == Maskbits.One = oct { b8 = bit, b7 = bit, b6 = bit, b5 = bit, b4 = bit, b3 = bit, b2 = bit } - | mask == Maskbits.Zero = min_octet + | mask == Maskbits.Zero = oct { b8 = bit, b7 = bit, b6 = bit, b5 = bit, b4 = bit, b3 = bit, b2 = bit, b1 = bit } | otherwise = Octet.None