Fixing endianess error in XDR when data is not 4-byte aligned.

This commit is contained in:
Gregor Maier 2010-12-15 07:58:58 -08:00
parent 2ced4839e9
commit d6e6d6b650
2 changed files with 3 additions and 8 deletions

View file

@ -17,13 +17,13 @@ uint32 extract_XDR_uint32(const u_char*& buf, int& len)
return 0; return 0;
} }
uint32 bits32 = XDR_aligned(buf) ? *(uint32*) buf : // takes care of alignment and endianess differences.
((buf[0] << 24) | (buf[1] << 16) | (buf[2] << 8) | buf[3]); uint32 bits32 = (buf[0] << 24) | (buf[1] << 16) | (buf[2] << 8) | buf[3];
buf += 4; buf += 4;
len -= 4; len -= 4;
return ntohl(bits32); return bits32;
} }
double extract_XDR_uint64_as_double(const u_char*& buf, int& len) double extract_XDR_uint64_as_double(const u_char*& buf, int& len)

View file

@ -10,11 +10,6 @@
#include "util.h" #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 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_uint64_as_double(const u_char*& buf, int& len);
extern double extract_XDR_time(const u_char*& buf, int& len); extern double extract_XDR_time(const u_char*& buf, int& len);