[Gllug] endian.h

Andy Farnsworth farnsaw at stonedoor.com
Wed Feb 5 17:23:04 UTC 2003


The gent on the other list corrected himself about the time you sent this.

Sorry folks,

Andy Farnsworth

-----Original Message-----
From: gllug-admin at linux.co.uk [mailto:gllug-admin at linux.co.uk]On Behalf
Of Tethys
Sent: February 05 2003 17:52
To: gllug at linux.co.uk
Subject: Re: [Gllug] endian.h



rich at annexia.org writes:

>> >So betoh32 <-> ntohl && letoh32 <-> htonl
>
> [...]
>
>Hmmm ... except that it probably won't fail. On, say, Sparc machines,
>the betoh32 (Big Endian to Host) transformation _is_ a null transformation,
>because Sparcs are already Big Endian.

Yes, it will still fail. In fact, if you do a direct swap as described,
it'll even fail on little endian, too!

On little endian:

	betoh32 -> ntohl -> transform    (correct)
	letoh32 -> htonl -> transform    (*WRONG*)

On big endian:

	betoh32 -> ntohl -> no transform (correct)
	letoh32 -> htonl -> no transform (*WRONG*)

On little endian, you can fix that with "#define letoh32(x) (x)".
The same trick doesn't work on big endian, though, and you need
to resort to a manual conversion. With glibc, you can use bswap_32(),
but it's not portable.

Tet

--
Gllug mailing list  -  Gllug at linux.co.uk
http://list.ftech.net/mailman/listinfo/gllug


-- 
Gllug mailing list  -  Gllug at linux.co.uk
http://list.ftech.net/mailman/listinfo/gllug




More information about the GLLUG mailing list