mDNS resolution for *.local fixes #16269

"Add user control over DNS timeout reducing blocking"  c988ba1645 created DnsClient so that a timeout can be used to prevent blocking on ESP32, but it can't do one-shot mDNS queries. Use WiFi.hostByName () for those.
This commit is contained in:
rogg 2022-08-20 23:17:05 -07:00 committed by GitHub
parent 204289e1ab
commit 16c39aab9e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -807,6 +807,17 @@ void wifiKeepAlive(void) {
#endif // ESP8266
bool WifiHostByName(const char* aHostname, IPAddress& aResult) {
// DnsClient can't do one-shot mDNS queries so use WiFi.hostByName() for *.local
size_t hostname_len = strlen(aHostname);
if (strstr(aHostname, ".local") == &aHostname[hostname_len] - 6) {
if (WiFi.hostByName(aHostname, aResult)) {
// Host name resolved
if (0xFFFFFFFF != (uint32_t)aResult) {
return true;
}
return false;
}
}
// Use this instead of WiFi.hostByName or connect(host_name,.. to block less if DNS server is not found
uint32_t dns_address = (!TasmotaGlobal.global_state.eth_down) ? Settings->eth_ipv4_address[3] : Settings->ipv4_address[3];
DnsClient.begin((IPAddress)dns_address);