File tree Expand file tree Collapse file tree 2 files changed +51
-0
lines changed Expand file tree Collapse file tree 2 files changed +51
-0
lines changed Original file line number Diff line number Diff line change @@ -285,4 +285,51 @@ uint16_t MDNSResponder::port(int idx) {
285285 return result->port ;
286286}
287287
288+ int MDNSResponder::numTxt (int idx) {
289+ mdns_result_t * result = _getResult (idx);
290+ if (!result){
291+ log_e (" Result %d not found" , idx);
292+ return 0 ;
293+ }
294+ return result->txt_count ;
295+ }
296+
297+ bool MDNSResponder::hasTxt (int idx, const char * key) {
298+ mdns_result_t * result = _getResult (idx);
299+ if (!result){
300+ log_e (" Result %d not found" , idx);
301+ return false ;
302+ }
303+ int i = 0 ;
304+ while (i < result->txt_count ) {
305+ if (strcmp (result->txt [i].key , key) == 0 ) return true ;
306+ i++;
307+ }
308+ return false ;
309+ }
310+
311+ String MDNSResponder::txt (int idx, const char * key) {
312+ mdns_result_t * result = _getResult (idx);
313+ if (!result){
314+ log_e (" Result %d not found" , idx);
315+ return " " ;
316+ }
317+ int i = 0 ;
318+ while (i < result->txt_count ) {
319+ if (strcmp (result->txt [i].key , key) == 0 ) return result->txt [i].value ;
320+ i++;
321+ }
322+ return " " ;
323+ }
324+
325+ String MDNSResponder::txt (int idx, int txtIdx) {
326+ mdns_result_t * result = _getResult (idx);
327+ if (!result){
328+ log_e (" Result %d not found" , idx);
329+ return " " ;
330+ }
331+ if (txtIdx >= result->txt_count ) return " " ;
332+ return result->txt [txtIdx].value ;
333+ }
334+
288335MDNSResponder MDNS;
Original file line number Diff line number Diff line change @@ -107,6 +107,10 @@ class MDNSResponder {
107107 IPAddress IP (int idx);
108108 IPv6Address IPv6 (int idx);
109109 uint16_t port (int idx);
110+ int numTxt (int idx);
111+ bool hasTxt (int idx, const char * key);
112+ String txt (int idx, const char * key);
113+ String txt (int idx, int txtIdx);
110114
111115private:
112116 String _hostname;
You can’t perform that action at this time.
0 commit comments