diff --git a/configure.ac b/configure.ac index d3a19505af..c09e5328fd 100644 --- a/configure.ac +++ b/configure.ac @@ -753,7 +753,32 @@ OMPI_CHECK_FUNC_LIB([dirname], [gen]) # Darwin doesn't need -lm, as it's a symlink to libSystem.dylib OMPI_CHECK_FUNC_LIB([ceil], [m]) -AC_CHECK_FUNCS([asprintf snprintf vasprintf vsnprintf openpty isatty htonl ntohl htons ntohs getpwuid fork waitpid execve pipe ptsname setsid mmap mallopt tcgetpgrp posix_memalign strsignal sysconf syslog regcmp regexec regfree _NSGetEnviron socketpair strncpy_s _strdup usleep mkfifo]) +AC_CHECK_FUNCS([asprintf snprintf vasprintf vsnprintf openpty isatty getpwuid fork waitpid execve pipe ptsname setsid mmap mallopt tcgetpgrp posix_memalign strsignal sysconf syslog regcmp regexec regfree _NSGetEnviron socketpair strncpy_s _strdup usleep mkfifo]) + +# On some hosts, htonl is a define, so the AC_CHECK_FUNC will get +# confused. On others, it's in the standard library, but stubbed with +# the magic glibc foo as not implemented. and on other systems, it's +# just not there. This covers all cases. +AC_CACHE_CHECK([for htonl define], + [ompi_cv_htonl_define], + [AC_PREPROC_IFELSE([AC_LANG_PROGRAM([ +#ifdef HAVE_SYS_TYPES_H +#include +#endif +#ifdef HAVE_NETINET_IN_H +#include +#endif +#ifdef HAVE_ARPA_INET_H +#include +#endif],[ +#ifndef ntohl +#error "ntohl not defined" +#endif +])], [ompi_cv_htonl_define=yes], [ompi_cv_htonl_define=no])]) +AC_CHECK_FUNC([htonl], [ompi_have_htonl=yes], [ompi_have_htonl=no]) +AS_IF([test "$ompi_cv_htonl_define" = "yes" -o "$ompi_have_htonl" = "yes"], + [AC_DEFINE_UNQUOTED([HAVE_UNIX_BYTESWAP], [1], + [whether unix byteswap routines -- htonl, htons, nothl, ntohs -- are available])]) # # Make sure we can copy va_lists (need check declared, not linkable) diff --git a/opal/include/opal/types.h b/opal/include/opal/types.h index a1050e84a4..e1080e8c34 100644 --- a/opal/include/opal/types.h +++ b/opal/include/opal/types.h @@ -80,7 +80,7 @@ typedef int opal_socklen_t; static inline uint64_t hton64(uint64_t val) __opal_attribute_const__; static inline uint64_t hton64(uint64_t val) { -#ifdef HAVE_HTONL +#ifdef HAVE_UNIX_BYTESWAP union { uint64_t ll; uint32_t l[2]; } w, r; @@ -104,7 +104,7 @@ static inline uint64_t hton64(uint64_t val) static inline uint64_t ntoh64(uint64_t val) __opal_attribute_const__; static inline uint64_t ntoh64(uint64_t val) { -#ifdef HAVE_NTOHL +#ifdef HAVE_UNIX_BYTESWAP union { uint64_t ll; uint32_t l[2]; } w, r; @@ -142,7 +142,7 @@ static inline void* ompi_ptr_ltop( uint64_t value ) return (void*)(uintptr_t) value; } -#if defined(WORDS_BIGENDIAN) || !defined(HAVE_HTONS) || !defined(HAVE_HTONL) +#if defined(WORDS_BIGENDIAN) || !defined(HAVE_UNIX_BYTESWAP) static inline uint16_t opal_swap_bytes2(uint16_t val) __opal_attribute_const__; static inline uint16_t opal_swap_bytes2(uint16_t val) { @@ -197,6 +197,6 @@ static inline uint64_t opal_swap_bytes8(uint64_t val) #define opal_swap_bytes2 htons #define opal_swap_bytes4 htonl #define opal_swap_bytes8 hton64 -#endif /* WORDS_BIGENDIAN || !HAVE_HTONS || !HAVE_HTONL */ +#endif /* WORDS_BIGENDIAN || !HAVE_UNIX_BYTESWAP */ #endif /* OPAL_TYPES_H */ diff --git a/opal/include/opal_config_bottom.h b/opal/include/opal_config_bottom.h index 47dc98b93e..285736298d 100644 --- a/opal/include/opal_config_bottom.h +++ b/opal/include/opal_config_bottom.h @@ -428,20 +428,12 @@ typedef long long bool; * and would want to talk to the outside world... On other platforms * (like Windows) we fail to detect them correctly. */ -#ifndef __WINDOWS__ -#ifndef HAVE_HTONL +#if !defined(__WINDOWS__) && !defined(HAVE_UNIX_BYTESWAP) static inline uint32_t htonl(uint32_t hostvar) { return hostvar; } -#endif -#ifndef HAVE_NTOHL static inline uint32_t ntohl(uint32_t netvar) { return netvar; } -#endif -#ifndef HAVE_HTONS static inline uint16_t htons(uint16_t hostvar) { return hostvar; } -#endif -#ifndef HAVE_NTOHS static inline uint16_t ntohs(uint16_t netvar) { return netvar; } #endif -#endif /* WINDOWS */ /* * Define __func__-preprocessor directive if the compiler does not