From 507af6fc151b69a9b7c243e30387da303c5b83cc Mon Sep 17 00:00:00 2001 From: Michael Jeanson Date: Thu, 15 Oct 2015 12:17:43 -0400 Subject: [PATCH] Port: Add Solaris compat for netdb MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Michael Jeanson Signed-off-by: Jérémie Galarneau --- configure.ac | 6 ++--- src/common/compat/Makefile.am | 2 +- src/common/compat/netdb.h | 44 +++++++++++++++++++++++++++++++++++ src/common/uri.c | 4 ++-- 4 files changed, 50 insertions(+), 6 deletions(-) create mode 100644 src/common/compat/netdb.h diff --git a/configure.ac b/configure.ac index 5d286beb0..c2f49d52d 100644 --- a/configure.ac +++ b/configure.ac @@ -53,6 +53,8 @@ LIBS="$PTHREAD_LIBS $LIBS" CFLAGS="$CFLAGS $PTHREAD_CFLAGS" CC="$PTHREAD_CC" +AX_LIB_SOCKET_NSL + # Compute minor/major/patchlevel version numbers major_version=$(echo AC_PACKAGE_VERSION | $SED 's/^\([[0-9]]\)*\.[[0-9]]*\.[[0-9]]*.*$/\1/') minor_version=$(echo AC_PACKAGE_VERSION | $SED 's/^[[0-9]]*\.\([[0-9]]*\)\.[[0-9]]*.*$/\1/') @@ -111,7 +113,7 @@ AC_CHECK_FUNCS([ \ gethostbyname gethostname getpagesize localtime_r memchr memset \ mkdir munmap putenv realpath rmdir socket strchr strcspn strdup \ strncasecmp strndup strnlen strpbrk strrchr strstr strtol strtoul \ - strtoull dirfd \ + strtoull dirfd gethostbyname2 getipnodebyname \ ]) # Babeltrace viewer check @@ -403,8 +405,6 @@ else fi -AX_LIB_SOCKET_NSL - # Epoll check. If not present, the build will fallback on poll() API AX_HAVE_EPOLL( [AX_CONFIG_FEATURE_ENABLE(epoll)], diff --git a/src/common/compat/Makefile.am b/src/common/compat/Makefile.am index 69e2dc590..865fd7f70 100644 --- a/src/common/compat/Makefile.am +++ b/src/common/compat/Makefile.am @@ -10,4 +10,4 @@ endif libcompat_la_SOURCES = poll.h fcntl.h endian.h mman.h dirent.h \ socket.h compat-fcntl.c uuid.h tid.h \ - getenv.h string.h prctl.h paths.h $(COMPAT) + getenv.h string.h prctl.h paths.h netdb.h $(COMPAT) diff --git a/src/common/compat/netdb.h b/src/common/compat/netdb.h new file mode 100644 index 000000000..477058bad --- /dev/null +++ b/src/common/compat/netdb.h @@ -0,0 +1,44 @@ +/* + * Copyright (C) 2015 Michael Jeanson + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#ifndef _COMPAT_NETDB_H +#define _COMPAT_NETDB_H + +#include + +#ifdef HAVE_GETHOSTBYNAME2 +static inline +struct hostent *lttng_gethostbyname2(const char *name, int af) { + return gethostbyname2(name, af); +} +#elif HAVE_GETIPNODEBYNAME +static inline +struct hostent *lttng_gethostbyname2(const char *name, int af) { + int unused; + + return getipnodebyname(name, af, AI_DEFAULT, &unused); +} +#else +# error "Missing compat for gethostbyname2()" +#endif + +#endif /* _COMPAT_NETDB_H */ diff --git a/src/common/uri.c b/src/common/uri.c index dd2d9e4ee..ef68cd4fa 100644 --- a/src/common/uri.c +++ b/src/common/uri.c @@ -18,7 +18,7 @@ #define _LGPL_SOURCE #include #include -#include +#include #include #include #include @@ -115,7 +115,7 @@ static int set_ip_address(const char *addr, int af, char *dst, size_t size) ret = inet_pton(af, addr, buf); if (ret < 1) { /* We consider the dst to be an hostname or an invalid IP char */ - record = gethostbyname2(addr, af); + record = lttng_gethostbyname2(addr, af); if (record == NULL) { /* At this point, the IP or the hostname is bad */ ERR("URI parse bad hostname %s for af %d", addr, af); -- 2.34.1