diff --git a/I2PEndian.cpp b/I2PEndian.cpp index fa4e08cb..1fccf47f 100644 --- a/I2PEndian.cpp +++ b/I2PEndian.cpp @@ -1,81 +1,81 @@ -//#include "I2PEndian.h" -// -//// http://habrahabr.ru/post/121811/ -//// http://codepad.org/2ycmkz2y -// -//#include "LittleBigEndian.h" -// -//uint16_t htobe16(uint16_t int16) -//{ -// BigEndian u16(int16); -// return u16.raw_value; -//} -// -//uint32_t htobe32(uint32_t int32) -//{ -// BigEndian u32(int32); -// return u32.raw_value; -//} -// -//uint64_t htobe64(uint64_t int64) -//{ -// BigEndian u64(int64); -// return u64.raw_value; -//} -// -//uint16_t be16toh(uint16_t big16) -//{ -// LittleEndian u16(big16); -// return u16.raw_value; -//} -// -//uint32_t be32toh(uint32_t big32) -//{ -// LittleEndian u32(big32); -// return u32.raw_value; -//} -// -//uint64_t be64toh(uint64_t big64) -//{ -// LittleEndian u64(big64); -// return u64.raw_value; -//} -// -///* it can be used in Windows 8 -//#include -// -//uint16_t htobe16(uint16_t int16) -//{ -// return htons(int16); -//} -// -//uint32_t htobe32(uint32_t int32) -//{ -// return htonl(int32); -//} -// -//uint64_t htobe64(uint64_t int64) -//{ -// // http://msdn.microsoft.com/en-us/library/windows/desktop/jj710199%28v=vs.85%29.aspx -// //return htonll(int64); -// return 0; -//} -// -// -//uint16_t be16toh(uint16_t big16) -//{ -// return ntohs(big16); -//} -// -//uint32_t be32toh(uint32_t big32) -//{ -// return ntohl(big32); -//} -// -//uint64_t be64toh(uint64_t big64) -//{ -// // http://msdn.microsoft.com/en-us/library/windows/desktop/jj710199%28v=vs.85%29.aspx -// //return ntohll(big64); -// return 0; -//} -//*/ \ No newline at end of file +#include "I2PEndian.h" + +// http://habrahabr.ru/post/121811/ +// http://codepad.org/2ycmkz2y + +#include "LittleBigEndian.h" + +uint16_t htobe16(uint16_t int16) +{ + BigEndian u16(int16); + return u16.raw_value; +} + +uint32_t htobe32(uint32_t int32) +{ + BigEndian u32(int32); + return u32.raw_value; +} + +uint64_t htobe64(uint64_t int64) +{ + BigEndian u64(int64); + return u64.raw_value; +} + +uint16_t be16toh(uint16_t big16) +{ + LittleEndian u16(big16); + return u16.raw_value; +} + +uint32_t be32toh(uint32_t big32) +{ + LittleEndian u32(big32); + return u32.raw_value; +} + +uint64_t be64toh(uint64_t big64) +{ + LittleEndian u64(big64); + return u64.raw_value; +} + +/* it can be used in Windows 8 +#include + +uint16_t htobe16(uint16_t int16) +{ + return htons(int16); +} + +uint32_t htobe32(uint32_t int32) +{ + return htonl(int32); +} + +uint64_t htobe64(uint64_t int64) +{ + // http://msdn.microsoft.com/en-us/library/windows/desktop/jj710199%28v=vs.85%29.aspx + //return htonll(int64); + return 0; +} + + +uint16_t be16toh(uint16_t big16) +{ + return ntohs(big16); +} + +uint32_t be32toh(uint32_t big32) +{ + return ntohl(big32); +} + +uint64_t be64toh(uint64_t big64) +{ + // http://msdn.microsoft.com/en-us/library/windows/desktop/jj710199%28v=vs.85%29.aspx + //return ntohll(big64); + return 0; +} +*/ \ No newline at end of file diff --git a/I2PEndian.h b/I2PEndian.h index 3014f564..01ba73e8 100644 --- a/I2PEndian.h +++ b/I2PEndian.h @@ -5,16 +5,14 @@ #include #else #include -// -//uint16_t htobe16(uint16_t int16); -//uint32_t htobe32(uint32_t int32); -//uint64_t htobe64(uint64_t int64); -// -//uint16_t be16toh(uint16_t big16); -//uint32_t be32toh(uint32_t big32); -//uint64_t be64toh(uint64_t big64); -#include "portable_endian.h" +uint16_t htobe16(uint16_t int16); +uint32_t htobe32(uint32_t int32); +uint64_t htobe64(uint64_t int64); + +uint16_t be16toh(uint16_t big16); +uint32_t be32toh(uint32_t big32); +uint64_t be64toh(uint64_t big64); #endif diff --git a/LittleBigEndian.h b/LittleBigEndian.h index ea879729..69f10ee9 100644 --- a/LittleBigEndian.h +++ b/LittleBigEndian.h @@ -59,12 +59,12 @@ struct LittleEndian return t; } - const T operator = (const T t) - { - for (unsigned i = 0; i < sizeof(T); i++) - bytes[i] = t >> (i << 3); - return t; - } + const T operator = (const T t) + { + for (unsigned i = 0; i < sizeof(T); i++) + bytes[sizeof(T)-1 - i] = static_cast(t >> (i << 3)); + return t; + } // operators diff --git a/Streaming.cpp b/Streaming.cpp index c7cd9ad3..05f838fa 100644 --- a/Streaming.cpp +++ b/Streaming.cpp @@ -2,7 +2,6 @@ #include #include #include "Log.h" -#include "I2PEndian.h" #include "RouterInfo.h" #include "RouterContext.h" #include "Tunnel.h" diff --git a/i2p.cpp b/i2p.cpp index 6636c2b6..24341fe7 100644 --- a/i2p.cpp +++ b/i2p.cpp @@ -1,3 +1,7 @@ +#ifdef _WIN32 +#define _CRT_SECURE_NO_WARNINGS // to use freopen +#endif + #include #include #include diff --git a/portable_endian.h b/portable_endian.h deleted file mode 100644 index 3355d2b9..00000000 --- a/portable_endian.h +++ /dev/null @@ -1,115 +0,0 @@ -#ifndef PORTABLE_ENDIAN_H__ -#define PORTABLE_ENDIAN_H__ - -#if (defined(_WIN16) || defined(_WIN32) || defined(_WIN64)) && !defined(__WINDOWS__) - -# define __WINDOWS__ - -#endif - -#if defined(__linux__) || defined(__CYGWIN__) - -# include - -#elif defined(__APPLE__) - -# include - -# define htobe16 OSSwapHostToBigInt16 -# define htole16 OSSwapHostToLittleInt16 -# define be16toh OSSwapBigToHostInt16 -# define le16toh OSSwapLittleToHostInt16 - -# define htobe32 OSSwapHostToBigInt32 -# define htole32 OSSwapHostToLittleInt32 -# define be32toh OSSwapBigToHostInt32 -# define le32toh OSSwapLittleToHostInt32 - -# define htobe64 OSSwapHostToBigInt64 -# define htole64 OSSwapHostToLittleInt64 -# define be64toh OSSwapBigToHostInt64 -# define le64toh OSSwapLittleToHostInt64 - -# define __BYTE_ORDER BYTE_ORDER -# define __BIG_ENDIAN BIG_ENDIAN -# define __LITTLE_ENDIAN LITTLE_ENDIAN -# define __PDP_ENDIAN PDP_ENDIAN - -#elif defined(__OpenBSD__) - -# include - -#elif defined(__NetBSD__) || defined(__FreeBSD__) || defined(__DragonFly__) - -# include - -# define be16toh betoh16 -# define le16toh letoh16 - -# define be32toh betoh32 -# define le32toh letoh32 - -# define be64toh betoh64 -# define le64toh letoh64 - -#elif defined(__WINDOWS__) - -#define INCL_EXTRA_HTON_FUNCTIONS -#define NOMINMAX -# include -#undef NOMINMAX -//# include - -# if BYTE_ORDER == LITTLE_ENDIAN - -# define htobe16 htons -# define htole16(x) (x) -# define be16toh ntohs -# define le16toh(x) (x) - -# define htobe32 htonl -# define htole32(x) (x) -# define be32toh ntohl -# define le32toh(x) (x) - -# define htobe64 htonll -# define htole64(x) (x) -# define be64toh ntohll -# define le64toh(x) (x) - -# elif BYTE_ORDER == BIG_ENDIAN - - /* that would be xbox 360 */ -# define htobe16(x) (x) -# define htole16(x) __builtin_bswap16(x) -# define be16toh(x) (x) -# define le16toh(x) __builtin_bswap16(x) - -# define htobe32(x) (x) -# define htole32(x) __builtin_bswap32(x) -# define be32toh(x) (x) -# define le32toh(x) __builtin_bswap32(x) - -# define htobe64(x) (x) -# define htole64(x) __builtin_bswap64(x) -# define be64toh(x) (x) -# define le64toh(x) __builtin_bswap64(x) - -# else - -# error byte order not supported - -# endif - -# define __BYTE_ORDER BYTE_ORDER -# define __BIG_ENDIAN BIG_ENDIAN -# define __LITTLE_ENDIAN LITTLE_ENDIAN -# define __PDP_ENDIAN PDP_ENDIAN - -#else - -# error platform not supported - -#endif - -#endif \ No newline at end of file