[pisa-src] r2514 - trunk/tools/dhcp/mac2ip.c

  • From: Christoph Viethen <christoph.viethen@xxxxxxxxxxxxxx>
  • To: pisa-src@xxxxxxxxxxxxx
  • Date: Tue, 5 Apr 2011 01:22:18 +0200

Author: viethen
Date: Tue Apr  5 01:22:17 2011
New Revision: 2514

Log:
fix endianness bug in IP generation code (choosing clarity over elegance)

Modified:
   trunk/tools/dhcp/mac2ip.c

Modified: trunk/tools/dhcp/mac2ip.c
==============================================================================
--- trunk/tools/dhcp/mac2ip.c   Tue Apr  5 01:09:19 2011        (r2513)
+++ trunk/tools/dhcp/mac2ip.c   Tue Apr  5 01:22:17 2011        (r2514)
@@ -62,7 +62,15 @@
     /* hash it! */
     hash = jenkins_one_at_a_time_hash((char *) mac_duplicate.x, 
sizeof(mac_duplicate.x));
 
-    *((uint32_t *) ip->x) = hash;
+    /* store the hash value in LSB-first order (the previous version of this
+     *  code relied on a platform's endianness and was evaluated on the LE 
x86_64
+     *  platform, so we emulate this behaviour now for all platforms 
independent
+     *  of their actual endianness)
+     */
+    ip->x[3] = (hash & 0xff000000) >> 24;
+    ip->x[2] = (hash & 0x00ff0000) >> 16;
+    ip->x[1] = (hash & 0x0000ff00) >>  8;
+    ip->x[0] =  hash & 0x000000ff;
 }
 
 /* converts mac in hex_string_format to mac_t */
-- 
This is the pisa developer mailing list. Please also subscribe to the main pisa 
list at:
//www.freelists.org/list/pisa

Other related posts: