-
-
Save dminuoso/8c4eb6a1d996f4e226f9ecce23c35895 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
data IPv4 = IPv4 Word32 | |
deriving (Eq, Ord, Show) | |
ipv4ToWord8s :: IPv4 -> (Word8, Word8, Word8, Word8) | |
ipv4ToWord8s (IPv4 addr) = ( fromIntegral (addr `unsafeShiftR` 24) | |
, fromIntegral (addr `unsafeShiftR` 16) | |
, fromIntegral (addr `unsafeShiftR` 8) | |
, fromIntegral addr | |
) | |
ipv4FromWord8s :: Word8 -> Word8 -> Word8 -> Word8 -> IPv4 | |
ipv4FromWord8s a b c d = IPv4 $ (fromIntegral a `shiftL` 24) | |
.|. (fromIntegral b `shiftL` 16) | |
.|. (fromIntegral c `shiftL` 8) | |
.|. (fromIntegral d) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment