提交 83810fa1 编写于 作者: H horihiro 提交者: Me No Dev

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

* add methods for getting TXTs.

* add methods for getting TXTs.
上级 8e4ebf49
......@@ -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;
......@@ -107,6 +107,10 @@ public:
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;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册