From d6e6d6b650b3331d87ac9940ad170bb53a7d6990 Mon Sep 17 00:00:00 2001 From: Gregor Maier Date: Wed, 15 Dec 2010 07:58:58 -0800 Subject: [PATCH] Fixing endianess error in XDR when data is not 4-byte aligned. --- src/XDR.cc | 6 +++--- src/XDR.h | 5 ----- 2 files changed, 3 insertions(+), 8 deletions(-) diff --git a/src/XDR.cc b/src/XDR.cc index 4e6a05ff10..9e2074f1ac 100644 --- a/src/XDR.cc +++ b/src/XDR.cc @@ -17,13 +17,13 @@ uint32 extract_XDR_uint32(const u_char*& buf, int& len) return 0; } - uint32 bits32 = XDR_aligned(buf) ? *(uint32*) buf : - ((buf[0] << 24) | (buf[1] << 16) | (buf[2] << 8) | buf[3]); + // takes care of alignment and endianess differences. + uint32 bits32 = (buf[0] << 24) | (buf[1] << 16) | (buf[2] << 8) | buf[3]; buf += 4; len -= 4; - return ntohl(bits32); + return bits32; } double extract_XDR_uint64_as_double(const u_char*& buf, int& len) diff --git a/src/XDR.h b/src/XDR.h index 070e13ee6c..047acd90f5 100644 --- a/src/XDR.h +++ b/src/XDR.h @@ -10,11 +10,6 @@ #include "util.h" -inline int XDR_aligned(const u_char* buf) - { - return (((unsigned long) buf) & 0x3) == 0; - } - extern uint32 extract_XDR_uint32(const u_char*& buf, int& len); extern double extract_XDR_uint64_as_double(const u_char*& buf, int& len); extern double extract_XDR_time(const u_char*& buf, int& len);