1 /*
2 * Adapted from tadns 1.1, from http://adns.sourceforge.net/
3 * Original license -->
4 *
5 * Copyright (c) 2004-2005 Sergey Lyubka <valenok@gmail.com>
6 *
7 * "THE BEER-WARE LICENSE" (Revision 42):
8 * Sergey Lyubka wrote this file. As long as you retain this notice you
9 * can do whatever you want with this stuff. If we meet some day, and you think
10 * this stuff is worth it, you can buy me a beer in return.
11 *
12 * Integrated into lws, largely rewritten and relicensed (as allowed above)
13 *
14 * libwebsockets - small server side websockets and web server implementation
15 *
16 * Copyright (C) 2010 - 2019 Andy Green <andy@warmcat.com>
17 *
18 * Permission is hereby granted, free of charge, to any person obtaining a copy
19 * of this software and associated documentation files (the "Software"), to
20 * deal in the Software without restriction, including without limitation the
21 * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
22 * sell copies of the Software, and to permit persons to whom the Software is
23 * furnished to do so, subject to the following conditions:
24 *
25 * The above copyright notice and this permission notice shall be included in
26 * all copies or substantial portions of the Software.
27 *
28 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
29 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
30 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
31 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
32 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
33 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
34 * IN THE SOFTWARE.
35 */
36
37 #include "private-lib-core.h"
38
39 lws_async_dns_server_check_t
lws_plat_asyncdns_init(struct lws_context * context,lws_sockaddr46 * sa46)40 lws_plat_asyncdns_init(struct lws_context *context, lws_sockaddr46 *sa46)
41 {
42 char subkey[512], dhcpns[512], ns[512], value[128], *key =
43 "SYSTEM\\ControlSet001\\Services\\Tcpip\\Parameters\\Interfaces";
44 HKEY hKey, hSub;
45 LONG err;
46 int i, n;
47
48 if ((err = RegOpenKey(HKEY_LOCAL_MACHINE, key, &hKey)) != ERROR_SUCCESS) {
49 lwsl_err("%s: cannot open reg key %s: %d\n", __func__, key, err);
50
51 return 1;
52 }
53
54 for (i = 0; RegEnumKey(hKey, i, subkey, sizeof(subkey)) == ERROR_SUCCESS; i++) {
55 DWORD type, len = sizeof(value);
56
57 if (RegOpenKey(hKey, subkey, &hSub) == ERROR_SUCCESS &&
58 (RegQueryValueEx(hSub, "NameServer", 0,
59 &type, value, &len) == ERROR_SUCCESS ||
60 RegQueryValueEx(hSub, "DhcpNameServer", 0,
61 &type, value, &len) == ERROR_SUCCESS)) {
62 n = lws_sa46_parse_numeric_address(value, sa46)
63 RegCloseKey(hSub);
64 RegCloseKey(hKey);
65 return n == 0 ? LADNS_CONF_SERVER_CHANGED :
66 LADNS_CONF_SERVER_UNKNOWN;
67 }
68 }
69 RegCloseKey(hKey);
70
71 return LADNS_CONF_SERVER_UNKNOWN;
72 }
73
74