From f5b599ead1702a8212a6ff4354ce17b90ee941f7 Mon Sep 17 00:00:00 2001 From: Emil Muratov Date: Mon, 23 Sep 2024 01:26:17 +0900 Subject: [PATCH 1/2] DNSServer: fix improper startup code in WiFi mode When running on WiFi-AP mode server's start() method returned true while in fact UDP listening socket was never created Regression introduced in #8760 Closes #10330 --- .../DNSServer/examples/CaptivePortal/CaptivePortal.ino | 5 ++++- libraries/DNSServer/src/DNSServer.cpp | 8 +++++--- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/libraries/DNSServer/examples/CaptivePortal/CaptivePortal.ino b/libraries/DNSServer/examples/CaptivePortal/CaptivePortal.ino index f5de8aa9b57..a485fcaa13f 100644 --- a/libraries/DNSServer/examples/CaptivePortal/CaptivePortal.ino +++ b/libraries/DNSServer/examples/CaptivePortal/CaptivePortal.ino @@ -39,7 +39,10 @@ void setup() { // by default DNSServer is started serving any "*" domain name. It will reply // AccessPoint's IP to all DNS request (this is required for Captive Portal detection) - dnsServer.start(); + if ( dnsServer.start() ) + Serial.println("Started DNS server in captive portal-mode"); + else + Serial.println("Err: Can't start DNS server!"); // serve a simple root page server.on("/", handleRoot); diff --git a/libraries/DNSServer/src/DNSServer.cpp b/libraries/DNSServer/src/DNSServer.cpp index 69e41092dc5..a9081ba72d2 100644 --- a/libraries/DNSServer/src/DNSServer.cpp +++ b/libraries/DNSServer/src/DNSServer.cpp @@ -22,10 +22,12 @@ bool DNSServer::start() { #if SOC_WIFI_SUPPORTED if (WiFi.getMode() & WIFI_AP) { _resolvedIP = WiFi.softAPIP(); - return true; - } + } else + return false; // won't run if WiFi is not in AP mode, or no WiFi +#else + return false; // for other non WiFi-AP networking an overloaded method must be used to get device's IP + // start(uint16_t port, const String &domainName, const IPAddress &resolvedIP) #endif - return false; // won't run if WiFi is not in AP mode } _udp.close(); From a7c21df0d5f55beffed41a27b034722de66a87ca Mon Sep 17 00:00:00 2001 From: "pre-commit-ci-lite[bot]" <117423508+pre-commit-ci-lite[bot]@users.noreply.github.com> Date: Wed, 25 Sep 2024 20:51:49 +0000 Subject: [PATCH 2/2] ci(pre-commit): Apply automatic fixes --- .../DNSServer/examples/CaptivePortal/CaptivePortal.ino | 5 +++-- libraries/DNSServer/src/DNSServer.cpp | 9 +++++---- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/libraries/DNSServer/examples/CaptivePortal/CaptivePortal.ino b/libraries/DNSServer/examples/CaptivePortal/CaptivePortal.ino index a485fcaa13f..d956dc14ad3 100644 --- a/libraries/DNSServer/examples/CaptivePortal/CaptivePortal.ino +++ b/libraries/DNSServer/examples/CaptivePortal/CaptivePortal.ino @@ -39,10 +39,11 @@ void setup() { // by default DNSServer is started serving any "*" domain name. It will reply // AccessPoint's IP to all DNS request (this is required for Captive Portal detection) - if ( dnsServer.start() ) + if (dnsServer.start()) { Serial.println("Started DNS server in captive portal-mode"); - else + } else { Serial.println("Err: Can't start DNS server!"); + } // serve a simple root page server.on("/", handleRoot); diff --git a/libraries/DNSServer/src/DNSServer.cpp b/libraries/DNSServer/src/DNSServer.cpp index a9081ba72d2..28cf89d6ede 100644 --- a/libraries/DNSServer/src/DNSServer.cpp +++ b/libraries/DNSServer/src/DNSServer.cpp @@ -22,11 +22,12 @@ bool DNSServer::start() { #if SOC_WIFI_SUPPORTED if (WiFi.getMode() & WIFI_AP) { _resolvedIP = WiFi.softAPIP(); - } else - return false; // won't run if WiFi is not in AP mode, or no WiFi + } else { + return false; // won't run if WiFi is not in AP mode, or no WiFi + } #else - return false; // for other non WiFi-AP networking an overloaded method must be used to get device's IP - // start(uint16_t port, const String &domainName, const IPAddress &resolvedIP) + return false; // for other non WiFi-AP networking an overloaded method must be used to get device's IP + // start(uint16_t port, const String &domainName, const IPAddress &resolvedIP) #endif }