Skip to content

Commit

Permalink
ESPmDNS: Add method for querying discovered service name (#10819)
Browse files Browse the repository at this point in the history
* Add method for querying service name

* Added implementation for getting service name

* Update mDNS-SD_Extended example to include service name

* ci(pre-commit): Apply automatic fixes

---------

Co-authored-by: pre-commit-ci-lite[bot] <117423508+pre-commit-ci-lite[bot]@users.noreply.github.com>
  • Loading branch information
1 parent 51ef2a1 commit c23c786
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,8 @@ void browseService(const char *service, const char *proto) {
Serial.print(" ");
Serial.print(i + 1);
Serial.print(": ");
Serial.print(MDNS.instanceName(i));
Serial.print(" - ");
Serial.print(MDNS.hostname(i));
Serial.print(" (");
Serial.print(MDNS.address(i));
Expand Down
9 changes: 9 additions & 0 deletions libraries/ESPmDNS/src/ESPmDNS.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -299,6 +299,15 @@ String MDNSResponder::hostname(int idx) {
return String(result->hostname);
}

String MDNSResponder::instanceName(int idx) {
mdns_result_t *result = _getResult(idx);
if (!result) {
log_e("Result %d not found", idx);
return String();
}
return String(result->instance_name);
}

IPAddress MDNSResponder::address(int idx) {
mdns_result_t *result = _getResult(idx);
if (!result) {
Expand Down
1 change: 1 addition & 0 deletions libraries/ESPmDNS/src/ESPmDNS.h
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ class MDNSResponder {
}

String hostname(int idx);
String instanceName(int idx);
IPAddress address(int idx);
IPAddress addressV6(int idx);
uint16_t port(int idx);
Expand Down

0 comments on commit c23c786

Please sign in to comment.