The Cygwin resolver library doesn't fill out the list of name servers in
res_init() if /etc/resolv.conf doesn't exist, which is usual. Add code to handle this by calling GetNetworkParams(). git-svn-id: svn://svn.code.sf.net/p/bitchx/code/trunk@198 13b04d17-f746-0410-82c6-800466cd88b0
This commit is contained in:
@@ -164,6 +164,8 @@ if test x"$bx_cv_lib_resolver" != x"not found"; then
|
||||
if test x"$bx_cv_lib_resolver" != x"none required"; then
|
||||
LIBS="$bx_cv_lib_resolver $LIBS"
|
||||
fi
|
||||
dnl This is for getting the DNS servers on Windows
|
||||
AC_CHECK_HEADER([iphlpapi.h], [AC_CHECK_LIB(iphlpapi, GetNetworkParams, [], [])], [], [#include <windows.h>])
|
||||
else
|
||||
AC_MSG_WARN([No resolver library found, /nslookup will be disabled.])
|
||||
fi
|
||||
|
||||
@@ -2053,6 +2053,36 @@ static struct resstats {
|
||||
int re_timeouts;
|
||||
} ar_reinfo;
|
||||
|
||||
#ifdef HAVE_LIBIPHLPAPI
|
||||
#include <windows.h>
|
||||
#include <iphlpapi.h>
|
||||
|
||||
void ar_get_windows_dns(void)
|
||||
{
|
||||
DWORD ret;
|
||||
ULONG buflen = 0;
|
||||
FIXED_INFO *buf;
|
||||
|
||||
ret = GetNetworkParams(NULL, &buflen);
|
||||
if (ret != ERROR_BUFFER_OVERFLOW)
|
||||
return;
|
||||
|
||||
buf = new_malloc(buflen);
|
||||
|
||||
ret = GetNetworkParams(buf, &buflen);
|
||||
if (ret == NO_ERROR)
|
||||
{
|
||||
_res.nscount = 1;
|
||||
_res.nsaddr_list[0].sin_family = AF_INET;
|
||||
_res.nsaddr_list[0].sin_addr.s_addr = inet_addr(buf->DnsServerList.IpAddress.String);
|
||||
_res.nsaddr_list[0].sin_port = htons(53);
|
||||
}
|
||||
|
||||
new_free(&buf);
|
||||
return;
|
||||
}
|
||||
#endif /* HAVE_LIBIPHLPAPI */
|
||||
|
||||
/*
|
||||
* ar_init
|
||||
*
|
||||
@@ -2079,10 +2109,20 @@ int ar_init(int op)
|
||||
ret = res_init();
|
||||
(void)strcpy(ar_domainname, ar_dot);
|
||||
(void)strncat(ar_domainname, _res.defdname, HOSTLEN-2);
|
||||
if (!_res.nscount)
|
||||
#ifdef HAVE_LIBIPHLPAPI
|
||||
/* The Cygwin resolver library doesn't fill out _res.nsaddr_list
|
||||
* and sets _res.nscount to -1 if there's no /etc/resolv.conf file,
|
||||
* so we try fetching the first DNS server address ourselves. */
|
||||
if (_res.nscount < 1)
|
||||
ar_get_windows_dns();
|
||||
#endif
|
||||
if (_res.nscount < 1)
|
||||
{
|
||||
/* Try falling back to the Google public DNS */
|
||||
_res.nscount = 1;
|
||||
_res.nsaddr_list[0].sin_addr.s_addr = inet_addr("127.0.0.1");
|
||||
_res.nsaddr_list[0].sin_family = AF_INET;
|
||||
_res.nsaddr_list[0].sin_addr.s_addr = inet_addr("8.8.8.8");
|
||||
_res.nsaddr_list[0].sin_port = htons(53);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user