From 17ef47d6f29aa6ace32ed74e8d514bb7d0cf606d Mon Sep 17 00:00:00 2001 From: df Date: Sun, 26 Jul 2020 14:57:23 +0100 Subject: [PATCH] Add response to service meta-query (RFC6763 Section 10), following https://github.com/espressif/esp-idf/pull/340/files --- mdnsd.c | 35 +++++++++++++++++++++++------------ 1 file changed, 23 insertions(+), 12 deletions(-) diff --git a/mdnsd.c b/mdnsd.c index b6cc6ee..0472c6f 100644 --- a/mdnsd.c +++ b/mdnsd.c @@ -630,22 +630,34 @@ static int populate_probe(struct mdnsd *svr, struct rr_list **rr_head) static int populate_answers(struct mdnsd *svr, struct rr_list **rr_head, uint8_t *name, enum rr_type type) { int num_ans = 0; - // check if we have the records pthread_mutex_lock(&svr->data_lock); - struct rr_group *ans_grp = rr_group_find(svr->group, name); - if (ans_grp != NULL) { - // decide which records should go into answers - for (struct rr_list *n = ans_grp->rr; n; n = n->next) { - // exclude NSEC for RR_ANY - if (type == RR_ANY && n->e->type == RR_NSEC) - continue; - if ((type == n->e->type || type == RR_ANY) && cmp_nlabel(name, n->e->name) == 0) { - num_ans += rr_list_append(rr_head, n->e); + if (type == RR_PTR && 0 == cmp_nlabel(SERVICES_DNS_SD_NLABEL, name)) { + + // add answers for all services + for (struct rr_list *n = svr->services; n; n = n->next) { +// if (s->service->service && s->service->proto) + num_ans += rr_list_append(rr_head, n->e); + } + + } else { + + // check if we have the records + struct rr_group *ans_grp = rr_group_find(svr->group, name); + if (ans_grp != NULL) { + // decide which records should go into answers + for (struct rr_list *n = ans_grp->rr; n; n = n->next) { + // exclude NSEC for RR_ANY + if (type == RR_ANY && n->e->type == RR_NSEC) + continue; + + if ((type == n->e->type || type == RR_ANY) && cmp_nlabel(name, n->e->name) == 0) { + num_ans += rr_list_append(rr_head, n->e); + } } } - } + } pthread_mutex_unlock(&svr->data_lock); return num_ans; @@ -2341,7 +2353,6 @@ int mdnsd_discover_service(char *service_type, int discover_time_msec, struct md { int result = -1; struct timeval old_time, cur_time; - unsigned int time_diff; int try_count; int domain; char service_type_str[128];