From 13f4a96d93f0b039aaf47c5f4103002d836828d5 Mon Sep 17 00:00:00 2001 From: "John \"Elwin\" Edwards" Date: Thu, 13 Aug 2015 17:17:40 -0400 Subject: [PATCH] XRogue: fix md_htonl() and md_ntohl(). xcrypt requires them. The implementations in state.c used htonl() and ntohl(), which aren't available on Windows. So the Advanced Rogue 7 versions were copied over. This implementation could be problematic on other systems where sizeof(long) == 8. Maybe someday I can convert everything to C99 and use stdint.h. --- xrogue/state.c | 37 ++++++++++++++++++++++++++++--------- xrogue/xcrypt.c | 3 +++ 2 files changed, 31 insertions(+), 9 deletions(-) diff --git a/xrogue/state.c b/xrogue/state.c index 5e2801e..d30d73b 100644 --- a/xrogue/state.c +++ b/xrogue/state.c @@ -3327,18 +3327,38 @@ md_killchar() return(killchar()); } -long -md_ntohl(netlong) -long netlong; +int md_endian = 0x01020304; + +unsigned long int +md_ntohl(unsigned long int x) { - return( ntohl(netlong) ); +#ifdef _WIN32 + if ( *((char *)&md_endian) == 0x01 ) + return(x); + else + return( ((x & 0x000000ffU) << 24) | + ((x & 0x0000ff00U) << 8) | + ((x & 0x00ff0000U) >> 8) | + ((x & 0xff000000U) >> 24) ); +#else + return( ntohl(x) ); +#endif } -long -md_htonl(netlong) -long netlong; +unsigned long int +md_htonl(unsigned long int x) { - return(htonl(netlong)); +#ifdef _WIN32 + if ( *((char *)&md_endian) == 0x01 ) + return(x); + else + return( ((x & 0x000000ffU) << 24) | + ((x & 0x0000ff00U) << 8) | + ((x & 0x00ff0000U) >> 8) | + ((x & 0xff000000U) >> 24) ); +#else + return( htonl(x) ); +#endif } void @@ -3493,4 +3513,3 @@ md_unlink(char *file) return(unlink(file)); #endif } - diff --git a/xrogue/xcrypt.c b/xrogue/xcrypt.c index 8214747..a65c6f9 100644 --- a/xrogue/xcrypt.c +++ b/xrogue/xcrypt.c @@ -54,6 +54,9 @@ #define _PASSWORD_EFMT1 '_' +unsigned long int md_htonl(unsigned long int x); +unsigned long int md_ntohl(unsigned long int x); + static unsigned char IP[64] = { 58, 50, 42, 34, 26, 18, 10, 2, 60, 52, 44, 36, 28, 20, 12, 4, 62, 54, 46, 38, 30, 22, 14, 6, 64, 56, 48, 40, 32, 24, 16, 8,