From e472341769931b837c8cd826978f83f32c9623c2 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Petr=20Men=C5=A1=C3=ADk?= <pemensik@redhat.com>
Date: Tue, 21 Feb 2017 12:53:43 +0100
Subject: [PATCH 1/2] Prefix provided getaddrinfo in libirs with irs_

---
 config.h.in                    | 12 ---------
 configure                      | 55 ++++++++++++++++++------------------------
 configure.in                   | 37 ++++++++++++++--------------
 lib/irs/gai_strerror.c         |  2 +-
 lib/irs/getaddrinfo.c          |  4 +--
 lib/irs/getnameinfo.c          |  8 +++---
 lib/irs/include/irs/netdb.h.in | 28 +++++++++++++++++++++
 lib/irs/resconf.c              |  2 +-
 8 files changed, 78 insertions(+), 70 deletions(-)

diff --git a/config.h.in b/config.h.in
index 3e1b0d4..4dad23d 100644
--- a/config.h.in
+++ b/config.h.in
@@ -428,18 +428,6 @@ int sigwait(const unsigned int *set, int *sig);
 /* Define to 1 if you have the `usleep' function. */
 #undef HAVE_USLEEP
 
-/* return type of gai_strerror */
-#undef IRS_GAISTRERROR_RETURN_T
-
-/* Define to the buffer length type used by getnameinfo(3). */
-#undef IRS_GETNAMEINFO_BUFLEN_T
-
-/* Define to the flags type used by getnameinfo(3). */
-#undef IRS_GETNAMEINFO_FLAGS_T
-
-/* Define to the sockaddr length type used by getnameinfo(3). */
-#undef IRS_GETNAMEINFO_SOCKLEN_T
-
 /* Define to allow building of objects for dlopen(). */
 #undef ISC_DLZ_DLOPEN
 
diff --git a/configure b/configure
index 4813f77..4f2a278 100755
--- a/configure
+++ b/configure
@@ -750,6 +750,10 @@ ISC_IRS_GETNAMEINFOSOCKLEN
 ISC_LWRES_GETNAMEINFOPROTO
 ISC_LWRES_GETADDRINFOPROTO
 ISC_LWRES_GETIPNODEPROTO
+IRS_GAISTRERROR_RETURN_T
+IRS_GETNAMEINFO_FLAGS_T
+IRS_GETNAMEINFO_BUFLEN_T
+IRS_GETNAMEINFO_SOCKLEN_T
 ISC_LWRES_NEEDHERRNO
 ISC_LWRES_GETHOSTBYADDRVOID
 ISC_LWRES_ENDNETENTINT
@@ -17392,15 +17396,9 @@ _ACEOF
 if ac_fn_c_try_compile "$LINENO"; then :
   { $as_echo "$as_me:${as_lineno-$LINENO}: result: socklen_t for buflen; u_int for flags" >&5
 $as_echo "socklen_t for buflen; u_int for flags" >&6; }
-
-$as_echo "#define IRS_GETNAMEINFO_SOCKLEN_T socklen_t" >>confdefs.h
-
-
-$as_echo "#define IRS_GETNAMEINFO_BUFLEN_T socklen_t" >>confdefs.h
-
-
-$as_echo "#define IRS_GETNAMEINFO_FLAGS_T unsigned int" >>confdefs.h
-
+	 IRS_GETNAMEINFO_SOCKLEN_T=socklen_t
+	 IRS_GETNAMEINFO_BUFLEN_T=socklen_t
+	 IRS_GETNAMEINFO_FLAGS_T="unsigned int"
 else
   cat confdefs.h - <<_ACEOF >conftest.$ac_ext
 /* end confdefs.h.  */
@@ -17421,12 +17419,9 @@ _ACEOF
 if ac_fn_c_try_compile "$LINENO"; then :
   { $as_echo "$as_me:${as_lineno-$LINENO}: result: size_t for buflen; int for flags" >&5
 $as_echo "size_t for buflen; int for flags" >&6; }
-	 $as_echo "#define IRS_GETNAMEINFO_SOCKLEN_T socklen_t" >>confdefs.h
-
-	 $as_echo "#define IRS_GETNAMEINFO_BUFLEN_T size_t" >>confdefs.h
-
-	 $as_echo "#define IRS_GETNAMEINFO_FLAGS_T int" >>confdefs.h
-
+	 IRS_GETNAMEINFO_SOCKLEN_T=socklen_t
+	 IRS_GETNAMEINFO_BUFLEN_T=size_t
+	 IRS_GETNAMEINFO_FLAGS_T=int
 else
   cat confdefs.h - <<_ACEOF >conftest.$ac_ext
 /* end confdefs.h.  */
