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

Bernhard Kaindl bernhard.kaindl at gmx.net
Fri Oct 14 09:44:13 CEST 2011


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/
> -mike

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.

I'd prefer the already sent patch.

Best Regards,
Bernhard


More information about the U-Boot mailing list