diff --git a/CMakeLists.txt b/CMakeLists.txt index 8814844..61b79c4 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -122,8 +122,10 @@ if(LIBGCRYPT_LIBRARIES) endif(LIBGCRYPT_LIBRARIES) +check_include_file("endian.h" LIBVNCSERVER_HAVE_ENDIAN_H) check_include_file("fcntl.h" LIBVNCSERVER_HAVE_FCNTL_H) check_include_file("netinet/in.h" LIBVNCSERVER_HAVE_NETINET_IN_H) +check_include_file("sys/endian.h" LIBVNCSERVER_HAVE_SYS_ENDIAN_H) check_include_file("sys/socket.h" LIBVNCSERVER_HAVE_SYS_SOCKET_H) check_include_file("sys/stat.h" LIBVNCSERVER_HAVE_SYS_STAT_H) check_include_file("sys/time.h" LIBVNCSERVER_HAVE_SYS_TIME_H) diff --git a/configure.ac b/configure.ac index 773d29a..3c8e3b7 100644 --- a/configure.ac +++ b/configure.ac @@ -885,7 +885,7 @@ fi # Checks for header files. AC_HEADER_STDC -AC_CHECK_HEADERS([arpa/inet.h fcntl.h netdb.h netinet/in.h stdlib.h string.h sys/socket.h sys/time.h sys/timeb.h syslog.h unistd.h ws2tcpip.h]) +AC_CHECK_HEADERS([arpa/inet.h endian.h fcntl.h netdb.h netinet/in.h stdlib.h string.h sys/endian.h sys/socket.h sys/time.h sys/timeb.h syslog.h unistd.h ws2tcpip.h]) # x11vnc only: if test "$build_x11vnc" = "yes"; then diff --git a/libvncserver/websockets.c b/libvncserver/websockets.c index 043e6cb..b8de5cd 100644 --- a/libvncserver/websockets.c +++ b/libvncserver/websockets.c @@ -35,25 +35,22 @@ /* errno */ #include -#include +#ifdef LIBVNCSERVER_HAVE_ENDIAN_H +#include +#elif LIBVNCSERVER_HAVE_SYS_ENDIAN_H +#include +#endif + #include #include "rfb/rfbconfig.h" #include "rfbssl.h" #include "rfbcrypto.h" -#if defined(__BYTE_ORDER) && defined(__BIG_ENDIAN) && __BYTE_ORDER == __BIG_ENDIAN -#define WS_NTOH64(n) (n) -#define WS_NTOH32(n) (n) -#define WS_NTOH16(n) (n) -#define WS_HTON64(n) (n) -#define WS_HTON16(n) (n) -#else -#define WS_NTOH64(n) bswap_64(n) -#define WS_NTOH32(n) bswap_32(n) -#define WS_NTOH16(n) bswap_16(n) -#define WS_HTON64(n) bswap_64(n) -#define WS_HTON16(n) bswap_16(n) -#endif +#define WS_NTOH64(n) htobe64(n) +#define WS_NTOH32(n) htobe32(n) +#define WS_NTOH16(n) htobe16(n) +#define WS_HTON64(n) htobe64(n) +#define WS_HTON16(n) htobe16(n) #define B64LEN(__x) (((__x + 2) / 3) * 12 / 3) #define WSHLENMAX 14 /* 2 + sizeof(uint64_t) + sizeof(uint32_t) */ diff --git a/rfb/rfbconfig.h.cmake b/rfb/rfbconfig.h.cmake index e973f5b..3e3155b 100644 --- a/rfb/rfbconfig.h.cmake +++ b/rfb/rfbconfig.h.cmake @@ -9,6 +9,9 @@ /* work around when write() returns ENOENT but does not mean it */ #cmakedefine LIBVNCSERVER_ENOENT_WORKAROUND 1 +/* Define to 1 if you have the header file. */ +#cmakedefine LIBVNCSERVER_HAVE_ENDIAN_H 1 + /* Define to 1 if you have the header file. */ #cmakedefine LIBVNCSERVER_HAVE_FCNTL_H 1 @@ -30,6 +33,9 @@ /* Define to 1 if you have the header file. */ #cmakedefine LIBVNCSERVER_HAVE_NETINET_IN_H 1 +/* Define to 1 if you have the header file. */ +#cmakedefine LIBVNCSERVER_HAVE_SYS_ENDIAN_H 1 + /* Define to 1 if you have the header file. */ #cmakedefine LIBVNCSERVER_HAVE_SYS_SOCKET_H 1