>From 6b0fdb1d1bb064265da442abc609f6081402eba3 Mon Sep 17 00:00:00 2001
From: Mats Erik Andersson
Date: Wed, 22 Aug 2012 20:13:15 +0200
Subject: [PATCH 1/2] Locate res_query and libresolv.
For portability res_query must be searched
in libc, and in libresolv. The latter need
not even exist on systems such as BSD.
---
configure.ac | 31 +++++++++++++++++++++++++------
lib/resolv.c | 12 ++++++++----
2 files changed, 33 insertions(+), 10 deletions(-)
diff --git a/configure.ac b/configure.ac
index 7c38731..919fcfc 100644
--- a/configure.ac
+++ b/configure.ac
@@ -42,6 +42,12 @@ gl2_EARLY
gl3_EARLY
AC_HEADER_STDC
AC_CHECK_HEADERS(termios.h pwd.h syslog.h arpa/nameser.h netinet/in6.h)
+AC_CHECK_HEADERS(resolv.h, , , [#include
+ #include
+ #ifdef HAVE_ARPA_NAMESER_H
+ # include
+ #endif
+])
# Used when creating libshishi-XX.def.
SOVERSION=`expr ${LT_CURRENT} - ${LT_AGE}`
@@ -81,14 +87,27 @@ if test "$ac_cv_libgcrypt" != yes; then
fi
# Checks for library functions.
-AC_CHECK_FUNCS(signal select ngettext gethostbyname getpwnam getuid)
+AC_CHECK_FUNCS(signal select ngettext gethostbyname getpwnam getuid res_query)
AC_SEARCH_LIBS(socket, socket)
AC_SEARCH_LIBS(gethostbyname, nsl)
-AC_LIB_HAVE_LINKFLAGS(resolv,, [
- #include
- #include
- #include
-], [res_query (0, 0, 0, 0, 0);])
+
+# BSD systems deliver res_query in libc.
+# Most of them do not even offer libresolv.
+if test "$ac_cv_func_res_query" != yes; then
+ AC_LIB_HAVE_LINKFLAGS(resolv,, [
+ #include
+ #include
+ #include
+ ], [res_query (0, 0, 0, 0, 0);])
+ # Check again, with newly acquired knowledge.
+ if test "$ac_cv_libresolv" = yes; then
+ AC_DEFINE([HAVE_RES_QUERY], 1,
+ [Define to 1 if you have the res_query function.])
+ fi
+fi
+dnl Declare LIBRESOLV and LTLIBRESOLV in all cases.
+AC_SUBST(LIBRESOLV)
+AC_SUBST(LTLIBRESOLV)
# Shishid needs a logging mechanism, and right now there is no
# alternative to syslog. A 'fprintf(stderr,...)' mechanism may be
diff --git a/lib/resolv.c b/lib/resolv.c
index 57d4824..599d5b4 100644
--- a/lib/resolv.c
+++ b/lib/resolv.c
@@ -30,11 +30,15 @@
#include "internal.h"
-#ifdef HAVE_LIBRESOLV
+#ifdef HAVE_RES_QUERY
#include
-#include
-#include
+# ifdef HAVE_ARPA_NAMESER_H
+# include
+# endif
+# ifdef HAVE_RESOLV_H
+# include
+# endif
/* the largest packet we'll send and receive */
#if PACKETSZ > 1024
@@ -263,7 +267,7 @@ shishi_resolv (const char *zone, uint16_t querytype)
return first;
}
-#else
+#else /* !HAVE_RES_QUERY */
Shishi_dns
shishi_resolv (const char *zone, uint16_t querytype)
--
1.7.2.5