ESPmDNS: Add method for querying discovered service name (#10819)

* 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>
This commit is contained in:
stefan-sherwood 2025-01-07 16:53:43 -05:00 committed by GitHub
parent 51ef2a1d29
commit c23c786749
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 12 additions and 0 deletions

View file

@ -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));

View file

@ -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) {

View file

@ -110,6 +110,7 @@ public:
}
String hostname(int idx);
String instanceName(int idx);
IPAddress address(int idx);
IPAddress addressV6(int idx);
uint16_t port(int idx);