@@ -17447,21 +17442,15 @@ _ACEOF
 if ac_fn_c_try_compile "$LINENO"; then :
   { $as_echo "$as_me:${as_lineno-$LINENO}: result: size_t for buflen; int for flags" >&5
 $as_echo "size_t for buflen; int for flags" >&6; }
-	 $as_echo "#define IRS_GETNAMEINFO_SOCKLEN_T size_t" >>confdefs.h
-
-	 $as_echo "#define IRS_GETNAMEINFO_BUFLEN_T size_t" >>confdefs.h
-
-	 $as_echo "#define IRS_GETNAMEINFO_FLAGS_T int" >>confdefs.h
-
+	 IRS_GETNAMEINFO_SOCKLEN_T=size_t
+	 IRS_GETNAMEINFO_BUFLEN_T=size_t
+	 IRS_GETNAMEINFO_FLAGS_T=int
 else
   { $as_echo "$as_me:${as_lineno-$LINENO}: result: not match any subspecies; assume standard definition" >&5
 $as_echo "not match any subspecies; assume standard definition" >&6; }
-$as_echo "#define IRS_GETNAMEINFO_SOCKLEN_T socklen_t" >>confdefs.h
-
-$as_echo "#define IRS_GETNAMEINFO_BUFLEN_T socklen_t" >>confdefs.h
-
-$as_echo "#define IRS_GETNAMEINFO_FLAGS_T int" >>confdefs.h
-
+IRS_GETNAMEINFO_SOCKLEN_T=socklen_t
+IRS_GETNAMEINFO_BUFLEN_T=socklen_t
+IRS_GETNAMEINFO_FLAGS_T=int
 fi
 rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
 fi
@@ -17469,6 +17458,10 @@ rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
 fi
 rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
 
+
+
+
+
 #
 # ...and same for gai_strerror().
 #
@@ -17492,17 +17485,15 @@ _ACEOF
 if ac_fn_c_try_compile "$LINENO"; then :
   { $as_echo "$as_me:${as_lineno-$LINENO}: result: returning char *" >&5
 $as_echo "returning char *" >&6; }
-
-$as_echo "#define IRS_GAISTRERROR_RETURN_T char *" >>confdefs.h
-
+	 IRS_GAISTRERROR_RETURN_T='char *'
 else
   { $as_echo "$as_me:${as_lineno-$LINENO}: result: not match any subspecies; assume standard definition" >&5
 $as_echo "not match any subspecies; assume standard definition" >&6; }
-$as_echo "#define IRS_GAISTRERROR_RETURN_T const char *" >>confdefs.h
-
+IRS_GAISTRERROR_RETURN_T='const char *'
 fi
 rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
 
+
 ac_fn_c_check_func "$LINENO" "getipnodebyname" "ac_cv_func_getipnodebyname"
 if test "x$ac_cv_func_getipnodebyname" = xyes; then :
   ISC_LWRES_GETIPNODEPROTO="#undef ISC_LWRES_GETIPNODEPROTO"
