diff --git a/Net/include/Poco/Net/SocketDefs.h b/Net/include/Poco/Net/SocketDefs.h index c87ebd4c0..13546aa79 100644 --- a/Net/include/Poco/Net/SocketDefs.h +++ b/Net/include/Poco/Net/SocketDefs.h @@ -313,4 +313,16 @@ extern char *if_indextoname (unsigned int __ifindex, char *__ifname) __THROW; #define INADDR_MAX_LOCAL_GROUP 0xe00000ff #endif + +#if defined(POCO_ARCH_BIG_ENDIAN) + #define poco_ntoh_16(x) (x) + #define poco_ntoh_32(x) (x) +#else + #define poco_ntoh_16(x) \ + ((((x) >> 8) & 0x00ff) | (((x) << 8) & 0xff00)) + #define poco_ntoh_32(x) \ + ((((x) >> 24) & 0x000000ff) | (((x) >> 8) & 0x0000ff00) | (((x) << 8) & 0x00ff0000) | (((x) << 24) & 0xff000000)) +#endif + + #endif // Net_SocketDefs_INCLUDED diff --git a/Net/testsuite/src/IPAddressTest.cpp b/Net/testsuite/src/IPAddressTest.cpp index baceffde6..c76d708a3 100644 --- a/Net/testsuite/src/IPAddressTest.cpp +++ b/Net/testsuite/src/IPAddressTest.cpp @@ -630,6 +630,15 @@ void IPAddressTest::testRelationals6() } +void IPAddressTest::testByteOrderMacros() +{ + Poco::UInt16 a16 = 0xDEAD; + assert (poco_ntoh_16(a16) == ntohs(a16)); + Poco::UInt32 a32 = 0xDEADBEEF; + assert (poco_ntoh_32(a32) == ntohl(a32)); +} + + void IPAddressTest::setUp() { } @@ -658,6 +667,7 @@ CppUnit::Test* IPAddressTest::suite() CppUnit_addTest(pSuite, IPAddressTest, testPrefixCons); CppUnit_addTest(pSuite, IPAddressTest, testPrefixLen); CppUnit_addTest(pSuite, IPAddressTest, testOperators); + CppUnit_addTest(pSuite, IPAddressTest, testByteOrderMacros); return pSuite; } diff --git a/Net/testsuite/src/IPAddressTest.h b/Net/testsuite/src/IPAddressTest.h index d3dde03a9..f8fd675ca 100644 --- a/Net/testsuite/src/IPAddressTest.h +++ b/Net/testsuite/src/IPAddressTest.h @@ -60,7 +60,8 @@ public: void testPrefixCons(); void testPrefixLen(); void testOperators(); - + void testByteOrderMacros(); + void setUp(); void tearDown();