summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJérémie Courrèges-Anglas <jca@wxcvbn.org>2013-04-16 11:11:45 +0200
committerJérémie Courrèges-Anglas <jca@wxcvbn.org>2013-04-16 11:11:45 +0200
commit9314ea18fab323f3b981a412d7a765f66abfaab3 (patch)
tree70c8801828f4eb11a8686645d90c52e092b8782d
parent24b078a5a126fc7c7c207747d5f2e20022264e9f (diff)
use betoh64 if be64toh not found
Instead of looking for htobe64 which is be available both when be64toh or betoh64 are, check for the latter functions. If we find betoh64 but not be64toh, use compat #defines. If both can't be found, search for OSX' OSSwapHostToBigInt64. Also include sys/types.h in byteorder.h (which is necessary for byteorder functions on OpenBSD), and incidentally fixes build of networkfragment.cc. Fixes build on OpenBSD Signed-off-by: Jérémie Courrèges-Anglas <jca@wxcvbn.org>
-rw-r--r--configure.ac18
-rw-r--r--src/crypto/byteorder.h9
2 files changed, 18 insertions, 9 deletions
diff --git a/configure.ac b/configure.ac
index 11153ea..b07291a 100644
--- a/configure.ac
+++ b/configure.ac
@@ -285,20 +285,22 @@ AC_CHECK_DECL([mach_absolute_time],
[Define if mach_absolute_time is available.])],
, [[#include <mach/mach_time.h>]])
-AC_CHECK_DECL([htobe64],
- [AC_DEFINE([HAVE_HTOBE64], [1],
- [Define if htobe64 and friends exist.])],
- [AC_CHECK_DECL([OSSwapHostToBigInt64],
- [AC_DEFINE([HAVE_OSX_SWAP], [1],
- [Define if OSSwapHostToBigInt64 and friends exist.])],
- [AC_MSG_WARN([Unable to find byte swapping functions; using built-in routines.])],
- [[#include <libkern/OSByteOrder.h>]])],
+AC_CHECK_DECLS([be64toh, betoh64], [], [],
[[#if defined(HAVE_ENDIAN_H)
#include <endian.h>
#elif defined(HAVE_SYS_ENDIAN_H)
+#include <sys/types.h>
#include <sys/endian.h>
#endif]])
+AS_IF([test x"$ac_cv_have_decl_be64toh" != xyes &&
+ test x"$ac_cv_have_decl_betoh64" != xyes],
+ [AC_CHECK_DECL([OSSwapHostToBigInt64],
+ [AC_DEFINE([HAVE_OSX_SWAP], [1],
+ [Define if OSSwapHostToBigInt64 and friends exist.])],
+ [AC_MSG_WARN([Unable to find byte swapping functions; using built-in routines.])],
+ [[#include <libkern/OSByteOrder.h>]])])
+
AC_CHECK_DECL([IP_MTU_DISCOVER],
[AC_DEFINE([HAVE_IP_MTU_DISCOVER], [1],
[Define if IP_MTU_DISCOVER is a valid sockopt.])],
diff --git a/src/crypto/byteorder.h b/src/crypto/byteorder.h
index a5f0a47..e5f9baa 100644
--- a/src/crypto/byteorder.h
+++ b/src/crypto/byteorder.h
@@ -35,13 +35,20 @@
#include "config.h"
-#ifdef HAVE_HTOBE64
+#if HAVE_DECL_BE64TOH || HAVE_DECL_BETOH64
+
# if defined(HAVE_ENDIAN_H)
# include <endian.h>
# elif defined(HAVE_SYS_ENDIAN_H)
+# include <sys/types.h>
# include <sys/endian.h>
# endif
+#if !HAVE_DECL_BE64TOH && HAVE_DECL_BETOH64
+#define be64toh betoh64
+#define be16toh betoh16
+#endif
+
#elif HAVE_OSX_SWAP
# include <libkern/OSByteOrder.h>
# define htobe64 OSSwapHostToBigInt64