instance Show SockAddr

Wolfgang Thaller wolfgang.thaller at gmx.net
Sun Oct 17 18:02:14 EDT 2004


> 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



More information about the Libraries mailing list