mirror of
https://github.com/esp8266/Arduino.git
synced 2025-09-06 19:08:12 +03:00
Revert "ESP8266mDNS using the provided IP in the begin method (#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 b682d597c5
.
This commit is contained in:
committed by
Ivan Grokhotkov
parent
0291a6e32a
commit
eb1ac103e4
@@ -146,31 +146,19 @@ MDNSResponder::~MDNSResponder() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool MDNSResponder::begin(const char* hostName){
|
bool MDNSResponder::begin(const char* hostname){
|
||||||
return _begin(hostName, 0, 120);
|
size_t n = strlen(hostname);
|
||||||
}
|
|
||||||
|
|
||||||
bool MDNSResponder::begin(const char* hostName, IPAddress ip, uint32_t ttl){
|
|
||||||
return _begin(hostName, ip, ttl);
|
|
||||||
}
|
|
||||||
|
|
||||||
bool MDNSResponder::_begin(const char *hostName, uint32_t ip, uint32_t ttl){
|
|
||||||
size_t n = strlen(hostName);
|
|
||||||
if (n > 63) { // max size for a single label.
|
if (n > 63) { // max size for a single label.
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
_ip = ip;
|
|
||||||
|
|
||||||
// Copy in hostname characters as lowercase
|
// Copy in hostname characters as lowercase
|
||||||
_hostName = hostName;
|
_hostName = hostname;
|
||||||
_hostName.toLowerCase();
|
_hostName.toLowerCase();
|
||||||
|
|
||||||
// If instance name is not already set copy hostname to instance name
|
// If instance name is not already set copy hostname to instance name
|
||||||
if (_instanceName.equals("") ) _instanceName=hostName;
|
if (_instanceName.equals("") ) _instanceName=hostname;
|
||||||
|
|
||||||
//only if the IP hasn't been set manually, use the events
|
|
||||||
if (ip == 0) {
|
|
||||||
_gotIPHandler = WiFi.onStationModeGotIP([this](const WiFiEventStationModeGotIP& event){
|
_gotIPHandler = WiFi.onStationModeGotIP([this](const WiFiEventStationModeGotIP& event){
|
||||||
_restart();
|
_restart();
|
||||||
});
|
});
|
||||||
@@ -178,7 +166,6 @@ bool MDNSResponder::_begin(const char *hostName, uint32_t ip, uint32_t ttl){
|
|||||||
_disconnectedHandler = WiFi.onStationModeDisconnected([this](const WiFiEventStationModeDisconnected& event) {
|
_disconnectedHandler = WiFi.onStationModeDisconnected([this](const WiFiEventStationModeDisconnected& event) {
|
||||||
_restart();
|
_restart();
|
||||||
});
|
});
|
||||||
}
|
|
||||||
|
|
||||||
return _listen();
|
return _listen();
|
||||||
}
|
}
|
||||||
@@ -459,11 +446,7 @@ uint16_t MDNSResponder::_getServicePort(char *name, char *proto){
|
|||||||
|
|
||||||
uint32_t MDNSResponder::_getOurIp(){
|
uint32_t MDNSResponder::_getOurIp(){
|
||||||
int mode = wifi_get_opmode();
|
int mode = wifi_get_opmode();
|
||||||
|
if(mode & STATION_MODE){
|
||||||
//if has a manually set IP use this
|
|
||||||
if(_ip){
|
|
||||||
return _ip;
|
|
||||||
} else if(mode & STATION_MODE){
|
|
||||||
struct ip_info staIpInfo;
|
struct ip_info staIpInfo;
|
||||||
wifi_get_ip_info(STATION_IF, &staIpInfo);
|
wifi_get_ip_info(STATION_IF, &staIpInfo);
|
||||||
return staIpInfo.ip.addr;
|
return staIpInfo.ip.addr;
|
||||||
|
@@ -63,7 +63,9 @@ public:
|
|||||||
~MDNSResponder();
|
~MDNSResponder();
|
||||||
bool begin(const char* hostName);
|
bool begin(const char* hostName);
|
||||||
//for compatibility
|
//for compatibility
|
||||||
bool begin(const char* hostName, IPAddress ip, uint32_t ttl=120);
|
bool begin(const char* hostName, IPAddress ip, uint32_t ttl=120){
|
||||||
|
return begin(hostName);
|
||||||
|
}
|
||||||
void update();
|
void update();
|
||||||
|
|
||||||
void addService(char *service, char *proto, uint16_t port);
|
void addService(char *service, char *proto, uint16_t port);
|
||||||
@@ -114,9 +116,8 @@ private:
|
|||||||
bool _waitingForAnswers;
|
bool _waitingForAnswers;
|
||||||
WiFiEventHandler _disconnectedHandler;
|
WiFiEventHandler _disconnectedHandler;
|
||||||
WiFiEventHandler _gotIPHandler;
|
WiFiEventHandler _gotIPHandler;
|
||||||
uint32_t _ip;
|
|
||||||
|
|
||||||
bool _begin(const char* hostName, uint32_t ip, uint32_t ttl);
|
|
||||||
uint32_t _getOurIp();
|
uint32_t _getOurIp();
|
||||||
uint16_t _getServicePort(char *service, char *proto);
|
uint16_t _getServicePort(char *service, char *proto);
|
||||||
MDNSTxt * _getServiceTxt(char *name, char *proto);
|
MDNSTxt * _getServiceTxt(char *name, char *proto);
|
||||||
|
Reference in New Issue
Block a user