mirror of
https://github.com/warmcat/libwebsockets.git
synced 2025-03-30 00:00:16 +01:00
windows: async dns find DNS server using modern api
This commit is contained in:
parent
a8ad5068e4
commit
8299bd4191
1 changed files with 14 additions and 37 deletions
|
@ -1,16 +1,4 @@
|
|||
/*
|
||||
* Adapted from tadns 1.1, from http://adns.sourceforge.net/
|
||||
* Original license -->
|
||||
*
|
||||
* Copyright (c) 2004-2005 Sergey Lyubka <valenok@gmail.com>
|
||||
*
|
||||
* "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 <andy@warmcat.com>
|
||||
|
@ -35,39 +23,28 @@
|
|||
*/
|
||||
|
||||
#include "private-lib-core.h"
|
||||
#include <iphlpapi.h>
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue