Skip to content

Commit

Permalink
DNSServer: fix improper startup code in WiFi mode
Browse files Browse the repository at this point in the history
When running on WiFi-AP mode server's start() method returned true while in fact UDP listening socket was never created
Regression introduced in espressif#8760
Closes espressif#10330
  • Loading branch information
vortigont committed Sep 22, 2024
1 parent 7018cd1 commit f5b599e
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
5 changes: 4 additions & 1 deletion libraries/DNSServer/examples/CaptivePortal/CaptivePortal.ino
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
8 changes: 5 additions & 3 deletions libraries/DNSServer/src/DNSServer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down

0 comments on commit f5b599e

Please sign in to comment.