[U-Boot] [PATCH] net/dns.c: Fix broken endian handling in dns command

Mike Frysinger vapier at gentoo.org
Wed Oct 12 23:48:01 CEST 2011


On Wednesday 12 October 2011 17:23:20 Bernhard Kaindl wrote:
> The U-Boot dns command only worked in little-endian CPUs so far because it
> was based on an antique version of the TADNS source which was using a
> broken macro to read the shorts found in DNS reply messages by shifting
> the LSB from the message into the CPU's MSB of a short int and the MSB
> from the stream into the LSB part of the CPU's short int. So far, so
> twisted.
> 
> To correct the twisted bytes, the code used ntohs() as a byte-swapping
> function to swap the MSB back where it belongs and vice versa.
> 
> This works fine, except that ntohs() naturally does nothing on big-endian
> CPUs.
> 
> So on big-endian CPUs, the MSB from the message stayed in the LSB of the
> CPU and vice versa.
> 
> Ditch this brain-deadness by just shifting the MSB from the network byte
> stream of the reply message into the right (MSB) location of a short int
> and putting the LSB from the network byte stream as the lower byte of it,
> and we are done with reading the short from the network stream for both
> endianesses, no ntohs() or such!

please use a standard macro instead of inventing yet another.  we've got the 
rich Linux api which should cover every case you could possibly need.
	cpu_to_{l,b}e{16,32,64}(...)
	{l,b}e_to_cpu{16,32,63}(...)

see include/linux/byteorder/
-mike
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 836 bytes
Desc: This is a digitally signed message part.
Url : http://lists.denx.de/pipermail/u-boot/attachments/20111012/701fc3e3/attachment.pgp 


More information about the U-Boot mailing list