instance Show SockAddr

Tomasz Zielonka t.zielonka at students.mimuw.edu.pl
Fri Oct 15 14:43:44 EDT 2004


On Fri, Oct 15, 2004 at 04:24:01PM +0200, Peter Simons wrote:
> Hi,
> 
> I've found myself needing to show a SockAddr type left and
> right in my code. Is it possible to add the appropriate
> definition to Network.Socket? Here is a suggestion:
> 
> -- |Split up an 32-bit word in network byte order.
> 
> 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. 

Couldn't GHC's HostAddress be always in host-order, with necessary
conversions done behind the curtains? 

When I was playing with pure Haskell DNS resolver library, the current
situation forced me to make foreign imports for htonl. Because of this
the library is 99.9% Haskell + 0.01% C.

Best regards,
Tom

-- 
.signature: Too many levels of symbolic links


More information about the Libraries mailing list