diff --git a/modules/ripple_basics/memory/ripple_ByteOrder.cpp b/modules/ripple_basics/memory/ripple_ByteOrder.cpp new file mode 100644 index 0000000000..0b3c627a59 --- /dev/null +++ b/modules/ripple_basics/memory/ripple_ByteOrder.cpp @@ -0,0 +1,41 @@ +#ifdef WIN32 + +//#include +// from: http://stackoverflow.com/questions/3022552/is-there-any-standard-htonl-like-function-for-64-bits-integers-in-c +// but we don't need to check the endianness +uint64_t htobe64(uint64_t value) +{ + // The answer is 42 + //static const int num = 42; + + // Check the endianness + //if (*reinterpret_cast(&num) == num) + //{ + const uint32_t high_part = htonl(static_cast(value >> 32)); + const uint32_t low_part = htonl(static_cast(value & 0xFFFFFFFFLL)); + + return (static_cast(low_part) << 32) | high_part; + //} else + //{ + // return value; + //} +} + +uint64_t be64toh(uint64_t value) +{ + return(_byteswap_uint64(value)); +} + +uint32_t htobe32(uint32_t value) +{ + return(htonl(value)); +} + +uint32_t be32toh(uint32_t value) +{ + return( _byteswap_ulong(value)); +} + +#endif + +// vim:ts=4 diff --git a/modules/ripple_basics/memory/ripple_ByteOrder.h b/modules/ripple_basics/memory/ripple_ByteOrder.h new file mode 100644 index 0000000000..09341cb931 --- /dev/null +++ b/modules/ripple_basics/memory/ripple_ByteOrder.h @@ -0,0 +1,46 @@ +#ifndef RIPPLE_BYTEORDER_H +#define RIPPLE_BYTEORDER_H + +// Routines for converting endianness + +// Reference: http://www.mail-archive.com/licq-commits@googlegroups.com/msg02334.html + +// VFALCO: TODO, use VFLIB_* platform macros instead of hard-coded compiler specific ones +#ifdef WIN32 +extern uint64_t htobe64(uint64_t value); +extern uint64_t be64toh(uint64_t value); +extern uint32_t htobe32(uint32_t value); +extern uint32_t be32toh(uint32_t value); + +#elif __APPLE__ +#include + +#define htobe16(x) OSSwapHostToBigInt16(x) +#define htole16(x) OSSwapHostToLittleInt16(x) +#define be16toh(x) OSSwapBigToHostInt16(x) +#define le16toh(x) OSSwapLittleToHostInt16(x) + +#define htobe32(x) OSSwapHostToBigInt32(x) +#define htole32(x) OSSwapHostToLittleInt32(x) +#define be32toh(x) OSSwapBigToHostInt32(x) +#define le32toh(x) OSSwapLittleToHostInt32(x) + +#define htobe64(x) OSSwapHostToBigInt64(x) +#define htole64(x) OSSwapHostToLittleInt64(x) +#define be64toh(x) OSSwapBigToHostInt64(x) +#define le64toh(x) OSSwapLittleToHostInt64(x) + +#elif defined(__FreeBSD__) || defined(__NetBSD__) +#include + +#elif defined(__OpenBSD__) +#include +#define be16toh(x) betoh16(x) +#define be32toh(x) betoh32(x) +#define be64toh(x) betoh64(x) + +#endif + +#endif + +// vim:ts=4 diff --git a/modules/ripple_basics/ripple_basics.cpp b/modules/ripple_basics/ripple_basics.cpp index e0904ecf06..88a9a576b3 100644 --- a/modules/ripple_basics/ripple_basics.cpp +++ b/modules/ripple_basics/ripple_basics.cpp @@ -44,6 +44,12 @@ #include "events/ripple_UptimeTimer.cpp" +#ifdef WIN32 +// Winsock #defines 'max' and does other stupid things so put it last +#include "Winsock2.h" // for ripple_ByteOrder.cpp +#endif +#include "memory/ripple_ByteOrder.cpp" + #ifdef _MSC_VER //#pragma warning (pop) #endif diff --git a/modules/ripple_basics/ripple_basics.h b/modules/ripple_basics/ripple_basics.h index 8ecce394ae..2954f076e4 100644 --- a/modules/ripple_basics/ripple_basics.h +++ b/modules/ripple_basics/ripple_basics.h @@ -68,6 +68,17 @@ namespace boost { #include #include +// ByteOrder +#ifdef WIN32 + // (nothing) +#elif __APPLE__ +# include +#elif defined(__FreeBSD__) || defined(__NetBSD__) +# include +#elif defined(__OpenBSD__) +# include +#endif + #include "../ripple_json/ripple_json.h" @@ -81,6 +92,8 @@ namespace boost { #include "containers/ripple_SecureAllocator.h" #include "containers/ripple_TaggedCache.h" +#include "memory/ripple_ByteOrder.h" + #include "events/ripple_UptimeTimer.h" #endif diff --git a/newcoin.vcxproj b/newcoin.vcxproj index 8258dd1e08..a431b7352f 100644 --- a/newcoin.vcxproj +++ b/newcoin.vcxproj @@ -197,6 +197,12 @@ true true + + true + true + true + true + @@ -1181,6 +1187,7 @@ + diff --git a/newcoin.vcxproj.filters b/newcoin.vcxproj.filters index d2fd3b7611..c741c72669 100644 --- a/newcoin.vcxproj.filters +++ b/newcoin.vcxproj.filters @@ -133,6 +133,9 @@ {1194480b-fa6b-4d92-8656-2470f45f2753} + + {49faa808-02f3-44ba-a17c-43dce213672e} + @@ -753,6 +756,9 @@ 1. Modules\ripple_basics\containers + + 1. Modules\ripple_basics\memory + @@ -1400,6 +1406,9 @@ 1. Modules\ripple_basics\containers + + 1. Modules\ripple_basics\memory + diff --git a/src/cpp/ripple/utils.cpp b/src/cpp/ripple/utils.cpp index de771bc7b9..c1b712cc4c 100644 --- a/src/cpp/ripple/utils.cpp +++ b/src/cpp/ripple/utils.cpp @@ -344,46 +344,6 @@ int strIPtoInt(std::string& ipStr) } */ -#ifdef WIN32 - -//#include "Winsock2.h" -//#include -// from: http://stackoverflow.com/questions/3022552/is-there-any-standard-htonl-like-function-for-64-bits-integers-in-c -// but we don't need to check the endianness -uint64_t htobe64(uint64_t value) -{ - // The answer is 42 - //static const int num = 42; - - // Check the endianness - //if (*reinterpret_cast(&num) == num) - //{ - const uint32_t high_part = htonl(static_cast(value >> 32)); - const uint32_t low_part = htonl(static_cast(value & 0xFFFFFFFFLL)); - - return (static_cast(low_part) << 32) | high_part; - //} else - //{ - // return value; - //} -} - -uint64_t be64toh(uint64_t value) -{ - return(_byteswap_uint64(value)); -} - -uint32_t htobe32(uint32_t value) -{ - return(htonl(value)); -} - -uint32_t be32toh(uint32_t value) -{ - return( _byteswap_ulong(value)); -} - -#endif #ifdef PR_SET_NAME #define HAVE_NAME_THREAD diff --git a/src/cpp/ripple/utils.h b/src/cpp/ripple/utils.h index ab767e6566..fc4c7b9892 100644 --- a/src/cpp/ripple/utils.h +++ b/src/cpp/ripple/utils.h @@ -21,39 +21,6 @@ #define isSetBit(x,y) (!!((x) & (y))) -// maybe use http://www.mail-archive.com/licq-commits@googlegroups.com/msg02334.html -#ifdef WIN32 -extern uint64_t htobe64(uint64_t value); -extern uint64_t be64toh(uint64_t value); -extern uint32_t htobe32(uint32_t value); -extern uint32_t be32toh(uint32_t value); -#elif __APPLE__ -#include - -#define htobe16(x) OSSwapHostToBigInt16(x) -#define htole16(x) OSSwapHostToLittleInt16(x) -#define be16toh(x) OSSwapBigToHostInt16(x) -#define le16toh(x) OSSwapLittleToHostInt16(x) - -#define htobe32(x) OSSwapHostToBigInt32(x) -#define htole32(x) OSSwapHostToLittleInt32(x) -#define be32toh(x) OSSwapBigToHostInt32(x) -#define le32toh(x) OSSwapLittleToHostInt32(x) - -#define htobe64(x) OSSwapHostToBigInt64(x) -#define htole64(x) OSSwapHostToLittleInt64(x) -#define be64toh(x) OSSwapBigToHostInt64(x) -#define le64toh(x) OSSwapLittleToHostInt64(x) -#elif defined(__FreeBSD__) || defined(__NetBSD__) -#include -#elif defined(__OpenBSD__) -#include -#define be16toh(x) betoh16(x) -#define be32toh(x) betoh32(x) -#define be64toh(x) betoh64(x) -#endif - - #define vt_f_black "\033[30m" #define vt_f_red "\033[31m" #define vt_f_green "\033[32m"