add support for TXT records in mDNS query responses (#1480)

* add methods for getting TXTs.

* add methods for getting TXTs.
This commit is contained in:
horihiro 2018-06-19 00:18:50 +09:00 committed by Me No Dev
parent 8e4ebf49de
commit 83810fa156
2 changed files with 51 additions and 0 deletions

View File

@ -285,4 +285,51 @@ uint16_t MDNSResponder::port(int idx) {
return result->port; 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; MDNSResponder MDNS;

View File

@ -107,6 +107,10 @@ public:
IPAddress IP(int idx); IPAddress IP(int idx);
IPv6Address IPv6(int idx); IPv6Address IPv6(int idx);
uint16_t port(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: private:
String _hostname; String _hostname;