Skip to content

Commit 8c3e1d0

Browse files
committed
Merge pull request esp8266#1451 from probonopd/patch-2
advertise all hosted services
2 parents 27de48b + b2a9296 commit 8c3e1d0

File tree

2 files changed

+17
-0
lines changed

2 files changed

+17
-0
lines changed

libraries/ESP8266mDNS/ESP8266mDNS.cpp

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -366,6 +366,10 @@ void MDNSResponder::_parsePacket(){
366366
memmove(protoName, protoName+1, protoNameLen);
367367
protoNameLen--;
368368
protoParsed = true;
369+
} else if(strcmp("services", serviceName) == 0 && strcmp("_dns-sd", protoName) == 0){
370+
_conn->flush();
371+
advertiseServices();
372+
return;
369373
} else {
370374
#ifdef MDNS_DEBUG_ERR
371375
Serial.printf("ERR_PROTO: %s\n", protoName);
@@ -479,6 +483,18 @@ void MDNSResponder::enableArduino(uint16_t port, bool auth){
479483
addServiceTxt("arduino", "tcp", "auth_upload", (auth) ? "yes":"no");
480484
}
481485

486+
size_t MDNSResponder::advertiseServices(){
487+
MDNSService* servicePtr;
488+
size_t i = 0;
489+
for (servicePtr = _services; servicePtr; servicePtr = servicePtr->_next) {
490+
if(servicePtr->_port > 0){
491+
_reply(0x0F, servicePtr->_name, servicePtr->_proto, servicePtr->_port);
492+
i++;
493+
}
494+
}
495+
return i;
496+
}
497+
482498
void MDNSResponder::_reply(uint8_t replyMask, char * service, char *proto, uint16_t port){
483499
int i;
484500
if(replyMask == 0) return;

libraries/ESP8266mDNS/ESP8266mDNS.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,7 @@ class MDNSResponder {
104104
uint16_t _getServiceTxtLen(char *name, char *proto);
105105
void _parsePacket();
106106
void _reply(uint8_t replyMask, char * service, char *proto, uint16_t port);
107+
size_t advertiseServices(); // advertise all hosted services
107108
};
108109

109110
extern MDNSResponder MDNS;

0 commit comments

Comments
 (0)