diff --git a/configure b/configure index b3d4a89..44081ed 100755 --- a/configure +++ b/configure @@ -12561,6 +12561,7 @@ if test -n "$_ldlib"; then { $as_echo "$as_me:${as_lineno-$LINENO}: result: LD_LIBRARY_PATH: $LD_LIBRARY_PATH" >&5 $as_echo "LD_LIBRARY_PATH: $LD_LIBRARY_PATH" >&6; } fi + { $as_echo "$as_me:${as_lineno-$LINENO}: checking is libsodium compiled correctly" >&5 $as_echo_n "checking is libsodium compiled correctly... " >&6; } if test "$cross_compiling" = yes; then : @@ -12602,6 +12603,52 @@ rm -f core *.core core.conftest.* gmon.out bb.out conftest$ac_exeext \ fi + +# check endianess +# program returns 0 on little and 1 on big endian systems +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking are we on a big endian system" >&5 +$as_echo_n "checking are we on a big endian system... " >&6; } +if test "$cross_compiling" = yes; then : + { { $as_echo "$as_me:${as_lineno-$LINENO}: error: in \`$ac_pwd':" >&5 +$as_echo "$as_me: error: in \`$ac_pwd':" >&2;} +as_fn_error $? "cannot run test program while cross compiling +See \`config.log' for more details" "$LINENO" 5; } +else + cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ + + +int +main () +{ +long one= 1; exit(!(*((char *)(&one)))); + ; + return 0; +} +_ACEOF +if ac_fn_c_try_run "$LINENO"; then : + + { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 +$as_echo "no" >&6; } + bigendian="" + +else + + { $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5 +$as_echo "yes" >&6; } + bigendian=1 + + +fi +rm -f core *.core core.conftest.* gmon.out bb.out conftest$ac_exeext \ + conftest.$ac_objext conftest.beam conftest.$ac_ext +fi + + +if test -n "$bigendian"; then + CFLAGS="$CFLAGS -D__BYTE_ORDER=__BIG_ENDIAN" +fi + # Specify output files ac_config_files="$ac_config_files Makefile libpcp/Makefile src/Makefile man/Makefile tests/Makefile" diff --git a/configure.ac b/configure.ac index 09f0d4a..3ddbf3c 100755 --- a/configure.ac +++ b/configure.ac @@ -173,6 +173,7 @@ if test -n "$_ldlib"; then export LD_LIBRARY_PATH="$LD_LIBRARY_PATH:${_ldlib}" AC_MSG_RESULT([LD_LIBRARY_PATH: $LD_LIBRARY_PATH]) fi + AC_MSG_CHECKING([is libsodium compiled correctly]) AC_RUN_IFELSE([ AC_LANG_PROGRAM([[ @@ -189,6 +190,26 @@ AC_LANG_PROGRAM([[ ] ) + +# check endianess +# program returns 0 on little and 1 on big endian systems +AC_MSG_CHECKING([are we on a big endian system]) +AC_RUN_IFELSE([ +AC_LANG_PROGRAM([[]],[[long one= 1; exit(!(*((char *)(&one)))); ]])], + [ + AC_MSG_RESULT([no]) + bigendian="" + ], + [ + AC_MSG_RESULT([yes]) + bigendian=1 + ] +) + +if test -n "$bigendian"; then + CFLAGS="$CFLAGS -D__BYTE_ORDER=__BIG_ENDIAN" +fi + # Specify output files AC_CONFIG_FILES([Makefile libpcp/Makefile src/Makefile man/Makefile tests/Makefile]) AC_OUTPUT diff --git a/include/pcp.h b/include/pcp.h index b2f1c1f..e695e88 100644 --- a/include/pcp.h +++ b/include/pcp.h @@ -5,7 +5,6 @@ extern "C" { #endif -#include #include #include #include /* uint32_t */ @@ -19,7 +18,6 @@ extern "C" { #include #include /* memcmp,strlen */ #include -#include #include #include #include @@ -341,26 +339,33 @@ void pcp_pad_remove(unsigned char **unpadded, unsigned char *padded, #endif #ifdef HAVE_ENDIAN_H -#else -#ifdef HAVE_SYS_ENDIAN_H -#else -#ifdef HAVE_BETOH32 -// openbsd, use aliases -#define be32toh betoh32 -#define htobe32 hto32be -#else - -#if __BYTE_ORDER == __BIG_ENDIAN -// Copyright (c) 1999 Joseph Samuel Myers. bsd-games -#define be32toh(x) ((void)0) -#define htobe32(x) ((void)0) -#else -#define be32toh(x) ((u_int32_t)ntohl((u_int32_t)(x))) -#define htobe32(x) ((u_int32_t)htonl((u_int32_t)(x))) -#endif - -#endif // HAVE_BETOH32 -#endif // HAVE_SYS_ENDIAN_H +# include +#else // no endian.h +# ifdef HAVE_SYS_ENDIAN_H +# include +# ifdef HAVE_BETOH32 + // openbsd, use aliases +# define be32toh betoh32 +# define htobe32 hto32be +# endif +# else // no sys/endian.h +# if __BYTE_ORDER == __BIG_ENDIAN +# define be32toh(x) ((void)0) +# define htobe32(x) ((void)0) +# else +# ifdef HAVE_ARPA_INET_H +# include +# else +# ifdef HAVE_NETINET_IN_H +# include +# else +# error Need either netinet/in.h or arpa/inet.h for ntohl() and htonl() +# endif +# endif +# define be32toh(x) ((u_int32_t)ntohl((u_int32_t)(x))) +# define htobe32(x) ((u_int32_t)htonl((u_int32_t)(x))) +# endif +# endif // HAVE_SYS_ENDIAN_H #endif // HAVE_ENDIAN_H diff --git a/libpcp/platform.h b/libpcp/platform.h index d813131..f0eaf58 100644 --- a/libpcp/platform.h +++ b/libpcp/platform.h @@ -10,28 +10,33 @@ #endif #ifdef HAVE_ENDIAN_H -#include -#else -#ifdef HAVE_SYS_ENDIAN_H -#include -#else -#ifdef HAVE_BETOH32 -// openbsd, use aliases -#define be32toh betoh32 -#define htobe32 hto32be -#else - -#if __BYTE_ORDER == __BIG_ENDIAN -// Copyright (c) 1999 Joseph Samuel Myers. bsd-games -#define be32toh(x) ((void)0) -#define htobe32(x) ((void)0) -#else -#define be32toh(x) ((u_int32_t)ntohl((u_int32_t)(x))) -#define htobe32(x) ((u_int32_t)htonl((u_int32_t)(x))) -#endif - -#endif // HAVE_BETOH32 -#endif // HAVE_SYS_ENDIAN_H +# include +#else // no endian.h +# ifdef HAVE_SYS_ENDIAN_H +# include +# ifdef HAVE_BETOH32 + // openbsd, use aliases +# define be32toh betoh32 +# define htobe32 hto32be +# endif +# else // no sys/endian.h +# if __BYTE_ORDER == __BIG_ENDIAN +# define be32toh(x) ((void)0) +# define htobe32(x) ((void)0) +# else +# ifdef HAVE_ARPA_INET_H +# include +# else +# ifdef HAVE_NETINET_IN_H +# include +# else +# error Need either netinet/in.h or arpa/inet.h for ntohl() and htonl() +# endif +# endif +# define be32toh(x) ((u_int32_t)ntohl((u_int32_t)(x))) +# define htobe32(x) ((u_int32_t)htonl((u_int32_t)(x))) +# endif +# endif // HAVE_SYS_ENDIAN_H #endif // HAVE_ENDIAN_H