Commit 4f3269f1 authored by Huw Davies's avatar Huw Davies Committed by Alexandre Julliard

iphlpapi: Use DnsQueryConfig() to retrieve the dns suffix.

parent 769952df
MODULE = iphlpapi.dll MODULE = iphlpapi.dll
IMPORTLIB = iphlpapi IMPORTLIB = iphlpapi
IMPORTS = advapi32 dnsapi nsi uuid IMPORTS = advapi32 dnsapi nsi uuid
EXTRALIBS = $(RESOLV_LIBS) $(KSTAT_LIBS) $(PROCSTAT_LIBS) EXTRALIBS = $(KSTAT_LIBS) $(PROCSTAT_LIBS)
C_SRCS = \ C_SRCS = \
icmp.c \ icmp.c \
......
...@@ -30,12 +30,6 @@ ...@@ -30,12 +30,6 @@
#ifdef HAVE_ARPA_INET_H #ifdef HAVE_ARPA_INET_H
# include <arpa/inet.h> # include <arpa/inet.h>
#endif #endif
#ifdef HAVE_ARPA_NAMESER_H
# include <arpa/nameser.h>
#endif
#ifdef HAVE_RESOLV_H
# include <resolv.h>
#endif
#define NONAMELESSUNION #define NONAMELESSUNION
#define NONAMELESSSTRUCT #define NONAMELESSSTRUCT
...@@ -1223,27 +1217,6 @@ static ULONG adapterAddressesFromIndex(ULONG family, ULONG flags, IF_INDEX index ...@@ -1223,27 +1217,6 @@ static ULONG adapterAddressesFromIndex(ULONG family, ULONG flags, IF_INDEX index
return ERROR_SUCCESS; return ERROR_SUCCESS;
} }
#ifdef HAVE_STRUCT___RES_STATE
/* call res_init() just once because of a bug in Mac OS X 10.4 */
/* Call once per thread on systems that have per-thread _res. */
static CRITICAL_SECTION res_init_cs;
static CRITICAL_SECTION_DEBUG res_init_cs_debug = {
0, 0, &res_init_cs,
{ &res_init_cs_debug.ProcessLocksList, &res_init_cs_debug.ProcessLocksList },
0, 0, { (DWORD_PTR)(__FILE__ ": res_init_cs") }
};
static CRITICAL_SECTION res_init_cs = { &res_init_cs_debug, -1, 0, 0, 0, 0 };
static void initialise_resolver(void)
{
EnterCriticalSection(&res_init_cs);
if ((_res.options & RES_INIT) == 0)
res_init();
LeaveCriticalSection(&res_init_cs);
}
#endif
static DWORD dns_servers_query_code( ULONG family ) static DWORD dns_servers_query_code( ULONG family )
{ {
if (family == WS_AF_INET) return DnsConfigDnsServersIpv4; if (family == WS_AF_INET) return DnsConfigDnsServersIpv4;
...@@ -1305,46 +1278,32 @@ err: ...@@ -1305,46 +1278,32 @@ err:
return err; return err;
} }
#ifdef HAVE_STRUCT___RES_STATE static ULONG get_dns_suffix(WCHAR *suffix, ULONG *len)
static BOOL is_ip_address_string(const char *str)
{ {
struct in_addr in; DWORD err, list_len = 0, needed = 1;
int ret; DNS_TXT_DATAW *search = NULL;
ret = inet_aton(str, &in); if (suffix && *len > 0) *suffix = '\0';
return ret != 0;
}
#endif
static ULONG get_dns_suffix(WCHAR *suffix, ULONG *len) err = DnsQueryConfig( DnsConfigSearchList, 0, NULL, NULL, NULL, &list_len );
{ if (err) goto err;
ULONG size;
const char *found_suffix = "";
/* Always return a NULL-terminated string, even if it's empty. */
#ifdef HAVE_STRUCT___RES_STATE search = heap_alloc( list_len );
{ err = DnsQueryConfig( DnsConfigSearchList, 0, NULL, NULL, search, &list_len );
ULONG i; if (err || !search->dwStringCount) goto err;
initialise_resolver();
for (i = 0; !*found_suffix && i < MAXDNSRCH + 1 && _res.dnsrch[i]; i++)
{
/* This uses a heuristic to select a DNS suffix:
* the first, non-IP address string is selected.
*/
if (!is_ip_address_string(_res.dnsrch[i]))
found_suffix = _res.dnsrch[i];
}
}
#endif
size = MultiByteToWideChar( CP_UNIXCP, 0, found_suffix, -1, NULL, 0 ) * sizeof(WCHAR); needed = (strlenW( search->pStringArray[0] ) + 1) * sizeof(WCHAR);
if (!suffix || *len < size) if (!suffix || *len < needed)
{ {
*len = size; err = ERROR_INSUFFICIENT_BUFFER;
return ERROR_BUFFER_OVERFLOW; goto err;
} }
*len = MultiByteToWideChar( CP_UNIXCP, 0, found_suffix, -1, suffix, *len / sizeof(WCHAR) ) * sizeof(WCHAR); memcpy( suffix, search->pStringArray[0], needed );
return ERROR_SUCCESS;
err:
*len = needed;
heap_free( search );
return err;
} }
ULONG WINAPI DECLSPEC_HOTPATCH GetAdaptersAddresses(ULONG family, ULONG flags, PVOID reserved, ULONG WINAPI DECLSPEC_HOTPATCH GetAdaptersAddresses(ULONG family, ULONG flags, PVOID reserved,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment