static void DNSSD_API browse_reply(DNSServiceRef client, const DNSServiceFlags flags, uint32_t ifIndex, DNSServiceErrorType errorCode, const char *replyName, const char *replyType, const char *replyDomain, void *context) { #if 0 std::cout << "name=" << replyName << " type=" << replyType << " domain=" << replyDomain << std::endl; #endif #if 1 NetServiceBrowser *self = (NetServiceBrowser *)context; const bool moreComing = bool(flags & kDNSServiceFlagsMoreComing); if(!self->getListener()) return; char if_name[128]; if_indextoname(ifIndex, if_name); if(flags & kDNSServiceFlagsAdd) { self->addService(replyDomain,replyType,replyName, if_name, moreComing); } else { self->removeService(replyDomain,replyType,replyName, moreComing); } #endif }
int main (int argc, char * const argv[]) { NetServiceBrowser browser; BrowserListener listener; browser.setListener(&listener); browser.searchForServicesOfType("_http._tcp", "local"); return getchar(); }
static void browse_reply(DNSServiceRef client, const DNSServiceFlags flags, uint32_t ifIndex, DNSServiceErrorType errorCode, const char *replyName, const char *replyType, const char *replyDomain, void *context) { NetServiceBrowser *self = (NetServiceBrowser *)context; const bool moreComing = bool(flags & kDNSServiceFlagsMoreComing); if(!self->getListener()) return; if(flags & kDNSServiceFlagsAdd) { self->addService(replyDomain,replyType,replyName, moreComing); } else { self->removeService(replyDomain,replyType,replyName, moreComing); } }