
On Sun, Oct 17, 2004 at 11:57:49PM +0200, Peter Simons wrote:
Tomasz Zielonka writes:
ha2tpl :: HostAddress -> (Int, Int, Int, Int) ha2tpl n = let (b1,n1) = (n .&. 255, n `shiftR` 8) (b2,n2) = (n1 .&. 255, n1 `shiftR` 8) (b3,n3) = (n2 .&. 255, n2 `shiftR` 8) b4 = n3 .&. 255 in (fromEnum b1, fromEnum b2, fromEnum b3, fromEnum b4)
This won't work on big-endian architectures.
Why not?
Because GHC keeps HostAddress in network-order (aka big-endian) but Data.Bits works in host order. First octet of IP4 address is the most significant byte in network-order word, but here you take it from the least significant byte. I assume that HostAddress on big-endian machines is also kept in network-order - but there this is the same as the host-order, so if you take the least significant byte you will get the last IP4 octet. Best regards, Tom -- .signature: Too many levels of symbolic links