Fix WifiHostByName for .local

This commit is contained in:
Theo Arends 2022-08-21 11:46:43 +02:00
parent 17d0382fe4
commit e301734b2c

View File

@ -673,12 +673,22 @@ void WifiEnable(void) {
Wifi.counter = 1;
}
//#ifdef ESP8266
//#include <sntp.h> // sntp_servermode_dhcp()
//#endif // ESP8266
void WifiConnect(void)
{
if (!Settings->flag4.network_wifi) { return; }
WifiSetState(0);
WifiSetOutputPower();
//#ifdef ESP8266
// https://github.com/arendst/Tasmota/issues/16061#issuecomment-1216970170
// sntp_servermode_dhcp(0);
//#endif // ESP8266
WiFi.persistent(false); // Solve possible wifi init errors
Wifi.status = 0;
Wifi.retry_init = WIFI_RETRY_OFFSET_SEC + (ESP_getChipId() & 0xF); // Add extra delay to stop overrun by simultanous re-connects
@ -809,23 +819,23 @@ void wifiKeepAlive(void) {
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 (strstr_P(aHostname, PSTR(".local")) == &aHostname[hostname_len] - 6) {
if (WiFi.hostByName(aHostname, aResult)) {
// Host name resolved
if (0xFFFFFFFF != (uint32_t)aResult) {
return true;
}
return false;
// Host name resolved
if (0xFFFFFFFF != (uint32_t)aResult) {
return true;
}
}
} else {
// 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);
if (1 == DnsClient.getHostByName(aHostname, aResult)) {
return true;
}
}
// 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);
if (DnsClient.getHostByName(aHostname, aResult) != 1) {
AddLog(LOG_LEVEL_DEBUG, PSTR("DNS: Unable to resolve '%s'"), aHostname);
return false;
}
return true;
AddLog(LOG_LEVEL_DEBUG, PSTR("DNS: Unable to resolve '%s'"), aHostname);
return false;
}
bool WifiDnsPresent(const char* aHostname) {