
17 Oct
2004
17 Oct
'04
6:02 p.m.
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 it assumes that network byte order is the opposite of host byte order. Network order is big-endian, so if host-order is big-endian, too, then that is not the case, and ha2tpl returns the bytes in the wrong order. Cheers, Wolfgang