[PATCH] iphlpapi: Use res_getservers() if available to get the DNS server list.
Chip Davis
cdavis at codeweavers.com
Thu Dec 12 17:18:28 CST 2019
Signed-off-by: Chip Davis <cdavis at codeweavers.com>
---
configure.ac | 15 +++++++++++++
dlls/iphlpapi/iphlpapi_main.c | 42 +++++++++++++++++++++++++++++++++++
2 files changed, 57 insertions(+)
diff --git a/configure.ac b/configure.ac
index d53321a8f7f..5b9a787e18a 100644
--- a/configure.ac
+++ b/configure.ac
@@ -1544,6 +1544,21 @@ then
AC_DEFINE(HAVE_RESOLV, 1)
AC_SUBST(RESOLV_LIBS,$ac_cv_have_resolv) ;;
esac
+
+ if test "x$ac_cv_have_resolv" != "xnot found"
+ then
+ AC_CACHE_CHECK([for res_getservers],wine_cv_have_res_getservers,
+ [ac_save_LIBS="$LIBS"
+ test "x$ac_cv_have_resolv" = "xnone required" || \
+ LIBS="$ac_cv_have_resolv $LIBS"
+ AC_LINK_IFELSE([AC_LANG_PROGRAM(
+ [[#include <resolv.h>]],[[res_getservers(NULL, NULL, 0);]])],[wine_cv_have_res_getservers=yes],[wine_cv_have_res_getservers=no])
+ LIBS="$ac_save_LIBS"])
+ if test "$wine_cv_have_res_getservers" = "yes"
+ then
+ AC_DEFINE(HAVE_RES_GETSERVERS, 1, [Define to 1 if you have the `res_getservers' function.])
+ fi
+ fi
fi
dnl **** Check for LittleCMS ***
diff --git a/dlls/iphlpapi/iphlpapi_main.c b/dlls/iphlpapi/iphlpapi_main.c
index 8c7c9018c48..f90879e0523 100644
--- a/dlls/iphlpapi/iphlpapi_main.c
+++ b/dlls/iphlpapi/iphlpapi_main.c
@@ -1281,6 +1281,47 @@ static void initialise_resolver(void)
LeaveCriticalSection(&res_init_cs);
}
+#ifdef HAVE_RES_GETSERVERS
+static int get_dns_servers( SOCKADDR_STORAGE *servers, int num, BOOL ip4_only )
+{
+ struct __res_state *state = &_res;
+ int i, found = 0, total;
+ SOCKADDR_STORAGE *addr = servers;
+ union res_sockaddr_union *buf;
+
+ initialise_resolver();
+
+ total = res_getservers( state, NULL, 0 );
+
+ if ((!servers || !num) && !ip4_only) return total;
+
+ buf = HeapAlloc( GetProcessHeap(), 0, total * sizeof(union res_sockaddr_union) );
+ total = res_getservers( state, buf, total );
+
+ for (i = 0; i < total; i++)
+ {
+ if (buf[i].sin6.sin6_family == AF_INET6 && ip4_only) continue;
+ if (buf[i].sin.sin_family != AF_INET && buf[i].sin6.sin6_family != AF_INET6) continue;
+
+ found++;
+ if (!servers || !num) continue;
+
+ if (buf[i].sin6.sin6_family == AF_INET6)
+ {
+ sockaddr_in6_to_WS_storage( addr, &buf[i].sin6 );
+ }
+ else
+ {
+ sockaddr_in_to_WS_storage( addr, &buf[i].sin );
+ }
+ if (++addr >= servers + num) break;
+ }
+
+ HeapFree( GetProcessHeap(), 0, buf );
+ return found;
+}
+#else
+
static int get_dns_servers( SOCKADDR_STORAGE *servers, int num, BOOL ip4_only )
{
int i, ip6_count = 0;
@@ -1316,6 +1357,7 @@ static int get_dns_servers( SOCKADDR_STORAGE *servers, int num, BOOL ip4_only )
}
return addr - servers;
}
+#endif
#elif defined(HAVE___RES_GET_STATE) && defined(HAVE___RES_GETSERVERS)
static int get_dns_servers( SOCKADDR_STORAGE *servers, int num, BOOL ip4_only )
--
2.24.0
More information about the wine-devel
mailing list