From mboxrd@z Thu Jan 1 00:00:00 1970 From: Mike Frysinger Date: Wed, 12 Oct 2011 17:48:01 -0400 Subject: [U-Boot] [PATCH] net/dns.c: Fix broken endian handling in dns command In-Reply-To: <1318454600-18349-1-git-send-email-bernhard.kaindl@gmx.net> References: <1318454600-18349-1-git-send-email-bernhard.kaindl@gmx.net> Message-ID: <201110121748.03380.vapier@gentoo.org> List-Id: MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit To: u-boot@lists.denx.de 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