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

Mike Frysinger vapier at gentoo.org
Fri Oct 14 17:41:38 CEST 2011


On Friday 14 October 2011 03:44:13 Bernhard Kaindl wrote:
> Am 12.10.2011 23:48, schrieb Mike Frysinger:
> >> 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/
> 
> No, of course I looked, but didn't find what is needed.
> 
> These are just conditional byte swaps in 16,32 or 64 bit, not more.
> 
> The code needs is a conversion from an uneven "const char *" to u16!
> 
> It ___is___ possible to use be_to_cpu16, but it needs ugly casting:
> 
>          if (&p[5] > e || be_to_cpu16(*(u16 *)(p+1)) != DNS_A_RECORD) {
> 
> To not be distracted by reading the ugly casting, one would have to put
> this into a macro again, but if you really like to see be_to_cpu16 so
> much, I can change the macro to:
> 
> #define netstring_to_cpu_short(p)    be16_to_cpu(*(u16 *)(p))
> 
> This result doesn't make it more readable than what I already posted.

sounds like you want get_unaligned_be16()
-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/20111014/a6f62b68/attachment.pgp 


More information about the U-Boot mailing list