diff --git a/configure.in b/configure.in
index ba8ddd1..a39adcf 100644
--- a/configure.in
+++ b/configure.in
@@ -2559,12 +2559,9 @@ int getnameinfo(const struct sockaddr *, socklen_t, char *,
 		socklen_t, char *, socklen_t, unsigned int);],
 [ return (0);],
 	[AC_MSG_RESULT(socklen_t for buflen; u_int for flags)
-	 AC_DEFINE(IRS_GETNAMEINFO_SOCKLEN_T, socklen_t,
-		   [Define to the sockaddr length type used by getnameinfo(3).])
-	 AC_DEFINE(IRS_GETNAMEINFO_BUFLEN_T, socklen_t,
-		   [Define to the buffer length type used by getnameinfo(3).])
-	 AC_DEFINE(IRS_GETNAMEINFO_FLAGS_T, unsigned int,
-		   [Define to the flags type used by getnameinfo(3).])],
+	 IRS_GETNAMEINFO_SOCKLEN_T=socklen_t
+	 IRS_GETNAMEINFO_BUFLEN_T=socklen_t
+	 IRS_GETNAMEINFO_FLAGS_T="unsigned int"],
 [AC_TRY_COMPILE([
 #include <sys/types.h>
 #include <sys/socket.h>
@@ -2573,9 +2570,9 @@ int getnameinfo(const struct sockaddr *, socklen_t, char *,
 		size_t, char *, size_t, int);],
 [ return (0);],
 	[AC_MSG_RESULT(size_t for buflen; int for flags)
-	 AC_DEFINE(IRS_GETNAMEINFO_SOCKLEN_T, socklen_t)
-	 AC_DEFINE(IRS_GETNAMEINFO_BUFLEN_T, size_t)
-	 AC_DEFINE(IRS_GETNAMEINFO_FLAGS_T, int)],
+	 IRS_GETNAMEINFO_SOCKLEN_T=socklen_t
+	 IRS_GETNAMEINFO_BUFLEN_T=size_t
+	 IRS_GETNAMEINFO_FLAGS_T=int],
 [AC_TRY_COMPILE([
 #include <sys/types.h>
 #include <sys/socket.h>
@@ -2584,13 +2581,17 @@ int getnameinfo(const struct sockaddr *, size_t, char *,
 		size_t, char *, size_t, int);],
 [ return (0);],
 	[AC_MSG_RESULT(size_t for buflen; int for flags)
-	 AC_DEFINE(IRS_GETNAMEINFO_SOCKLEN_T, size_t)
-	 AC_DEFINE(IRS_GETNAMEINFO_BUFLEN_T, size_t)
-	 AC_DEFINE(IRS_GETNAMEINFO_FLAGS_T, int)],
+	 IRS_GETNAMEINFO_SOCKLEN_T=size_t
+	 IRS_GETNAMEINFO_BUFLEN_T=size_t
+	 IRS_GETNAMEINFO_FLAGS_T=int],
 [AC_MSG_RESULT(not match any subspecies; assume standard definition)
-AC_DEFINE(IRS_GETNAMEINFO_SOCKLEN_T, socklen_t)
-AC_DEFINE(IRS_GETNAMEINFO_BUFLEN_T, socklen_t)
-AC_DEFINE(IRS_GETNAMEINFO_FLAGS_T, int)])])])
+IRS_GETNAMEINFO_SOCKLEN_T=socklen_t
+IRS_GETNAMEINFO_BUFLEN_T=socklen_t
+IRS_GETNAMEINFO_FLAGS_T=int])])])
+
+AC_SUBST(IRS_GETNAMEINFO_SOCKLEN_T)
+AC_SUBST(IRS_GETNAMEINFO_BUFLEN_T)
+AC_SUBST(IRS_GETNAMEINFO_FLAGS_T)
 
 #
 # ...and same for gai_strerror().
