1d4afb5ceSopenharmony_ci/* 2d4afb5ceSopenharmony_ci * libwebsockets - small server side websockets and web server implementation 3d4afb5ceSopenharmony_ci * 4d4afb5ceSopenharmony_ci * Copyright (C) 2010 - 2019 Andy Green <andy@warmcat.com> 5d4afb5ceSopenharmony_ci * 6d4afb5ceSopenharmony_ci * Permission is hereby granted, free of charge, to any person obtaining a copy 7d4afb5ceSopenharmony_ci * of this software and associated documentation files (the "Software"), to 8d4afb5ceSopenharmony_ci * deal in the Software without restriction, including without limitation the 9d4afb5ceSopenharmony_ci * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 10d4afb5ceSopenharmony_ci * sell copies of the Software, and to permit persons to whom the Software is 11d4afb5ceSopenharmony_ci * furnished to do so, subject to the following conditions: 12d4afb5ceSopenharmony_ci * 13d4afb5ceSopenharmony_ci * The above copyright notice and this permission notice shall be included in 14d4afb5ceSopenharmony_ci * all copies or substantial portions of the Software. 15d4afb5ceSopenharmony_ci * 16d4afb5ceSopenharmony_ci * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17d4afb5ceSopenharmony_ci * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18d4afb5ceSopenharmony_ci * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19d4afb5ceSopenharmony_ci * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20d4afb5ceSopenharmony_ci * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 21d4afb5ceSopenharmony_ci * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 22d4afb5ceSopenharmony_ci * IN THE SOFTWARE. 23d4afb5ceSopenharmony_ci */ 24d4afb5ceSopenharmony_ci 25d4afb5ceSopenharmony_ci#include "private-lib-core.h" 26d4afb5ceSopenharmony_ci#include <iphlpapi.h> 27d4afb5ceSopenharmony_ci 28d4afb5ceSopenharmony_cilws_async_dns_server_check_t 29d4afb5ceSopenharmony_cilws_plat_asyncdns_init(struct lws_context *context, lws_sockaddr46 *sa46) 30d4afb5ceSopenharmony_ci{ 31d4afb5ceSopenharmony_ci unsigned long ul; 32d4afb5ceSopenharmony_ci FIXED_INFO *fi; 33d4afb5ceSopenharmony_ci int n = 0; 34d4afb5ceSopenharmony_ci DWORD dw; 35d4afb5ceSopenharmony_ci 36d4afb5ceSopenharmony_ci ul = sizeof(fi); 37d4afb5ceSopenharmony_ci 38d4afb5ceSopenharmony_ci do { 39d4afb5ceSopenharmony_ci fi = (FIXED_INFO *)lws_malloc(ul, __func__); 40d4afb5ceSopenharmony_ci if (!fi) 41d4afb5ceSopenharmony_ci goto oom; 42d4afb5ceSopenharmony_ci 43d4afb5ceSopenharmony_ci dw = GetNetworkParams(fi, &ul); 44d4afb5ceSopenharmony_ci if (dw == NO_ERROR) 45d4afb5ceSopenharmony_ci break; 46d4afb5ceSopenharmony_ci if (dw != ERROR_BUFFER_OVERFLOW) { 47d4afb5ceSopenharmony_ci lwsl_err("%s: GetNetworkParams says 0x%x\n", __func__, 48d4afb5ceSopenharmony_ci (unsigned int)dw); 49d4afb5ceSopenharmony_ci 50d4afb5ceSopenharmony_ci return LADNS_CONF_SERVER_UNKNOWN; 51d4afb5ceSopenharmony_ci } 52d4afb5ceSopenharmony_ci 53d4afb5ceSopenharmony_ci lws_free(fi); 54d4afb5ceSopenharmony_ci if (n++) 55d4afb5ceSopenharmony_ci /* not twice or more */ 56d4afb5ceSopenharmony_ci goto oom; 57d4afb5ceSopenharmony_ci 58d4afb5ceSopenharmony_ci } while (1); 59d4afb5ceSopenharmony_ci 60d4afb5ceSopenharmony_ci /* if we got here, then we have it */ 61d4afb5ceSopenharmony_ci 62d4afb5ceSopenharmony_ci lwsl_info("%s: trying %s\n", __func__, 63d4afb5ceSopenharmony_ci fi->DnsServerList.IpAddress.String); 64d4afb5ceSopenharmony_ci n = lws_sa46_parse_numeric_address( 65d4afb5ceSopenharmony_ci fi->DnsServerList.IpAddress.String, sa46); 66d4afb5ceSopenharmony_ci 67d4afb5ceSopenharmony_ci lws_free(fi); 68d4afb5ceSopenharmony_ci 69d4afb5ceSopenharmony_ci return n == 0 ? LADNS_CONF_SERVER_CHANGED : 70d4afb5ceSopenharmony_ci LADNS_CONF_SERVER_UNKNOWN; 71d4afb5ceSopenharmony_ci 72d4afb5ceSopenharmony_cioom: 73d4afb5ceSopenharmony_ci lwsl_err("%s: OOM\n", __func__); 74d4afb5ceSopenharmony_ci 75d4afb5ceSopenharmony_ci return LADNS_CONF_SERVER_UNKNOWN; 76d4afb5ceSopenharmony_ci} 77d4afb5ceSopenharmony_ci 78d4afb5ceSopenharmony_ciint 79d4afb5ceSopenharmony_cilws_plat_ntpclient_config(struct lws_context *context) 80d4afb5ceSopenharmony_ci{ 81d4afb5ceSopenharmony_ci#if defined(LWS_HAVE_GETENV) 82d4afb5ceSopenharmony_ci char *ntpsrv = getenv("LWS_NTP_SERVER"); 83d4afb5ceSopenharmony_ci 84d4afb5ceSopenharmony_ci if (ntpsrv && strlen(ntpsrv) < 64) { 85d4afb5ceSopenharmony_ci lws_system_blob_heap_append(lws_system_get_blob(context, 86d4afb5ceSopenharmony_ci LWS_SYSBLOB_TYPE_NTP_SERVER, 0), 87d4afb5ceSopenharmony_ci (const uint8_t *)ntpsrv, 88d4afb5ceSopenharmony_ci strlen(ntpsrv)); 89d4afb5ceSopenharmony_ci return 1; 90d4afb5ceSopenharmony_ci } 91d4afb5ceSopenharmony_ci#endif 92d4afb5ceSopenharmony_ci return 0; 93d4afb5ceSopenharmony_ci} 94