SF#3560776: Fix byte-ordering issues with INADDR_* literals

This commit is contained in:
Aleksandar Fabijanic
2012-09-07 03:34:08 +00:00
parent 03b7dcd3e1
commit 2a6c041422
2 changed files with 226 additions and 224 deletions

View File

@@ -173,11 +173,11 @@ extern "C"
extern unsigned int if_nametoindex (__const char *__ifname) __THROW; extern unsigned int if_nametoindex (__const char *__ifname) __THROW;
extern char *if_indextoname (unsigned int __ifindex, char *__ifname) __THROW; extern char *if_indextoname (unsigned int __ifindex, char *__ifname) __THROW;
} }
#else // (POCO_OS != POCO_OS_LINUX) #else
#include <net/if.h> #include <net/if.h>
#endif // (POCO_OS != POCO_OS_LINUX)
#endif #endif
#if defined(sun) || defined(__APPLE__) #endif
#if (POCO_OS == POCO_OS_SOLARIS) || (POCO_OS == POCO_OS_MAC_OS_X)
#include <sys/sockio.h> #include <sys/sockio.h>
#include <sys/filio.h> #include <sys/filio.h>
#endif #endif
@@ -282,7 +282,7 @@ extern char *if_indextoname (unsigned int __ifindex, char *__ifname) __THROW;
#ifndef INADDR_NONE #ifndef INADDR_NONE
#define INADDR_NONE 0xFFFFFFFF #define INADDR_NONE 0xffffffff
#endif #endif
#ifndef INADDR_ANY #ifndef INADDR_ANY
@@ -313,7 +313,6 @@ extern char *if_indextoname (unsigned int __ifindex, char *__ifname) __THROW;
#define INADDR_MAX_LOCAL_GROUP 0xe00000ff #define INADDR_MAX_LOCAL_GROUP 0xe00000ff
#endif #endif
#if defined(POCO_ARCH_BIG_ENDIAN) #if defined(POCO_ARCH_BIG_ENDIAN)
#define poco_ntoh_16(x) (x) #define poco_ntoh_16(x) (x)
#define poco_ntoh_32(x) (x) #define poco_ntoh_32(x) (x)
@@ -323,6 +322,7 @@ extern char *if_indextoname (unsigned int __ifindex, char *__ifname) __THROW;
#define poco_ntoh_32(x) \ #define poco_ntoh_32(x) \
((((x) >> 24) & 0x000000ff) | (((x) >> 8) & 0x0000ff00) | (((x) << 8) & 0x00ff0000) | (((x) << 24) & 0xff000000)) ((((x) >> 24) & 0x000000ff) | (((x) >> 8) & 0x0000ff00) | (((x) << 8) & 0x00ff0000) | (((x) << 24) & 0xff000000))
#endif #endif
#define poco_hton_16(x) poco_ntoh_16(x)
#define poco_hton_32(x) poco_ntoh_32(x)
#endif // Net_SocketDefs_INCLUDED #endif // Net_SocketDefs_INCLUDED

View File

@@ -634,8 +634,10 @@ void IPAddressTest::testByteOrderMacros()
{ {
Poco::UInt16 a16 = 0xDEAD; Poco::UInt16 a16 = 0xDEAD;
assert (poco_ntoh_16(a16) == ntohs(a16)); assert (poco_ntoh_16(a16) == ntohs(a16));
assert (poco_hton_16(a16) == htons(a16));
Poco::UInt32 a32 = 0xDEADBEEF; Poco::UInt32 a32 = 0xDEADBEEF;
assert (poco_ntoh_32(a32) == ntohl(a32)); assert (poco_ntoh_32(a32) == ntohl(a32));
assert (poco_hton_32(a32) == htonl(a32));
} }