Skip to content

add support for TXT records in mDNS query responses #1480

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jun 18, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 47 additions & 0 deletions libraries/ESPmDNS/src/ESPmDNS.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -285,4 +285,51 @@ uint16_t MDNSResponder::port(int idx) {
return result->port;
}

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

bool MDNSResponder::hasTxt(int idx, const char * key) {
mdns_result_t * result = _getResult(idx);
if(!result){
log_e("Result %d not found", idx);
return false;
}
int i = 0;
while(i < result->txt_count) {
if (strcmp(result->txt[i].key, key) == 0) return true;
i++;
}
return false;
}

String MDNSResponder::txt(int idx, const char * key) {
mdns_result_t * result = _getResult(idx);
if(!result){
log_e("Result %d not found", idx);
return "";
}
int i = 0;
while(i < result->txt_count) {
if (strcmp(result->txt[i].key, key) == 0) return result->txt[i].value;
i++;
}
return "";
}

String MDNSResponder::txt(int idx, int txtIdx) {
mdns_result_t * result = _getResult(idx);
if(!result){
log_e("Result %d not found", idx);
return "";
}
if (txtIdx >= result->txt_count) return "";
return result->txt[txtIdx].value;
}

MDNSResponder MDNS;
4 changes: 4 additions & 0 deletions libraries/ESPmDNS/src/ESPmDNS.h
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,10 @@ class MDNSResponder {
IPAddress IP(int idx);
IPv6Address IPv6(int idx);
uint16_t port(int idx);
int numTxt(int idx);
bool hasTxt(int idx, const char * key);
String txt(int idx, const char * key);
String txt(int idx, int txtIdx);

private:
String _hostname;
Expand Down