[Asterisk-code-review] Fix misdetection of gethostbyname_r() on NetBSD (asterisk[master])

Jaco Kroon asteriskteam at digium.com
Thu Dec 16 00:10:33 CST 2021


Jaco Kroon has uploaded this change for review. ( https://gerrit.asterisk.org/c/asterisk/+/17703 )


Change subject: Fix misdetection of gethostbyname_r() on NetBSD
......................................................................

Fix misdetection of gethostbyname_r() on NetBSD

NetBSD includes gethostbyname_r() as an internal libc symbol that
is not exposed in system headers and that is incompatible with other
implementations.  Perform the symbol check only if the declaration
is found in the public header.

MichaƂ supplied me with this patch to submit.

Change-Id: Iafa359b09908251bcd299ff54be003ea129b9eda
Signed-off-by: Jaco Kroon <jaco at uls.co.za>
---
M configure.ac
1 file changed, 30 insertions(+), 20 deletions(-)



  git pull ssh://gerrit.asterisk.org:29418/asterisk refs/changes/03/17703/1

diff --git a/configure.ac b/configure.ac
index 9bae413..d6aa306 100644
--- a/configure.ac
+++ b/configure.ac
@@ -943,28 +943,38 @@
 		AC_MSG_RESULT(no)
 )
 
-# some systems already have gethostbyname_r so we don't need to build ours in main/utils.c
-AC_SEARCH_LIBS(gethostbyname_r, [socket nsl])
-
-AC_MSG_CHECKING(for gethostbyname_r with 6 arguments)
-AC_LINK_IFELSE(
-        [AC_LANG_PROGRAM([#include <stdlib.h>
-                         #include <netdb.h>],
-                        [struct hostent *he = gethostbyname_r((const char *)NULL, (struct hostent *)NULL, (char *)NULL, (int)0, (struct hostent **)NULL, (int *)NULL);])],
-        AC_MSG_RESULT(yes)
-        AC_DEFINE([HAVE_GETHOSTBYNAME_R_6], 1, [Define to 1 if your system has gethostbyname_r with 6 arguments.]),
-        AC_MSG_RESULT(no)
+# NetBSD libc ships with an internal-only incompatible symbol gethostbyname_r
+AC_CHECK_DECLS(gethostbyname_r,
+        [have_gethostbyname_r_public_declaration=yes],
+        [have_gethostbyname_r_public_declaration=no],
+        [#include <stdlib.h>
+         #include <netdb.h>]
 )
 
-AC_MSG_CHECKING(for gethostbyname_r with 5 arguments)
-AC_LINK_IFELSE(
-        [AC_LANG_PROGRAM([#include <stdlib.h>
-	                 #include <netdb.h>],
-                        [struct hostent *he = gethostbyname_r((const char *)NULL, (struct hostent *)NULL, (char *)NULL, (int)0, (int *)NULL);])],
-        AC_MSG_RESULT(yes)
-        AC_DEFINE([HAVE_GETHOSTBYNAME_R_5], 1, [Define to 1 if your system has gethostbyname_r with 5 arguments.]),
-        AC_MSG_RESULT(no)
-)
+if test "x$have_gethostbyname_r_public_declaration" = "xyes"; then
+        # some systems already have gethostbyname_r so we don't need to build ours in main/utils.c
+        AC_SEARCH_LIBS(gethostbyname_r, [socket nsl])
+
+        AC_MSG_CHECKING(for gethostbyname_r with 6 arguments)
+        AC_LINK_IFELSE(
+                [AC_LANG_PROGRAM([#include <stdlib.h>
+                                 #include <netdb.h>],
+                                [struct hostent *he = gethostbyname_r((const char *)NULL, (struct hostent *)NULL, (char *)NULL, (int)0, (struct hostent **)NULL, (int *)NULL);])],
+                AC_MSG_RESULT(yes)
+                AC_DEFINE([HAVE_GETHOSTBYNAME_R_6], 1, [Define to 1 if your system has gethostbyname_r with 6 arguments.]),
+                AC_MSG_RESULT(no)
+        )
+
+        AC_MSG_CHECKING(for gethostbyname_r with 5 arguments)
+        AC_LINK_IFELSE(
+                [AC_LANG_PROGRAM([#include <stdlib.h>
+	                         #include <netdb.h>],
+                                [struct hostent *he = gethostbyname_r((const char *)NULL, (struct hostent *)NULL, (char *)NULL, (int)0, (int *)NULL);])],
+                AC_MSG_RESULT(yes)
+                AC_DEFINE([HAVE_GETHOSTBYNAME_R_5], 1, [Define to 1 if your system has gethostbyname_r with 5 arguments.]),
+                AC_MSG_RESULT(no)
+        )
+fi
 
 AC_CHECK_HEADER([byteswap.h], [AC_DEFINE_UNQUOTED([HAVE_BYTESWAP_H], 1, [Define to 1 if byteswap.h macros are available.])])
 

-- 
To view, visit https://gerrit.asterisk.org/c/asterisk/+/17703
To unsubscribe, or for help writing mail filters, visit https://gerrit.asterisk.org/settings

Gerrit-Project: asterisk
Gerrit-Branch: master
Gerrit-Change-Id: Iafa359b09908251bcd299ff54be003ea129b9eda
Gerrit-Change-Number: 17703
Gerrit-PatchSet: 1
Gerrit-Owner: Jaco Kroon <jaco at uls.co.za>
Gerrit-MessageType: newchange
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.digium.com/pipermail/asterisk-code-review/attachments/20211216/026e9a69/attachment.html>


More information about the asterisk-code-review mailing list