From: Mike Frysinger <vapier@gentoo.org>
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 11:41:38 -0400 [thread overview]
Message-ID: <201110141141.40124.vapier@gentoo.org> (raw)
In-Reply-To: <4E97E84D.2020606@gmx.net>
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
next prev parent reply other threads:[~2011-10-14 15:41 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
2011-10-14 15:41 ` Mike Frysinger [this message]
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=201110141141.40124.vapier@gentoo.org \
--to=vapier@gentoo.org \
--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