From 8299bd4191a67994451476f45e4ccdac06553274 Mon Sep 17 00:00:00 2001 From: Andy Green Date: Thu, 16 Apr 2020 18:49:15 +0100 Subject: [PATCH] windows: async dns find DNS server using modern api --- lib/plat/windows/windows-resolv.c | 51 +++++++++---------------------- 1 file changed, 14 insertions(+), 37 deletions(-) diff --git a/lib/plat/windows/windows-resolv.c b/lib/plat/windows/windows-resolv.c index 541cc0ae6..146db2c41 100644 --- a/lib/plat/windows/windows-resolv.c +++ b/lib/plat/windows/windows-resolv.c @@ -1,16 +1,4 @@ /* - * Adapted from tadns 1.1, from http://adns.sourceforge.net/ - * Original license --> - * - * Copyright (c) 2004-2005 Sergey Lyubka - * - * "THE BEER-WARE LICENSE" (Revision 42): - * Sergey Lyubka wrote this file. As long as you retain this notice you - * can do whatever you want with this stuff. If we meet some day, and you think - * this stuff is worth it, you can buy me a beer in return. - * - * Integrated into lws, largely rewritten and relicensed (as allowed above) - * * libwebsockets - small server side websockets and web server implementation * * Copyright (C) 2010 - 2019 Andy Green @@ -35,39 +23,28 @@ */ #include "private-lib-core.h" +#include lws_async_dns_server_check_t lws_plat_asyncdns_init(struct lws_context *context, lws_sockaddr46 *sa46) { - char subkey[512], value[128], *key = - "SYSTEM\\ControlSet001\\Services\\Tcpip\\Parameters\\Interfaces"; - HKEY hKey, hSub; - LONG err; - int i, n; + unsigned long ul; + FIXED_INFO fi; + int n; - if ((err = RegOpenKey(HKEY_LOCAL_MACHINE, key, &hKey)) != ERROR_SUCCESS) { - lwsl_err("%s: cannot open reg key %s: %d\n", __func__, key, err); + ul = sizeof(fi); + if (GetNetworkParams(&fi, &ul) != NO_ERROR) { + lwsl_err("%s: can't get dns servers\n", __func__); - return 1; + return LADNS_CONF_SERVER_UNKNOWN; } - for (i = 0; RegEnumKey(hKey, i, subkey, sizeof(subkey)) == ERROR_SUCCESS; i++) { - DWORD type, len = sizeof(value); + lwsl_info("%s: trying %s\n", __func__, + fi.DnsServerList.IpAddress.String); + n = lws_sa46_parse_numeric_address( + fi.DnsServerList.IpAddress.String, sa46); - if (RegOpenKey(hKey, subkey, &hSub) == ERROR_SUCCESS && - (RegQueryValueEx(hSub, "NameServer", 0, - &type, value, &len) == ERROR_SUCCESS || - RegQueryValueEx(hSub, "DhcpNameServer", 0, - &type, value, &len) == ERROR_SUCCESS)) { - n = lws_sa46_parse_numeric_address(value, sa46); - RegCloseKey(hSub); - RegCloseKey(hKey); - return n == 0 ? LADNS_CONF_SERVER_CHANGED : - LADNS_CONF_SERVER_UNKNOWN; - } - } - RegCloseKey(hKey); - - return LADNS_CONF_SERVER_UNKNOWN; + return n == 0 ? LADNS_CONF_SERVER_CHANGED : + LADNS_CONF_SERVER_UNKNOWN; }