@@ -2603,10 +2604,10 @@ AC_TRY_COMPILE([
 char *gai_strerror(int ecode);],
 [ return (0); ],
 	[AC_MSG_RESULT(returning char *)
-	 AC_DEFINE([IRS_GAISTRERROR_RETURN_T], [char *],
-	 [return type of gai_strerror])],
+	 IRS_GAISTRERROR_RETURN_T='char *'],
 [AC_MSG_RESULT(not match any subspecies; assume standard definition)
-AC_DEFINE([IRS_GAISTRERROR_RETURN_T], [const char *])])
+IRS_GAISTRERROR_RETURN_T='const char *'])
+AC_SUBST(IRS_GAISTRERROR_RETURN_T)
 
 AC_CHECK_FUNC(getipnodebyname,
 	[ISC_LWRES_GETIPNODEPROTO="#undef ISC_LWRES_GETIPNODEPROTO"],
diff --git a/lib/irs/gai_strerror.c b/lib/irs/gai_strerror.c
index 2fe3941..b9a51ef 100644
--- a/lib/irs/gai_strerror.c
+++ b/lib/irs/gai_strerror.c
@@ -77,7 +77,7 @@ static const char *gai_messages[] = {
  * Returns an error message corresponding to an error code returned by
  * getaddrinfo() and getnameinfo()
  */
-IRS_GAISTRERROR_RETURN_T
+irs_gaistrerror_t
 gai_strerror(int ecode) {
 	union {
 		const char *const_ptr;
diff --git a/lib/irs/getaddrinfo.c b/lib/irs/getaddrinfo.c
index 5f904ed..3fa27ea 100644
--- a/lib/irs/getaddrinfo.c
+++ b/lib/irs/getaddrinfo.c
@@ -191,7 +191,7 @@ static void _freeaddrinfo(struct addrinfo *ai);
  * service servname.
  */
 int
-getaddrinfo(const char *hostname, const char *servname,
+irs_getaddrinfo(const char *hostname, const char *servname,
 	    const struct addrinfo *hints, struct addrinfo **res)
 {
 	struct servent *sp;
@@ -1174,7 +1174,7 @@ add_ipv6(const char *hostname, int flags, struct addrinfo **aip,
 
 /*% Free address info. */
 void
-freeaddrinfo(struct addrinfo *ai) {
+irs_freeaddrinfo(struct addrinfo *ai) {
 	_freeaddrinfo(ai);
 }
 
diff --git a/lib/irs/getnameinfo.c b/lib/irs/getnameinfo.c
index ec43043..a046fb8 100644
--- a/lib/irs/getnameinfo.c
+++ b/lib/irs/getnameinfo.c
@@ -143,10 +143,10 @@ static struct afd {
 	} while (0)
 
 int
-getnameinfo(const struct sockaddr *sa, IRS_GETNAMEINFO_SOCKLEN_T salen,
-	    char *host, IRS_GETNAMEINFO_BUFLEN_T hostlen,
-	    char *serv, IRS_GETNAMEINFO_BUFLEN_T servlen,
-	    IRS_GETNAMEINFO_FLAGS_T flags)
+irs_getnameinfo(const struct sockaddr *sa, irs_socklen_t salen,
+	    char *host, irs_buflen_t hostlen,
+	    char *serv, irs_buflen_t servlen,
+	    irs_flags_t flags)
 {
 	struct afd *afd = NULL;
 	struct servent *sp;
diff --git a/lib/irs/include/irs/netdb.h.in b/lib/irs/include/irs/netdb.h.in
index 299928b..3cf173f 100644
--- a/lib/irs/include/irs/netdb.h.in
+++ b/lib/irs/include/irs/netdb.h.in
@@ -157,6 +157,34 @@ struct addrinfo {
 #define	NI_NUMERICSERV	0x00000008
 #define	NI_DGRAM	0x00000010
 
+typedef @IRS_GETNAMEINFO_SOCKLEN_T@ irs_socklen_t;
+typedef @IRS_GETNAMEINFO_BUFLEN_T@ irs_buflen_t;
+typedef @IRS_GETNAMEINFO_FLAGS_T@ irs_flags_t;
+typedef @IRS_GAISTRERROR_RETURN_T@ irs_gaistrerror_t;
+
+int
+irs_getaddrinfo(const char *hostname, const char *servname,
+	    const struct addrinfo *hints, struct addrinfo **res);
+
+void
+irs_freeaddrinfo(struct addrinfo *ai);
+
+int
+irs_getnameinfo(const struct sockaddr *sa, irs_socklen_t salen,
+	    char *host, irs_buflen_t hostlen,
+	    char *serv, irs_buflen_t servlen,
+	    irs_flags_t flags);
+
+irs_gaistrerror_t
+irs_gai_strerror(int ecode);
+
+#ifndef IRS_NO_GETADDRINFO_COMPAT
+#define getaddrinfo irs_getaddrinfo
+#define freeaddrinfo irs_freeaddrinfo
+#define getnameinfo irs_getnameinfo
+#define gai_strerror irs_gai_strerror
+#endif
+
 /*
  * Tell Emacs to use C mode on this file.
  * Local variables:
diff --git a/lib/irs/resconf.c b/lib/irs/resconf.c
index 2ec6ac8..7480ff6 100644
--- a/lib/irs/resconf.c
+++ b/lib/irs/resconf.c
@@ -46,7 +46,6 @@
 
 #include <ctype.h>
 #include <errno.h>
-#include <netdb.h>
 #include <stdlib.h>
 #include <stdio.h>
 #include <string.h>
@@ -58,6 +57,7 @@
 #include <isc/util.h>
 
 #include <irs/resconf.h>
+#include <irs/netdb.h>
 
 #define IRS_RESCONF_MAGIC		ISC_MAGIC('R', 'E', 'S', 'c')
 #define IRS_RESCONF_VALID(c)		ISC_MAGIC_VALID(c, IRS_RESCONF_MAGIC)
-- 
2.9.3

