diff --git a/websocketpp/common/network.hpp b/websocketpp/common/network.hpp index dbe455151e..fcbb6a214f 100644 --- a/websocketpp/common/network.hpp +++ b/websocketpp/common/network.hpp @@ -40,6 +40,12 @@ namespace websocketpp { namespace lib { namespace net { +inline bool is_little_endian() { + short int val = 0x1; + char *ptr = (char*)&val; + return (ptr[0] == 1); +} + #define TYP_INIT 0 #define TYP_SMLE 1 #define TYP_BIGE 2 @@ -56,7 +62,7 @@ inline uint64_t htonll(uint64_t src) { typ = (x.c[7] == 0x01ULL) ? TYP_BIGE : TYP_SMLE; } if (typ == TYP_BIGE) - return src; + return src; x.ull = src; c = x.c[0]; x.c[0] = x.c[7]; x.c[7] = c; c = x.c[1]; x.c[1] = x.c[6]; x.c[6] = c; diff --git a/websocketpp/frame.hpp b/websocketpp/frame.hpp index 0ab8976e50..f8e0d06037 100644 --- a/websocketpp/frame.hpp +++ b/websocketpp/frame.hpp @@ -590,8 +590,13 @@ inline size_t prepare_masking_key(const masking_key_type& key) { * to zero and less than sizeof(size_t). */ inline size_t circshift_prepared_key(size_t prepared_key, size_t offset) { - size_t temp = prepared_key << (sizeof(size_t)-offset)*8; - return (prepared_key >> offset*8) | temp; + if (lib::net::is_little_endian()) { + size_t temp = prepared_key << (sizeof(size_t)-offset)*8; + return (prepared_key >> offset*8) | temp; + } else { + size_t temp = prepared_key >> (sizeof(size_t)-offset)*8; + return (prepared_key << offset*8) | temp; + } } /// Byte by byte mask/unmask