darcs patch: Implementation of aton and ntoa outside the IO monad

Tomasz Zielonka tomasz.zielonka at gmail.com
Sun Sep 24 05:42:28 EDT 2006

On Sun, Sep 24, 2006 at 05:07:23PM +0900, Robert Marlow wrote:
> Erk, I just realised this patch is completely wrong since the
> HostAddress will be totally different depending on the endianness of the
> platform.

I was thinking about it before. As of now, Network libraries just
put bits in network order into values of type HostAddress = Word32. But
Word32 is interpreted in host order by Haskell, so the same IP address
will be seen as a different number on little and big endian platforms.

The best would be to have an endianness independent representation for
IP4 addresses, by converting IP addresses to host order. This way things
are simple - the most significant octet of IP address with be the most
significant 8-bits of HostAddress, etc.

Conversion to/from network order could be done around calls to various
system calls. Yes, it adds an (small) additional cost (on little endian
machines), but I think it's worth it. With current design you sometimes
can't avoid impure and/or inelegant code.

Best regards

More information about the Libraries mailing list