// When the name, address, port, and txtinfo for a service is found, FoundInstanceInfo() // enqueues a record for PrintServiceInfo() to print. // Note, a browsing application would *not* normally need to get all this information -- // all it needs is the name, to display to the user. // Finding out the address, port, and txtinfo should be deferred to the time that the user // actually needs to contact the service to use it. static void FoundInstanceInfo(mDNS *const m, ServiceInfoQuery *query) { SearcherServices *services = (SearcherServices *)query->ServiceInfoQueryContext; linkedServiceInfo *info = (linkedServiceInfo *)(query->info); if (query->info->ip.type == mDNSAddrType_IPv4) { mDNS_StopResolveService(m, query); // For this test code, one answer is sufficient OTLIFOEnqueue(&services->serviceinfolist, &info->link); OTFreeMem(query); } }
static void foobar_manage_service(mDNS *m, const ResourceRecord *answer, const domainlabel *name, bool add) { if (add) { mStatus status; service_info_query *siq = calloc(1, sizeof(*siq)); assert(siq != NULL); siq->next = service_info_query_list; service_info_query_list = siq; siq->info.name = answer->rdata->u.name; siq->info.InterfaceID = answer->InterfaceID; status = mDNS_StartResolveService(m, &siq->query, &siq->info, foobar_service_info, NULL); assert(status == mStatus_NoError); } else { service_info_query *cur = service_info_query_list; service_info_query *prev = cur; while (cur != NULL && !SameDomainLabel(&name->c[0], &cur->info.name.c[0])) { prev = cur; cur = cur->next; } if (cur != NULL) { if (prev != cur) { prev->next = cur->next; } else { service_info_query_list = cur->next; } mDNS_StopResolveService(m, &cur->query); free(cur); } } }