From 4d51978d389085643cffc8dcdb40ddc7cb4cf60a Mon Sep 17 00:00:00 2001 From: altelch Date: Sun, 1 Dec 2019 21:38:46 +0100 Subject: [PATCH 01/15] Make DNS resolution order selectable during runtime or compile time (only in dual stack mode). --- .../ESP8266WiFi/src/ESP8266WiFiGeneric.cpp | 41 +++++++++++++++++++ .../ESP8266WiFi/src/ESP8266WiFiGeneric.h | 3 ++ 2 files changed, 44 insertions(+) diff --git a/libraries/ESP8266WiFi/src/ESP8266WiFiGeneric.cpp b/libraries/ESP8266WiFi/src/ESP8266WiFiGeneric.cpp index 4b2eb54ce7..96d59669ed 100644 --- a/libraries/ESP8266WiFi/src/ESP8266WiFiGeneric.cpp +++ b/libraries/ESP8266WiFi/src/ESP8266WiFiGeneric.cpp @@ -617,7 +617,47 @@ int ESP8266WiFiGenericClass::hostByName(const char* aHostname, IPAddress& aResul } DEBUG_WIFI_GENERIC("[hostByName] request IP for: %s\n", aHostname); +#if LWIP_IPV4 && LWIP_IPV6 + err_t err = dns_gethostbyname_addrtype(aHostname, &addr, &wifi_dns_found_callback, &aResult,LWIP_DNS_ADDRTYPE_DEFAULT); +#else err_t err = dns_gethostbyname(aHostname, &addr, &wifi_dns_found_callback, &aResult); +#endif + if(err == ERR_OK) { + aResult = IPAddress(&addr); + } else if(err == ERR_INPROGRESS) { + _dns_lookup_pending = true; + delay(timeout_ms); + // will resume on timeout or when wifi_dns_found_callback fires + _dns_lookup_pending = false; + // will return here when dns_found_callback fires + if(aResult.isSet()) { + err = ERR_OK; + } + } + + if(err != 0) { + DEBUG_WIFI_GENERIC("[hostByName] Host: %s lookup error: %d!\n", aHostname, (int)err); + } else { + DEBUG_WIFI_GENERIC("[hostByName] Host: %s IP: %s\n", aHostname, aResult.toString().c_str()); + } + + return (err == ERR_OK) ? 1 : 0; +} + +#if LWIP_IPV4 && LWIP_IPV6 +int ESP8266WiFiGenericClass::hostByName(const char* aHostname, IPAddress& aResult, uint32_t timeout_ms, uint8_t resolveType) +{ + ip_addr_t addr; + aResult = static_cast(0); + + if(aResult.fromString(aHostname)) { + // Host name is a IP address use it! + DEBUG_WIFI_GENERIC("[hostByName] Host: %s is a IP!\n", aHostname); + return 1; + } + + DEBUG_WIFI_GENERIC("[hostByName] request IP for: %s\n", aHostname); + err_t err = dns_gethostbyname_addrtype(aHostname, &addr, &wifi_dns_found_callback, &aResult,resolveType & 3); // limit to defined types 0 -3 if(err == ERR_OK) { aResult = IPAddress(&addr); } else if(err == ERR_INPROGRESS) { @@ -639,6 +679,7 @@ int ESP8266WiFiGenericClass::hostByName(const char* aHostname, IPAddress& aResul return (err == ERR_OK) ? 1 : 0; } +#endif /** * DNS callback diff --git a/libraries/ESP8266WiFi/src/ESP8266WiFiGeneric.h b/libraries/ESP8266WiFi/src/ESP8266WiFiGeneric.h index 1f5ec5c995..718f3f089c 100644 --- a/libraries/ESP8266WiFi/src/ESP8266WiFiGeneric.h +++ b/libraries/ESP8266WiFi/src/ESP8266WiFiGeneric.h @@ -113,6 +113,9 @@ class ESP8266WiFiGenericClass { public: int hostByName(const char* aHostname, IPAddress& aResult); int hostByName(const char* aHostname, IPAddress& aResult, uint32_t timeout_ms); +#if LWIP_IPV4 && LWIP_IPV6 + int hostByName(const char* aHostname, IPAddress& aResult, uint32_t timeout_ms, uint8_t resolveType); +#endif bool getPersistent(); protected: From 7706e6697803c21c9f279ea694bed2a7c19540fd Mon Sep 17 00:00:00 2001 From: altelch Date: Wed, 4 Dec 2019 13:23:16 +0100 Subject: [PATCH 02/15] Extend IPv6 example to show usage of new hostByName function with selectable resolving order --- libraries/ESP8266WiFi/examples/IPv6/IPv6.ino | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/libraries/ESP8266WiFi/examples/IPv6/IPv6.ino b/libraries/ESP8266WiFi/examples/IPv6/IPv6.ino index 1c7b1c081c..7aee2e4ca7 100644 --- a/libraries/ESP8266WiFi/examples/IPv6/IPv6.ino +++ b/libraries/ESP8266WiFi/examples/IPv6/IPv6.ino @@ -28,6 +28,7 @@ #endif #define FQDN F("www.google.com") // with both IPv4 & IPv6 addresses +#define FQDN2 F("www.yahoo.com") // with both IPv4 & IPv6 addresses #define FQDN6 F("ipv6.google.com") // does not resolve in IPv4 #define STATUSDELAY_MS 10000 #define TCP_PORT 23 @@ -50,6 +51,19 @@ void fqdn(Print& out, const String& fqdn) { } } +void fqdn_rt(Print& out, const String& fqdn, resolveType) { + out.print(F("resolving ")); + out.print(fqdn); + out.print(F(": ")); + IPAddress result; + if (WiFi.hostByName(fqdn.c_str(), result), 10000, resolveType) { + result.printTo(out); + out.println(); + } else { + out.println(F("timeout or not found")); + } +} + void status(Print& out) { out.println(F("------------------------------")); out.println(ESP.getFullVersion()); @@ -85,7 +99,8 @@ void status(Print& out) { // an example is provided with a fqdn which does not resolve with IPv4 fqdn(out, FQDN); fqdn(out, FQDN6); - + fqdn_rt(out, FQDN, LWIP_DNS_ADDRTYPE_IPV4_IPV6); // IPv4 before IPv6 + fqdn_rt(out, FQDN2, LWIP_DNS_ADDRTYPE_IPV6_IPV4); // IPv6 before IPv4 out.println(F("------------------------------")); } From 4d507df2dc2cdb352218df8616860d43aaf3f0b8 Mon Sep 17 00:00:00 2001 From: Heiko Krupp Date: Wed, 4 Dec 2019 14:10:50 +0100 Subject: [PATCH 03/15] Fix function definition of fqdn_rt in IPv6.ino. --- libraries/ESP8266WiFi/examples/IPv6/IPv6.ino | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libraries/ESP8266WiFi/examples/IPv6/IPv6.ino b/libraries/ESP8266WiFi/examples/IPv6/IPv6.ino index 7aee2e4ca7..9014d7b350 100644 --- a/libraries/ESP8266WiFi/examples/IPv6/IPv6.ino +++ b/libraries/ESP8266WiFi/examples/IPv6/IPv6.ino @@ -51,7 +51,7 @@ void fqdn(Print& out, const String& fqdn) { } } -void fqdn_rt(Print& out, const String& fqdn, resolveType) { +void fqdn_rt(Print& out, const String& fqdn, uint8_t resolveType) { out.print(F("resolving ")); out.print(fqdn); out.print(F(": ")); From cab31c13d07bff5876755ff1a270b738e7685d40 Mon Sep 17 00:00:00 2001 From: Heiko Krupp Date: Wed, 4 Dec 2019 14:54:29 +0100 Subject: [PATCH 04/15] Fix function call. --- libraries/ESP8266WiFi/examples/IPv6/IPv6.ino | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libraries/ESP8266WiFi/examples/IPv6/IPv6.ino b/libraries/ESP8266WiFi/examples/IPv6/IPv6.ino index 9014d7b350..b8612d38e8 100644 --- a/libraries/ESP8266WiFi/examples/IPv6/IPv6.ino +++ b/libraries/ESP8266WiFi/examples/IPv6/IPv6.ino @@ -56,7 +56,7 @@ void fqdn_rt(Print& out, const String& fqdn, uint8_t resolveType) { out.print(fqdn); out.print(F(": ")); IPAddress result; - if (WiFi.hostByName(fqdn.c_str(), result), 10000, resolveType) { + if (WiFi.hostByName(fqdn.c_str(), result, 10000, resolveType) { result.printTo(out); out.println(); } else { From 6e9ff589214d400703ef539a3b6fae8eca5e3dee Mon Sep 17 00:00:00 2001 From: Heiko Krupp Date: Wed, 4 Dec 2019 15:28:16 +0100 Subject: [PATCH 05/15] Fix missing bracket... --- libraries/ESP8266WiFi/examples/IPv6/IPv6.ino | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libraries/ESP8266WiFi/examples/IPv6/IPv6.ino b/libraries/ESP8266WiFi/examples/IPv6/IPv6.ino index b8612d38e8..8a7b82c3fd 100644 --- a/libraries/ESP8266WiFi/examples/IPv6/IPv6.ino +++ b/libraries/ESP8266WiFi/examples/IPv6/IPv6.ino @@ -56,7 +56,7 @@ void fqdn_rt(Print& out, const String& fqdn, uint8_t resolveType) { out.print(fqdn); out.print(F(": ")); IPAddress result; - if (WiFi.hostByName(fqdn.c_str(), result, 10000, resolveType) { + if (WiFi.hostByName(fqdn.c_str(), result, 10000, resolveType)) { result.printTo(out); out.println(); } else { From 8d944d3cf4f59e0cd3af196ad28517e66eafcb5b Mon Sep 17 00:00:00 2001 From: Heiko Krupp Date: Wed, 4 Dec 2019 15:40:59 +0100 Subject: [PATCH 06/15] Only run if built with dual stack support --- libraries/ESP8266WiFi/examples/IPv6/IPv6.ino | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/libraries/ESP8266WiFi/examples/IPv6/IPv6.ino b/libraries/ESP8266WiFi/examples/IPv6/IPv6.ino index 8a7b82c3fd..70d2070f25 100644 --- a/libraries/ESP8266WiFi/examples/IPv6/IPv6.ino +++ b/libraries/ESP8266WiFi/examples/IPv6/IPv6.ino @@ -51,6 +51,7 @@ void fqdn(Print& out, const String& fqdn) { } } +#if LWIP_IPV4 && LWIP_IPV6 void fqdn_rt(Print& out, const String& fqdn, uint8_t resolveType) { out.print(F("resolving ")); out.print(fqdn); @@ -63,6 +64,7 @@ void fqdn_rt(Print& out, const String& fqdn, uint8_t resolveType) { out.println(F("timeout or not found")); } } +#endif void status(Print& out) { out.println(F("------------------------------")); @@ -99,8 +101,10 @@ void status(Print& out) { // an example is provided with a fqdn which does not resolve with IPv4 fqdn(out, FQDN); fqdn(out, FQDN6); +#if LWIP_IPV4 && LWIP_IPV6 fqdn_rt(out, FQDN, LWIP_DNS_ADDRTYPE_IPV4_IPV6); // IPv4 before IPv6 - fqdn_rt(out, FQDN2, LWIP_DNS_ADDRTYPE_IPV6_IPV4); // IPv6 before IPv4 + fqdn_rt(out, FQDN2, LWIP_DNS_ADDRTYPE_IPV6_IPV4); // IPv6 before IPv4 +#endif out.println(F("------------------------------")); } From d546877958149b530b7bde229d2f016c4060b61c Mon Sep 17 00:00:00 2001 From: altelch Date: Sun, 1 Dec 2019 21:38:46 +0100 Subject: [PATCH 07/15] Make DNS resolution order selectable during runtime or compile time (only in dual stack mode). --- .../ESP8266WiFi/src/ESP8266WiFiGeneric.cpp | 41 +++++++++++++++++++ .../ESP8266WiFi/src/ESP8266WiFiGeneric.h | 3 ++ 2 files changed, 44 insertions(+) diff --git a/libraries/ESP8266WiFi/src/ESP8266WiFiGeneric.cpp b/libraries/ESP8266WiFi/src/ESP8266WiFiGeneric.cpp index 4b2eb54ce7..96d59669ed 100644 --- a/libraries/ESP8266WiFi/src/ESP8266WiFiGeneric.cpp +++ b/libraries/ESP8266WiFi/src/ESP8266WiFiGeneric.cpp @@ -617,7 +617,47 @@ int ESP8266WiFiGenericClass::hostByName(const char* aHostname, IPAddress& aResul } DEBUG_WIFI_GENERIC("[hostByName] request IP for: %s\n", aHostname); +#if LWIP_IPV4 && LWIP_IPV6 + err_t err = dns_gethostbyname_addrtype(aHostname, &addr, &wifi_dns_found_callback, &aResult,LWIP_DNS_ADDRTYPE_DEFAULT); +#else err_t err = dns_gethostbyname(aHostname, &addr, &wifi_dns_found_callback, &aResult); +#endif + if(err == ERR_OK) { + aResult = IPAddress(&addr); + } else if(err == ERR_INPROGRESS) { + _dns_lookup_pending = true; + delay(timeout_ms); + // will resume on timeout or when wifi_dns_found_callback fires + _dns_lookup_pending = false; + // will return here when dns_found_callback fires + if(aResult.isSet()) { + err = ERR_OK; + } + } + + if(err != 0) { + DEBUG_WIFI_GENERIC("[hostByName] Host: %s lookup error: %d!\n", aHostname, (int)err); + } else { + DEBUG_WIFI_GENERIC("[hostByName] Host: %s IP: %s\n", aHostname, aResult.toString().c_str()); + } + + return (err == ERR_OK) ? 1 : 0; +} + +#if LWIP_IPV4 && LWIP_IPV6 +int ESP8266WiFiGenericClass::hostByName(const char* aHostname, IPAddress& aResult, uint32_t timeout_ms, uint8_t resolveType) +{ + ip_addr_t addr; + aResult = static_cast(0); + + if(aResult.fromString(aHostname)) { + // Host name is a IP address use it! + DEBUG_WIFI_GENERIC("[hostByName] Host: %s is a IP!\n", aHostname); + return 1; + } + + DEBUG_WIFI_GENERIC("[hostByName] request IP for: %s\n", aHostname); + err_t err = dns_gethostbyname_addrtype(aHostname, &addr, &wifi_dns_found_callback, &aResult,resolveType & 3); // limit to defined types 0 -3 if(err == ERR_OK) { aResult = IPAddress(&addr); } else if(err == ERR_INPROGRESS) { @@ -639,6 +679,7 @@ int ESP8266WiFiGenericClass::hostByName(const char* aHostname, IPAddress& aResul return (err == ERR_OK) ? 1 : 0; } +#endif /** * DNS callback diff --git a/libraries/ESP8266WiFi/src/ESP8266WiFiGeneric.h b/libraries/ESP8266WiFi/src/ESP8266WiFiGeneric.h index 1f5ec5c995..718f3f089c 100644 --- a/libraries/ESP8266WiFi/src/ESP8266WiFiGeneric.h +++ b/libraries/ESP8266WiFi/src/ESP8266WiFiGeneric.h @@ -113,6 +113,9 @@ class ESP8266WiFiGenericClass { public: int hostByName(const char* aHostname, IPAddress& aResult); int hostByName(const char* aHostname, IPAddress& aResult, uint32_t timeout_ms); +#if LWIP_IPV4 && LWIP_IPV6 + int hostByName(const char* aHostname, IPAddress& aResult, uint32_t timeout_ms, uint8_t resolveType); +#endif bool getPersistent(); protected: From 50f79b80e78c8e3c71b7224fc3370e4c4f8fa9a7 Mon Sep 17 00:00:00 2001 From: altelch Date: Wed, 4 Dec 2019 13:23:16 +0100 Subject: [PATCH 08/15] Extend IPv6 example to show usage of new hostByName function with selectable resolving order --- libraries/ESP8266WiFi/examples/IPv6/IPv6.ino | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/libraries/ESP8266WiFi/examples/IPv6/IPv6.ino b/libraries/ESP8266WiFi/examples/IPv6/IPv6.ino index 1c7b1c081c..7aee2e4ca7 100644 --- a/libraries/ESP8266WiFi/examples/IPv6/IPv6.ino +++ b/libraries/ESP8266WiFi/examples/IPv6/IPv6.ino @@ -28,6 +28,7 @@ #endif #define FQDN F("www.google.com") // with both IPv4 & IPv6 addresses +#define FQDN2 F("www.yahoo.com") // with both IPv4 & IPv6 addresses #define FQDN6 F("ipv6.google.com") // does not resolve in IPv4 #define STATUSDELAY_MS 10000 #define TCP_PORT 23 @@ -50,6 +51,19 @@ void fqdn(Print& out, const String& fqdn) { } } +void fqdn_rt(Print& out, const String& fqdn, resolveType) { + out.print(F("resolving ")); + out.print(fqdn); + out.print(F(": ")); + IPAddress result; + if (WiFi.hostByName(fqdn.c_str(), result), 10000, resolveType) { + result.printTo(out); + out.println(); + } else { + out.println(F("timeout or not found")); + } +} + void status(Print& out) { out.println(F("------------------------------")); out.println(ESP.getFullVersion()); @@ -85,7 +99,8 @@ void status(Print& out) { // an example is provided with a fqdn which does not resolve with IPv4 fqdn(out, FQDN); fqdn(out, FQDN6); - + fqdn_rt(out, FQDN, LWIP_DNS_ADDRTYPE_IPV4_IPV6); // IPv4 before IPv6 + fqdn_rt(out, FQDN2, LWIP_DNS_ADDRTYPE_IPV6_IPV4); // IPv6 before IPv4 out.println(F("------------------------------")); } From 198f2ebc52abfe0c65dcc1b3edb7b165a1b70700 Mon Sep 17 00:00:00 2001 From: altelch Date: Wed, 4 Dec 2019 14:08:55 +0100 Subject: [PATCH 09/15] Fix function definition of fqdn_rt in IPv6 example. --- libraries/ESP8266WiFi/examples/IPv6/IPv6.ino | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libraries/ESP8266WiFi/examples/IPv6/IPv6.ino b/libraries/ESP8266WiFi/examples/IPv6/IPv6.ino index 7aee2e4ca7..9014d7b350 100644 --- a/libraries/ESP8266WiFi/examples/IPv6/IPv6.ino +++ b/libraries/ESP8266WiFi/examples/IPv6/IPv6.ino @@ -51,7 +51,7 @@ void fqdn(Print& out, const String& fqdn) { } } -void fqdn_rt(Print& out, const String& fqdn, resolveType) { +void fqdn_rt(Print& out, const String& fqdn, uint8_t resolveType) { out.print(F("resolving ")); out.print(fqdn); out.print(F(": ")); From 700247b343690055d28731c93ec2a232e48a43b6 Mon Sep 17 00:00:00 2001 From: altelch Date: Thu, 5 Dec 2019 11:03:34 +0100 Subject: [PATCH 10/15] Implement enum class for resolve type --- libraries/ESP8266WiFi/examples/IPv6/IPv6.ino | 4 ++-- .../ESP8266WiFi/src/ESP8266WiFiGeneric.cpp | 21 +++++++++++++++---- .../ESP8266WiFi/src/ESP8266WiFiGeneric.h | 12 ++++++++++- 3 files changed, 30 insertions(+), 7 deletions(-) diff --git a/libraries/ESP8266WiFi/examples/IPv6/IPv6.ino b/libraries/ESP8266WiFi/examples/IPv6/IPv6.ino index 12a28f7809..103100a387 100644 --- a/libraries/ESP8266WiFi/examples/IPv6/IPv6.ino +++ b/libraries/ESP8266WiFi/examples/IPv6/IPv6.ino @@ -101,8 +101,8 @@ void status(Print& out) { fqdn(out, FQDN); fqdn(out, FQDN6); #if LWIP_IPV4 && LWIP_IPV6 - fqdn_rt(out, FQDN, LWIP_DNS_ADDRTYPE_IPV4_IPV6); // IPv4 before IPv6 - fqdn_rt(out, FQDN2, LWIP_DNS_ADDRTYPE_IPV6_IPV4); // IPv6 before IPv4 + fqdn_rt(out, FQDN, DNSResolveType::DNS_ADDRTYPE_IPV4_IPV6); // IPv4 before IPv6 + fqdn_rt(out, FQDN2, DNSResolveType::DNS_ADDRTYPE_IPV6_IPV4); // IPv6 before IPv4 #endif out.println(F("------------------------------")); } diff --git a/libraries/ESP8266WiFi/src/ESP8266WiFiGeneric.cpp b/libraries/ESP8266WiFi/src/ESP8266WiFiGeneric.cpp index 96d59669ed..89edd7029a 100644 --- a/libraries/ESP8266WiFi/src/ESP8266WiFiGeneric.cpp +++ b/libraries/ESP8266WiFi/src/ESP8266WiFiGeneric.cpp @@ -608,7 +608,7 @@ int ESP8266WiFiGenericClass::hostByName(const char* aHostname, IPAddress& aResul int ESP8266WiFiGenericClass::hostByName(const char* aHostname, IPAddress& aResult, uint32_t timeout_ms) { ip_addr_t addr; - aResult = static_cast(0); + aResult = static_cast(INADDR_NONE); if(aResult.fromString(aHostname)) { // Host name is a IP address use it! @@ -645,10 +645,10 @@ int ESP8266WiFiGenericClass::hostByName(const char* aHostname, IPAddress& aResul } #if LWIP_IPV4 && LWIP_IPV6 -int ESP8266WiFiGenericClass::hostByName(const char* aHostname, IPAddress& aResult, uint32_t timeout_ms, uint8_t resolveType) +int ESP8266WiFiGenericClass::hostByName(const char* aHostname, IPAddress& aResult, uint32_t timeout_ms, DNSResolveType resolveType) { ip_addr_t addr; - aResult = static_cast(0); + aResult = static_cast(INADDR_NONE); if(aResult.fromString(aHostname)) { // Host name is a IP address use it! @@ -657,7 +657,20 @@ int ESP8266WiFiGenericClass::hostByName(const char* aHostname, IPAddress& aResul } DEBUG_WIFI_GENERIC("[hostByName] request IP for: %s\n", aHostname); - err_t err = dns_gethostbyname_addrtype(aHostname, &addr, &wifi_dns_found_callback, &aResult,resolveType & 3); // limit to defined types 0 -3 + switch(resolveType) + { + // Use selected addrtype + case DNSResolveType::DNS_ADDRTYPE_IPV4: + case DNSResolveType::DNS_ADDRTYPE_IPV6: + case DNSResolveType::DNS_ADDRTYPE_IPV4_IPV6: + case DNSResolveType::DNS_ADDRTYPE_IPV6_IPV4: + err_t err = dns_gethostbyname_addrtype(aHostname, &addr, &wifi_dns_found_callback, &aResult, resolveType); + break; + default: + err_t err = dns_gethostbyname_addrtype(aHostname, &addr, &wifi_dns_found_callback, &aResult, LWIP_DNS_ADDRTYPE_DEFAULT); // If illegal type, use default. + break; + } + if(err == ERR_OK) { aResult = IPAddress(&addr); } else if(err == ERR_INPROGRESS) { diff --git a/libraries/ESP8266WiFi/src/ESP8266WiFiGeneric.h b/libraries/ESP8266WiFi/src/ESP8266WiFiGeneric.h index 718f3f089c..a82a220d0a 100644 --- a/libraries/ESP8266WiFi/src/ESP8266WiFiGeneric.h +++ b/libraries/ESP8266WiFi/src/ESP8266WiFiGeneric.h @@ -42,6 +42,16 @@ typedef std::shared_ptr WiFiEventHandler; typedef void (*WiFiEventCb)(WiFiEvent_t); +#if LWIP_IPV4 && LWIP_IPV6 +enum class DNSResolveType : uint8_t +{ + DNS_ADDRTYPE_IPV4 = LWIP_DNS_ADDRTYPE_IPV4, + DNS_ADDRTYPE_IPV6 = LWIP_DNS_ADDRTYPE_IPV6, + DNS_ADDRTYPE_IPV4_IPV6 = LWIP_DNS_ADDRTYPE_IPV4_IPV6, + DNS_ADDRTYPE_IPV6_IPV4 = LWIP_DNS_ADDRTYPE_IPV6_IPV4 +}; +#endif + struct WiFiState; class ESP8266WiFiGenericClass { @@ -114,7 +124,7 @@ class ESP8266WiFiGenericClass { int hostByName(const char* aHostname, IPAddress& aResult); int hostByName(const char* aHostname, IPAddress& aResult, uint32_t timeout_ms); #if LWIP_IPV4 && LWIP_IPV6 - int hostByName(const char* aHostname, IPAddress& aResult, uint32_t timeout_ms, uint8_t resolveType); + int hostByName(const char* aHostname, IPAddress& aResult, uint32_t timeout_ms, DNSResolveType_t resolveType); #endif bool getPersistent(); From 5bd5cd6d40465119f6f5a93cbb8927e68b48126c Mon Sep 17 00:00:00 2001 From: altelch Date: Thu, 5 Dec 2019 11:06:52 +0100 Subject: [PATCH 11/15] Fix example IPv6.ino --- libraries/ESP8266WiFi/examples/IPv6/IPv6.ino | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libraries/ESP8266WiFi/examples/IPv6/IPv6.ino b/libraries/ESP8266WiFi/examples/IPv6/IPv6.ino index 103100a387..4e3c4d82cb 100644 --- a/libraries/ESP8266WiFi/examples/IPv6/IPv6.ino +++ b/libraries/ESP8266WiFi/examples/IPv6/IPv6.ino @@ -51,7 +51,7 @@ void fqdn(Print& out, const String& fqdn) { } #if LWIP_IPV4 && LWIP_IPV6 -void fqdn_rt(Print& out, const String& fqdn, uint8_t resolveType) { +void fqdn_rt(Print& out, const String& fqdn, DNSResolveType resolveType) { out.print(F("resolving ")); out.print(fqdn); out.print(F(": ")); From 198cc1fc5e2d05b5b8ae0106bd130c5552ba0fd2 Mon Sep 17 00:00:00 2001 From: altelch Date: Thu, 5 Dec 2019 11:08:44 +0100 Subject: [PATCH 12/15] Fix typedef in ESP8266WiFiGeneric.h function call --- libraries/ESP8266WiFi/src/ESP8266WiFiGeneric.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libraries/ESP8266WiFi/src/ESP8266WiFiGeneric.h b/libraries/ESP8266WiFi/src/ESP8266WiFiGeneric.h index a82a220d0a..2c69e39fcc 100644 --- a/libraries/ESP8266WiFi/src/ESP8266WiFiGeneric.h +++ b/libraries/ESP8266WiFi/src/ESP8266WiFiGeneric.h @@ -124,7 +124,7 @@ class ESP8266WiFiGenericClass { int hostByName(const char* aHostname, IPAddress& aResult); int hostByName(const char* aHostname, IPAddress& aResult, uint32_t timeout_ms); #if LWIP_IPV4 && LWIP_IPV6 - int hostByName(const char* aHostname, IPAddress& aResult, uint32_t timeout_ms, DNSResolveType_t resolveType); + int hostByName(const char* aHostname, IPAddress& aResult, uint32_t timeout_ms, DNSResolveType resolveType); #endif bool getPersistent(); From 37f3267e4b805bf27e36fee35635aa90043689e0 Mon Sep 17 00:00:00 2001 From: altelch Date: Thu, 5 Dec 2019 12:04:14 +0100 Subject: [PATCH 13/15] Change enum class definition to not depend on lwip/dns.h --- libraries/ESP8266WiFi/src/ESP8266WiFiGeneric.h | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/libraries/ESP8266WiFi/src/ESP8266WiFiGeneric.h b/libraries/ESP8266WiFi/src/ESP8266WiFiGeneric.h index 2c69e39fcc..e90893da27 100644 --- a/libraries/ESP8266WiFi/src/ESP8266WiFiGeneric.h +++ b/libraries/ESP8266WiFi/src/ESP8266WiFiGeneric.h @@ -45,10 +45,10 @@ typedef void (*WiFiEventCb)(WiFiEvent_t); #if LWIP_IPV4 && LWIP_IPV6 enum class DNSResolveType : uint8_t { - DNS_ADDRTYPE_IPV4 = LWIP_DNS_ADDRTYPE_IPV4, - DNS_ADDRTYPE_IPV6 = LWIP_DNS_ADDRTYPE_IPV6, - DNS_ADDRTYPE_IPV4_IPV6 = LWIP_DNS_ADDRTYPE_IPV4_IPV6, - DNS_ADDRTYPE_IPV6_IPV4 = LWIP_DNS_ADDRTYPE_IPV6_IPV4 + DNS_ADDRTYPE_IPV4, // LWIP_DNS_ADDRTYPE_IPV4 = 0 + DNS_ADDRTYPE_IPV6, // LWIP_DNS_ADDRTYPE_IPV6 = 1 + DNS_ADDRTYPE_IPV4_IPV6, // LWIP_DNS_ADDRTYPE_IPV4_IPV6 = 2 + DNS_ADDRTYPE_IPV6_IPV4 // LWIP_DNS_ADDRTYPE_IPV6_IPV4 = 3 }; #endif From 7751792122f0f8dae83442a3775d7356d271e8f2 Mon Sep 17 00:00:00 2001 From: altelch Date: Thu, 5 Dec 2019 21:28:18 +0100 Subject: [PATCH 14/15] Move err_t err definition outside switch. Fix typecast. --- libraries/ESP8266WiFi/examples/IPv6/IPv6.ino | 4 ++-- libraries/ESP8266WiFi/src/ESP8266WiFiGeneric.cpp | 13 +++++++------ libraries/ESP8266WiFi/src/ESP8266WiFiGeneric.h | 11 ++++++----- 3 files changed, 15 insertions(+), 13 deletions(-) diff --git a/libraries/ESP8266WiFi/examples/IPv6/IPv6.ino b/libraries/ESP8266WiFi/examples/IPv6/IPv6.ino index 4e3c4d82cb..e1d693756c 100644 --- a/libraries/ESP8266WiFi/examples/IPv6/IPv6.ino +++ b/libraries/ESP8266WiFi/examples/IPv6/IPv6.ino @@ -101,8 +101,8 @@ void status(Print& out) { fqdn(out, FQDN); fqdn(out, FQDN6); #if LWIP_IPV4 && LWIP_IPV6 - fqdn_rt(out, FQDN, DNSResolveType::DNS_ADDRTYPE_IPV4_IPV6); // IPv4 before IPv6 - fqdn_rt(out, FQDN2, DNSResolveType::DNS_ADDRTYPE_IPV6_IPV4); // IPv6 before IPv4 + fqdn_rt(out, FQDN, DNSResolveType::DNS_AddrType_IPv4_IPv6); // IPv4 before IPv6 + fqdn_rt(out, FQDN2, DNSResolveType::DNS_AddrType_IPv6_IPv4); // IPv6 before IPv4 #endif out.println(F("------------------------------")); } diff --git a/libraries/ESP8266WiFi/src/ESP8266WiFiGeneric.cpp b/libraries/ESP8266WiFi/src/ESP8266WiFiGeneric.cpp index 89edd7029a..41d771fb6a 100644 --- a/libraries/ESP8266WiFi/src/ESP8266WiFiGeneric.cpp +++ b/libraries/ESP8266WiFi/src/ESP8266WiFiGeneric.cpp @@ -648,6 +648,7 @@ int ESP8266WiFiGenericClass::hostByName(const char* aHostname, IPAddress& aResul int ESP8266WiFiGenericClass::hostByName(const char* aHostname, IPAddress& aResult, uint32_t timeout_ms, DNSResolveType resolveType) { ip_addr_t addr; + err_t err; aResult = static_cast(INADDR_NONE); if(aResult.fromString(aHostname)) { @@ -660,14 +661,14 @@ int ESP8266WiFiGenericClass::hostByName(const char* aHostname, IPAddress& aResul switch(resolveType) { // Use selected addrtype - case DNSResolveType::DNS_ADDRTYPE_IPV4: - case DNSResolveType::DNS_ADDRTYPE_IPV6: - case DNSResolveType::DNS_ADDRTYPE_IPV4_IPV6: - case DNSResolveType::DNS_ADDRTYPE_IPV6_IPV4: - err_t err = dns_gethostbyname_addrtype(aHostname, &addr, &wifi_dns_found_callback, &aResult, resolveType); + case DNSResolveType::DNS_AddrType_IPv4: + case DNSResolveType::DNS_AddrType_IPv6: + case DNSResolveType::DNS_AddrType_IPv4_IPv6: + case DNSResolveType::DNS_AddrType_IPv6_IPv4: + err = dns_gethostbyname_addrtype(aHostname, &addr, &wifi_dns_found_callback, &aResult, (uint8_t) resolveType); break; default: - err_t err = dns_gethostbyname_addrtype(aHostname, &addr, &wifi_dns_found_callback, &aResult, LWIP_DNS_ADDRTYPE_DEFAULT); // If illegal type, use default. + err = dns_gethostbyname_addrtype(aHostname, &addr, &wifi_dns_found_callback, &aResult, LWIP_DNS_ADDRTYPE_DEFAULT); // If illegal type, use default. break; } diff --git a/libraries/ESP8266WiFi/src/ESP8266WiFiGeneric.h b/libraries/ESP8266WiFi/src/ESP8266WiFiGeneric.h index e90893da27..9e973a3bf8 100644 --- a/libraries/ESP8266WiFi/src/ESP8266WiFiGeneric.h +++ b/libraries/ESP8266WiFi/src/ESP8266WiFiGeneric.h @@ -43,12 +43,13 @@ typedef std::shared_ptr WiFiEventHandler; typedef void (*WiFiEventCb)(WiFiEvent_t); #if LWIP_IPV4 && LWIP_IPV6 -enum class DNSResolveType : uint8_t + +enum class DNSResolveType: uint8_t { - DNS_ADDRTYPE_IPV4, // LWIP_DNS_ADDRTYPE_IPV4 = 0 - DNS_ADDRTYPE_IPV6, // LWIP_DNS_ADDRTYPE_IPV6 = 1 - DNS_ADDRTYPE_IPV4_IPV6, // LWIP_DNS_ADDRTYPE_IPV4_IPV6 = 2 - DNS_ADDRTYPE_IPV6_IPV4 // LWIP_DNS_ADDRTYPE_IPV6_IPV4 = 3 + DNS_AddrType_IPv4 = 0, // LWIP_DNS_ADDRTYPE_IPV4 = 0 + DNS_AddrType_IPv6, // LWIP_DNS_ADDRTYPE_IPV6 = 1 + DNS_AddrType_IPv4_IPv6, // LWIP_DNS_ADDRTYPE_IPV4_IPV6 = 2 + DNS_AddrType_IPv6_IPv4 // LWIP_DNS_ADDRTYPE_IPV6_IPV4 = 3 }; #endif From 32e7e87f66b414ac60821071f9cb0a747ee3ec23 Mon Sep 17 00:00:00 2001 From: altelch Date: Sat, 7 Dec 2019 10:37:46 +0100 Subject: [PATCH 15/15] Always define DNSResolveType as pio test otherwise failes even if the enum class isn't used. --- libraries/ESP8266WiFi/examples/IPv6/IPv6.ino | 4 ++-- libraries/ESP8266WiFi/src/ESP8266WiFiGeneric.h | 3 --- 2 files changed, 2 insertions(+), 5 deletions(-) diff --git a/libraries/ESP8266WiFi/examples/IPv6/IPv6.ino b/libraries/ESP8266WiFi/examples/IPv6/IPv6.ino index e1d693756c..48bd5a449b 100644 --- a/libraries/ESP8266WiFi/examples/IPv6/IPv6.ino +++ b/libraries/ESP8266WiFi/examples/IPv6/IPv6.ino @@ -26,8 +26,8 @@ #define STAPSK "your-password" #endif -#define FQDN F("www.google.com") // with both IPv4 & IPv6 addresses -#define FQDN2 F("www.yahoo.com") // with both IPv4 & IPv6 addresses +#define FQDN F("www.google.com") // with both IPv4 & IPv6 addresses +#define FQDN2 F("www.yahoo.com") // with both IPv4 & IPv6 addresses #define FQDN6 F("ipv6.google.com") // does not resolve in IPv4 #define STATUSDELAY_MS 10000 #define TCP_PORT 23 diff --git a/libraries/ESP8266WiFi/src/ESP8266WiFiGeneric.h b/libraries/ESP8266WiFi/src/ESP8266WiFiGeneric.h index 9e973a3bf8..b5f307aeda 100644 --- a/libraries/ESP8266WiFi/src/ESP8266WiFiGeneric.h +++ b/libraries/ESP8266WiFi/src/ESP8266WiFiGeneric.h @@ -42,8 +42,6 @@ typedef std::shared_ptr WiFiEventHandler; typedef void (*WiFiEventCb)(WiFiEvent_t); -#if LWIP_IPV4 && LWIP_IPV6 - enum class DNSResolveType: uint8_t { DNS_AddrType_IPv4 = 0, // LWIP_DNS_ADDRTYPE_IPV4 = 0 @@ -51,7 +49,6 @@ enum class DNSResolveType: uint8_t DNS_AddrType_IPv4_IPv6, // LWIP_DNS_ADDRTYPE_IPV4_IPV6 = 2 DNS_AddrType_IPv6_IPv4 // LWIP_DNS_ADDRTYPE_IPV6_IPV4 = 3 }; -#endif struct WiFiState;