Skip to content

Commit eb1ac10

Browse files
swarrenigrr
authored andcommitted
Revert "ESP8266mDNS using the provided IP in the begin method (esp8266#2349)"
Manually specifying the AP IP isn't required; the next change will modify the MDNS code to correctly handle any combination of AP and STA modes, and correctly respond to requests on all active interfaces. This reverts commit b682d59.
1 parent 0291a6e commit eb1ac10

File tree

2 files changed

+15
-31
lines changed

2 files changed

+15
-31
lines changed

libraries/ESP8266mDNS/ESP8266mDNS.cpp

Lines changed: 11 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -146,39 +146,26 @@ MDNSResponder::~MDNSResponder() {
146146
}
147147
}
148148

149-
bool MDNSResponder::begin(const char* hostName){
150-
return _begin(hostName, 0, 120);
151-
}
152-
153-
bool MDNSResponder::begin(const char* hostName, IPAddress ip, uint32_t ttl){
154-
return _begin(hostName, ip, ttl);
155-
}
156-
157-
bool MDNSResponder::_begin(const char *hostName, uint32_t ip, uint32_t ttl){
158-
size_t n = strlen(hostName);
149+
bool MDNSResponder::begin(const char* hostname){
150+
size_t n = strlen(hostname);
159151
if (n > 63) { // max size for a single label.
160152
return false;
161153
}
162154

163-
_ip = ip;
164-
165155
// Copy in hostname characters as lowercase
166-
_hostName = hostName;
156+
_hostName = hostname;
167157
_hostName.toLowerCase();
168158

169159
// If instance name is not already set copy hostname to instance name
170-
if (_instanceName.equals("") ) _instanceName=hostName;
160+
if (_instanceName.equals("") ) _instanceName=hostname;
171161

172-
//only if the IP hasn't been set manually, use the events
173-
if (ip == 0) {
174-
_gotIPHandler = WiFi.onStationModeGotIP([this](const WiFiEventStationModeGotIP& event){
175-
_restart();
176-
});
162+
_gotIPHandler = WiFi.onStationModeGotIP([this](const WiFiEventStationModeGotIP& event){
163+
_restart();
164+
});
177165

178-
_disconnectedHandler = WiFi.onStationModeDisconnected([this](const WiFiEventStationModeDisconnected& event) {
179-
_restart();
180-
});
181-
}
166+
_disconnectedHandler = WiFi.onStationModeDisconnected([this](const WiFiEventStationModeDisconnected& event) {
167+
_restart();
168+
});
182169

183170
return _listen();
184171
}
@@ -459,11 +446,7 @@ uint16_t MDNSResponder::_getServicePort(char *name, char *proto){
459446

460447
uint32_t MDNSResponder::_getOurIp(){
461448
int mode = wifi_get_opmode();
462-
463-
//if has a manually set IP use this
464-
if(_ip){
465-
return _ip;
466-
} else if(mode & STATION_MODE){
449+
if(mode & STATION_MODE){
467450
struct ip_info staIpInfo;
468451
wifi_get_ip_info(STATION_IF, &staIpInfo);
469452
return staIpInfo.ip.addr;

libraries/ESP8266mDNS/ESP8266mDNS.h

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,9 @@ class MDNSResponder {
6363
~MDNSResponder();
6464
bool begin(const char* hostName);
6565
//for compatibility
66-
bool begin(const char* hostName, IPAddress ip, uint32_t ttl=120);
66+
bool begin(const char* hostName, IPAddress ip, uint32_t ttl=120){
67+
return begin(hostName);
68+
}
6769
void update();
6870

6971
void addService(char *service, char *proto, uint16_t port);
@@ -114,9 +116,8 @@ class MDNSResponder {
114116
bool _waitingForAnswers;
115117
WiFiEventHandler _disconnectedHandler;
116118
WiFiEventHandler _gotIPHandler;
117-
uint32_t _ip;
119+
118120

119-
bool _begin(const char* hostName, uint32_t ip, uint32_t ttl);
120121
uint32_t _getOurIp();
121122
uint16_t _getServicePort(char *service, char *proto);
122123
MDNSTxt * _getServiceTxt(char *name, char *proto);

0 commit comments

Comments
 (0)