From 8825d30aabbee8cb2e452dc5a17deb6f9b6892a7 Mon Sep 17 00:00:00 2001 From: madmaxoft Date: Fri, 4 Apr 2014 10:13:25 +0200 Subject: Fixed some Clang warnings in protocols. --- src/Endianness.h | 31 +++++++++++++++++-------------- 1 file changed, 17 insertions(+), 14 deletions(-) (limited to 'src/Endianness.h') diff --git a/src/Endianness.h b/src/Endianness.h index 86eb369f5..6a2593077 100644 --- a/src/Endianness.h +++ b/src/Endianness.h @@ -1,12 +1,14 @@ #pragma once +#define ntohll(x) ((((UInt64)ntohl((u_long)x)) << 32) + ntohl(x >> 32)) + // Changes endianness -inline unsigned long long HostToNetwork8(const void* a_Value ) +inline UInt64 HostToNetwork8(const void * a_Value) { unsigned long long __HostToNetwork8; memcpy( &__HostToNetwork8, a_Value, sizeof( __HostToNetwork8 ) ); @@ -18,7 +20,7 @@ inline unsigned long long HostToNetwork8(const void* a_Value ) -inline unsigned int HostToNetwork4(const void* a_Value ) +inline UInt32 HostToNetwork4(const void* a_Value ) { unsigned int __HostToNetwork4; memcpy( &__HostToNetwork4, a_Value, sizeof( __HostToNetwork4 ) ); @@ -30,11 +32,10 @@ inline unsigned int HostToNetwork4(const void* a_Value ) -inline double NetworkToHostDouble8(const void* a_Value ) +inline double NetworkToHostDouble8(const void * a_Value) { -#define ntohll(x) ((((unsigned long long)ntohl((u_long)x)) << 32) + ntohl(x >> 32)) - unsigned long long buf = 0;//(*(unsigned long long*)a_Value); - memcpy( &buf, a_Value, 8 ); + UInt64 buf = 0; + memcpy(&buf, a_Value, 8); buf = ntohll(buf); double x; memcpy(&x, &buf, sizeof(double)); @@ -45,23 +46,25 @@ inline double NetworkToHostDouble8(const void* a_Value ) -inline long long NetworkToHostLong8(const void * a_Value ) +inline Int64 NetworkToHostLong8(const void * a_Value) { - unsigned long long buf = *(unsigned long long*)a_Value; + UInt64 buf; + memcpy(&buf, &a_Value, 8); buf = ntohll(buf); - return *reinterpret_cast(&buf); + return *reinterpret_cast(&buf); } -inline float NetworkToHostFloat4(const void* a_Value ) +inline float NetworkToHostFloat4(const void * a_Value) { - u_long buf = *(u_long*)a_Value; - buf = ntohl( buf ); - float x = 0; - memcpy( &x, &buf, sizeof(float) ); + UInt32 buf; + float x; + memcpy(&buf, &a_Value, 4); + buf = ntohl(buf); + memcpy(&x, &buf, sizeof(float)); return x; } -- cgit v1.2.3