From: Bernhard Kaindl <bernhard.kaindl@gmx.net>
To: u-boot@lists.denx.de
Subject: [U-Boot] [PATCH] net/dns.c: Fix broken endian handling in dns command
Date: Fri, 14 Oct 2011 09:44:13 +0200 [thread overview]
Message-ID: <4E97E84D.2020606@gmx.net> (raw)
In-Reply-To: <201110121748.03380.vapier@gentoo.org>
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
next prev parent reply other threads:[~2011-10-14 7:44 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-10-12 21:23 [U-Boot] [PATCH] net/dns.c: Fix broken endian handling in dns command Bernhard Kaindl
2011-10-12 21:48 ` Mike Frysinger
2011-10-14 7:44 ` Bernhard Kaindl [this message]
2011-10-14 15:41 ` Mike Frysinger
2011-10-16 9:59 ` [U-Boot] [PATCH] net/dns.c: Fix endian conversion for big-endian " Bernhard Kaindl
2011-10-16 12:11 ` Robin Getz
2011-10-16 15:14 ` Mike Frysinger
2011-10-23 20:57 ` Wolfgang Denk
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=4E97E84D.2020606@gmx.net \
--to=bernhard.kaindl@gmx.net \
--cc=u-boot@lists.denx.de \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox