OSStatus CSecondPage::StartBrowse() { OSStatus err; // // setup the DNS-SD browsing // err = DNSServiceBrowse( &m_pdlBrowser, 0, 0, kPDLServiceType, NULL, OnBrowse, this ); require_noerr( err, exit ); err = StartOperation( m_pdlBrowser ); require_noerr( err, exit ); err = DNSServiceBrowse( &m_lprBrowser, 0, 0, kLPRServiceType, NULL, OnBrowse, this ); require_noerr( err, exit ); err = StartOperation( m_lprBrowser ); require_noerr( err, exit ); err = DNSServiceBrowse( &m_ippBrowser, 0, 0, kIPPServiceType, NULL, OnBrowse, this ); require_noerr( err, exit ); err = StartOperation( m_ippBrowser ); require_noerr( err, exit ); exit: return err; }
void ProcessDNSMessages() { static boolean initialized; if ( !initialized ) { initialized = true; DNSServiceErrorType err = DNSServiceBrowse ( &browseRef, 0, /* flags */ 0, /* interface */ serviceName, NULL, /* domain */ DNSServiceBrowseReplyCallback, NULL /* context */ ); if ( err != kDNSServiceErr_NoError ) { printf( "DNSServiceBrowse error\n" ); return; } } // poll the socket for updates int socket = DNSServiceRefSockFD( browseRef ); if ( socket <= 0 ) { return; } fd_set set; FD_ZERO( &set ); FD_SET( socket, &set ); struct timeval tv; memset( &tv, 0, sizeof( tv ) ); if ( select( socket+1, &set, NULL, NULL, &tv ) > 0 ) { DNSServiceProcessResult( browseRef ); } }
// Called in a thread static void * OW_Browse_Bonjour(void * v) { struct connection_in * in = v ; DNSServiceErrorType dnserr; DETACH_THREAD; MONITOR_RLOCK ; dnserr = DNSServiceBrowse(&in->master.browse.bonjour_browse, 0, 0, "_owserver._tcp", NULL, BrowseBack, NULL); if (dnserr != kDNSServiceErr_NoError) { LEVEL_CONNECT("DNSServiceBrowse error = %d", dnserr); MONITOR_RUNLOCK ; return VOID_RETURN ; } // Blocks, which is why this is in it's own thread while (DNSServiceProcessResult(in->master.browse.bonjour_browse) == kDNSServiceErr_NoError) { //printf("DNSServiceProcessResult ref %ld\n",(long int)rs->sref) ; continue; } DNSServiceRefDeallocate(in->master.browse.bonjour_browse); in->master.browse.bonjour_browse = 0 ; MONITOR_RUNLOCK ; return VOID_RETURN; }
static VALUE dnssd_service_browse(VALUE self, VALUE _flags, VALUE _interface, VALUE _type, VALUE _domain) { const char *type; const char *domain = NULL; DNSServiceFlags flags = 0; uint32_t interface = 0; DNSServiceErrorType e; DNSServiceRef *client; dnssd_utf8_cstr(_type, type); if (!NIL_P(_domain)) dnssd_utf8_cstr(_domain, domain); if (!NIL_P(_flags)) flags = (DNSServiceFlags)NUM2ULONG(_flags); if (!NIL_P(_interface)) interface = (uint32_t)NUM2ULONG(_interface); get(cDNSSDService, self, DNSServiceRef, client); e = DNSServiceBrowse(client, flags, interface, type, domain, dnssd_service_browse_reply, (void *)self); dnssd_check_error_code(e); return self; }
int main(AVAHI_GCC_UNUSED int argc, AVAHI_GCC_UNUSED char*argv[]) { DNSServiceRef ref1, ref2, ref3, ref4 = NULL; DNSServiceRegister(&ref1, 0, 0, "simple", "_simple._tcp", NULL, NULL, 4711, 0, NULL, NULL, NULL); DNSServiceRegister(&ref2, 0, 0, "subtype #1", "_simple._tcp,_subtype1", NULL, NULL, 4711, 0, NULL, NULL, NULL); DNSServiceRegister(&ref3, 0, 0, "subtype #2", "_simple._tcp,_subtype1,_subtype2", NULL, NULL, 4711, 0, NULL, NULL, NULL); DNSServiceRegister(&ref4, 0, 0, "subtype #3", "_simple._tcp,,", NULL, NULL, 4711, 0, NULL, NULL, NULL); assert(!ref4); DNSServiceRegister(&ref4, 0, 0, "subtype #3", "", NULL, NULL, 4711, 0, NULL, NULL, NULL); assert(!ref4); DNSServiceRegister(&ref4, 0, 0, "subtype #3", ",", NULL, NULL, 4711, 0, NULL, NULL, NULL); assert(!ref4); DNSServiceRegister(&ref4, 0, 0, "subtype #3", ",,", NULL, NULL, 4711, 0, NULL, NULL, NULL); assert(!ref4); DNSServiceBrowse(&ref4, 0, 0, "_simple._tcp,_gurke", NULL, reply, NULL); sleep(20); DNSServiceRefDeallocate(ref1); DNSServiceRefDeallocate(ref2); DNSServiceRefDeallocate(ref3); DNSServiceRefDeallocate(ref4); return 0; }
/** * Browse for a service. The callback will be called * when it's fully resloved and queried */ static gboolean g_mdns_browse (GMDNS *mdns, gchar *service, GMDNSFunc callback, gpointer user_data) { DNSServiceErrorType err; DNSServiceRef client; GMDNSUserData *ud; g_return_val_if_fail (!mdns->browse_ud, FALSE); ud = g_new0 (GMDNSUserData, 1); err = DNSServiceBrowse (&client, 0, kDNSServiceInterfaceIndexAny, service, 0, browse_reply, ud); if (err != kDNSServiceErr_NoError) { g_warning ("Couldn't setup mDNS poller"); return FALSE; } g_mdns_poll_add (mdns, ud, client); mdns->callback = callback; mdns->user_data = user_data; mdns->browse_ud = ud; return TRUE; }
AutoDiscoveryClientImpl::AutoDiscoveryClientImpl(const std::string& type, DiscoveredServicesCallback* cb) { _cb = cb; DNSServiceErrorType err = DNSServiceBrowse(&client, 0, kDNSServiceInterfaceIndexAny, type.c_str(), "", browse_reply, this); if (!client || err != kDNSServiceErr_NoError) { OSG_WARN << "AutoDiscoveryImpl :: DNSServiceBrowse call failed " << (long int)err << std::endl; } }
/***************************************************************************** * NetBrowserInfoCreate * - * The method creates a NetBrowserInfo Object and initalizes it. *****************************************************************************/ NetBrowserInfo* NetBrowserInfoCreate(CFStringRef serviceType, CFStringRef domain, void* context) { NetBrowserInfo* outObj = NULL; DNSServiceRef browserRef = NULL; char* cServiceType = NULL; char* cDomain = NULL; Boolean success = true; CFIndex serviceSize = CFStringGetMaximumSizeForEncoding(CFStringGetLength(serviceType), kCFStringEncodingUTF8); cServiceType = calloc(serviceSize, 1); success = CFStringGetCString(serviceType, cServiceType, serviceSize, kCFStringEncodingUTF8); if (domain) { CFIndex domainSize = CFStringGetMaximumSizeForEncoding(CFStringGetLength(domain), kCFStringEncodingUTF8); cDomain = calloc(serviceSize, 1); success = success && CFStringGetCString(domain, cDomain, domainSize, kCFStringEncodingUTF8); } if (!success) { fprintf(stderr, "LaunchEvent has badly encoded service type or domain.\n"); free(cServiceType); if (cDomain) free(cDomain); return NULL; } DNSServiceErrorType err = DNSServiceBrowse(&browserRef, 0, 0, cServiceType, cDomain, ServiceBrowserCallback, context); if (err != kDNSServiceErr_NoError) { fprintf(stderr, "Failed to create browser for %s, %s\n", cServiceType, cDomain); free(cServiceType); if (cDomain) free(cDomain); return NULL; } DNSServiceSetDispatchQueue(browserRef, dispatch_get_main_queue()); outObj = malloc(sizeof(NetBrowserInfo)); outObj->refCount = 1; outObj->browserRef = browserRef; free(cServiceType); if (cDomain) free(cDomain); return outObj; }
int main() { OSStatus err; void *tempmem; DNSServiceRef sdRef; DNSServiceErrorType dse; SIOUXSettings.asktosaveonclose = false; SIOUXSettings.userwindowtitle = "\pMulticast DNS Searcher"; SIOUXSettings.rows = 40; SIOUXSettings.columns = 160; printf("DNS-SD Search Client\n\n"); printf("This software reports errors using MacsBug breaks,\n"); printf("so if you don't have MacsBug installed your Mac may crash.\n\n"); printf("******************************************************************************\n\n"); if (DNSServiceBrowse == (void*)kUnresolvedCFragSymbolAddress) { printf("Before you can use mDNS/DNS-SD clients, you need to place the \n"); printf("\"Multicast DNS & DNS-SD\" Extension in the Extensions Folder and restart\n"); return(-1); } err = InitOpenTransport(); if (err) { printf("InitOpenTransport failed %d", err); return(err); } // Make sure OT has a large enough memory pool for us to draw from at OTNotifier (interrupt) time tempmem = OTAllocMem(0x10000); if (tempmem) OTFreeMem(tempmem); else printf("**** Warning: OTAllocMem couldn't pre-allocate 64K for us.\n"); services.serviceinfolist.fHead = NULL; services.headerPrinted = false; services.lostRecords = false; printf("Sending mDNS service lookup queries and waiting for responses...\n\n"); dse = DNSServiceBrowse(&sdRef, 0, 0, "_http._tcp", "", FoundInstance, &services); if (dse == kDNSServiceErr_NoError) { while (!YieldSomeTime(35)) { if (services.serviceinfolist.fHead) PrintServiceInfo(&services); if (services.lostRecords) { services.lostRecords = false; printf("**** Warning: Out of memory: Records have been missed.\n"); } } } DNSServiceRefDeallocate(sdRef); CloseOpenTransport(); return(0); }
FskErr KprZeroconfPlatformBrowserStart(KprZeroconfBrowser self) { FskErr err = kFskErrNone; KprZeroconfPlatformBrowser browser = self->platform; if (!browser->service) { DNSServiceErrorType error; DNSServiceRef serviceRef; if (self->serviceType) error = DNSServiceBrowse(&serviceRef, 0, 0, self->serviceType, NULL, KprZeroconfPlatformBrowseCallback, self); else error = DNSServiceBrowse(&serviceRef, 0, 0, "_services._dns-sd._udp.", NULL, KprZeroconfPlatformWildcardCallback, self); if (error != kDNSServiceErr_NoError) { bailIfError(kFskErrNetworkErr); } bailIfError(KprZeroconfPlatformServiceNew(&browser->service, NULL, serviceRef, NULL, 0)); } bail: return err; }
/* void browse (); */ NS_IMETHODIMP CBFBROWSE::Browse() { Log(ToNewUnicode(NS_LITERAL_STRING("Browse Started"))); if (!mCallback) return NS_ERROR_FAILURE; DNSServiceErrorType err = kDNSServiceErr_Unknown; err = DNSServiceBrowse(&mSdRef, 0, mInterfaceIndex, ToNewUTF8String(mRegistrationType), ToNewUTF8String(mRegistrationDomain), (DNSServiceBrowseReply) Callback, this); if (err != kDNSServiceErr_NoError) return NS_ERROR_FAILURE; StartTimer(); return NS_OK; }
int browse(void) { DNSServiceErrorType err; CFSocketContext ctx = { 0, NULL, NULL, NULL, NULL }; err = DNSServiceBrowse(&nfsinfo.sdref, 0, 0, "_nfs._tcp", NULL, browser_callback, NULL); if (err != kDNSServiceErr_NoError) return (1); ctx.info = (void*)&nfsinfo; nfsinfo.sockref = CFSocketCreateWithNative(kCFAllocatorDefault, DNSServiceRefSockFD(nfsinfo.sdref), kCFSocketReadCallBack, socket_callback, &ctx); if (!nfsinfo.sockref) return (1); nfsinfo.rls = CFSocketCreateRunLoopSource(kCFAllocatorDefault, nfsinfo.sockref, 1); CFRunLoopAddSource(CFRunLoopGetCurrent(), nfsinfo.rls, kCFRunLoopDefaultMode); /* For backwards compatibility, browse for "mountd" services too */ err = DNSServiceBrowse(&mountdinfo.sdref, 0, 0, "_mountd._tcp", NULL, browser_callback, NULL); if (err != kDNSServiceErr_NoError) return (1); ctx.info = (void*)&mountdinfo; mountdinfo.sockref = CFSocketCreateWithNative(kCFAllocatorDefault, DNSServiceRefSockFD(mountdinfo.sdref), kCFSocketReadCallBack, socket_callback, &ctx); if (!mountdinfo.sockref) return (1); mountdinfo.rls = CFSocketCreateRunLoopSource(kCFAllocatorDefault, mountdinfo.sockref, 1); CFRunLoopAddSource(CFRunLoopGetCurrent(), mountdinfo.rls, kCFRunLoopDefaultMode); CFRunLoopRun(); CFRelease(nfsinfo.rls); CFSocketInvalidate(nfsinfo.sockref); CFRelease(nfsinfo.sockref); DNSServiceRefDeallocate(nfsinfo.sdref); CFRelease(mountdinfo.rls); CFSocketInvalidate(mountdinfo.sockref); CFRelease(mountdinfo.sockref); DNSServiceRefDeallocate(mountdinfo.sdref); return (0); }
STDMETHODIMP CDNSSD::Browse(DNSSDFlags flags, ULONG ifIndex, BSTR regtype, BSTR domain, IBrowseListener* listener, IDNSSDService** browser ) { CComObject<CDNSSDService> * object = NULL; std::string regtypeUTF8; std::string domainUTF8; DNSServiceRef sref = NULL; DNSServiceErrorType err = 0; HRESULT hr = 0; BOOL ok; // Initialize *browser = NULL; // Convert BSTR params to utf8 ok = BSTRToUTF8( regtype, regtypeUTF8 ); require_action( ok, exit, err = kDNSServiceErr_BadParam ); ok = BSTRToUTF8( domain, domainUTF8 ); require_action( ok, exit, err = kDNSServiceErr_BadParam ); try { object = new CComObject<CDNSSDService>(); } catch ( ... ) { object = NULL; } require_action( object != NULL, exit, err = kDNSServiceErr_NoMemory ); hr = object->FinalConstruct(); require_action( hr == S_OK, exit, err = kDNSServiceErr_Unknown ); object->AddRef(); err = DNSServiceBrowse( &sref, flags, ifIndex, regtypeUTF8.c_str(), domainUTF8.c_str(), ( DNSServiceBrowseReply ) &BrowseReply, object ); require_noerr( err, exit ); object->SetServiceRef( sref ); object->SetListener( listener ); err = object->Run(); require_noerr( err, exit ); *browser = object; exit: if ( err && object ) { object->Release(); } return err; }
BonjourDiscovery::BonjourDiscovery() : ServiceDiscovery() { thread = NULL; sdRef = NULL; DNSServiceErrorType error = DNSServiceBrowse(&sdRef, 0, kDNSServiceInterfaceIndexAny, "_astro._tcp", NULL, discover::browsereply_callback, this); if (error != kDNSServiceErr_NoError) { debug(LOG_ERR, DEBUG_LOG, 0, "browser failed: %d", error); throw std::runtime_error("cannot create browser"); } assert(sdRef != NULL); debug(LOG_DEBUG, DEBUG_LOG, 0, "DNSServiceBrowse started"); }
DNSServiceErrorType DNSSDPluginAPI::browse_init(DNSServiceRef* sdref, uint32_t ifnum, const std::string& regtype, const std::string& domain, void* context) { return DNSServiceBrowse(sdref, 0, ifnum, regtype.c_str(), domain.c_str(), DNSSDPluginAPI::browse_callback, context); }
int mdns_browse(char *regtype, int family, mdns_browse_cb cb, enum mdns_options flags) { struct mdns_browser *mb; DNSServiceErrorType err; DPRINTF(E_DBG, L_MDNS, "Adding service browser for type %s\n", regtype); CHECK_NULL(L_MDNS, mb = calloc(1, sizeof(*mb))); mb->flags = flags; mb->cb = cb; /* flags are ignored in DNS-SD implementation */ switch(family) { case AF_UNSPEC: mb->protocol = kDNSServiceProtocol_IPv4 | kDNSServiceProtocol_IPv6; break; case AF_INET: mb->protocol = kDNSServiceProtocol_IPv4; break; case AF_INET6: mb->protocol = kDNSServiceProtocol_IPv6; break; default: DPRINTF(E_LOG, L_MDNS, "Unrecognized protocol family %d.\n", family); return mdns_browser_free(mb); } mb->regtype = strdup(regtype); if (!mb->regtype) { DPRINTF(E_LOG, L_MDNS, "Out of memory creating service browser.\n"); return mdns_browser_free(mb); } mb->sdref = mdns_sdref_main; err = DNSServiceBrowse(&(mb->sdref), kDNSServiceFlagsShareConnection, 0, regtype, NULL, mdns_browse_callback, mb); if (err != kDNSServiceErr_NoError) { DPRINTF(E_LOG, L_MDNS, "Failed to create service browser.\n"); mb->sdref = NULL; return mdns_browser_free(mb); } mb->next = mdns_browsers; mdns_browsers = mb; return 0; }
bool CZeroconfBrowserMDNS::doAddServiceType(const std::string& fcr_service_type) { DNSServiceErrorType err; DNSServiceRef browser = NULL; #if !defined(HAS_MDNS_EMBEDDED) if(m_browser == NULL) { err = DNSServiceCreateConnection(&m_browser); if (err != kDNSServiceErr_NoError) { CLog::Log(LOGERROR, "ZeroconfBrowserMDNS: DNSServiceCreateConnection failed with error = %ld", (int) err); return false; } #if defined(TARGET_WINDOWS_DESKTOP) err = WSAAsyncSelect( (SOCKET) DNSServiceRefSockFD( m_browser ), g_hWnd, BONJOUR_BROWSER_EVENT, FD_READ | FD_CLOSE ); if (err != kDNSServiceErr_NoError) CLog::Log(LOGERROR, "ZeroconfBrowserMDNS: WSAAsyncSelect failed with error = %ld", (int) err); #elif defined(TARGET_WINDOWS_STORE) // need to modify this code to use WSAEventSelect since WSAAsyncSelect is not supported CLog::Log(LOGERROR, "%s is not implemented for TARGET_WINDOWS_STORE", __FUNCTION__); #endif // TARGET_WINDOWS_STORE } #endif //!HAS_MDNS_EMBEDDED { CSingleLock lock(m_data_guard); browser = m_browser; err = DNSServiceBrowse(&browser, kDNSServiceFlagsShareConnection, kDNSServiceInterfaceIndexAny, fcr_service_type.c_str(), NULL, BrowserCallback, this); } if( err != kDNSServiceErr_NoError ) { if (browser) DNSServiceRefDeallocate(browser); CLog::Log(LOGERROR, "ZeroconfBrowserMDNS: DNSServiceBrowse returned (error = %ld)", (int) err); return false; } //store the browser { CSingleLock lock(m_data_guard); m_service_browsers.insert(std::make_pair(fcr_service_type, browser)); } return true; }
int gp_port_library_list (GPPortInfoList *list) { GPPortInfo info; #ifdef HAVE_MDNS_BONJOUR DNSServiceRef sd; DNSServiceErrorType ret; int fd; fd_set infds; struct timeval tv; #endif gp_port_info_new (&info); gp_port_info_set_type (info, GP_PORT_PTPIP); gp_port_info_set_name (info, _("PTP/IP Connection")); gp_port_info_set_path (info, "ptpip:"); CHECK (gp_port_info_list_append (list, info)); /* Generic matcher so you can pass any IP address */ gp_port_info_new (&info); gp_port_info_set_type (info, GP_PORT_PTPIP); gp_port_info_set_name (info, ""); gp_port_info_set_path (info, "^ptpip:"); CHECK (gp_port_info_list_append (list, info)); #ifdef HAVE_MDNS_BONJOUR ret = DNSServiceBrowse ( &sd, 0, /* unused flags */ 0, /* all ifaces */ "_ptp._tcp", NULL, _ptpip_enumerate, list ); /* We need to make it a non-blocking query */ fd = DNSServiceRefSockFD(sd); if (fd != -1) { FD_ZERO (&infds); FD_SET (fd, &infds); tv.tv_sec = 0; tv.tv_usec = 1; /* If we have input, we can try to process a result */ if (1 == select (fd+1, &infds, NULL, NULL, &tv)) DNSServiceProcessResult (sd); } DNSServiceRefDeallocate (sd); #endif return GP_OK; }
void BonjourBrowser::browseForServiceType(const QString &service_type) { DNSServiceErrorType err = DNSServiceBrowse(&dns_ref_, 0, 0, service_type.toUtf8().constData(), 0, bonjourBrowseReply, this); if (err != kDNSServiceErr_NoError) { emit error(err); } else { int sock_fd = DNSServiceRefSockFD(dns_ref_); if (sock_fd == -1) { emit error(kDNSServiceErr_Invalid); } else { bonjour_socket_ = new QSocketNotifier(sock_fd, QSocketNotifier::Read, this); connect(bonjour_socket_, SIGNAL(activated(int)), this, SLOT(bonjourSocketReadyRead())); } } }
bool Manager::startBrowsing() { if( !m_linkLocalHandler ) return false; if( m_browseRef ) stopBrowsing(); DNSServiceErrorType e = DNSServiceBrowse( &m_browseRef, 0, // flags, currently ignored m_interface, // interface, 0 = any, -1 = local only LINKLOCAL_SERVICE_TYPE.c_str(), // service type m_domain.c_str(), // domain, 0 = default domain(s) &handleBrowseReply, // callback this ); // context if ( e != kDNSServiceErr_NoError ) return false; return true; }
void QxtServiceBrowser::browse(/* int iface */) { QStringList subtypes = qxt_d().serviceSubTypes; subtypes.prepend(fullServiceType()); DNSServiceErrorType err; err = DNSServiceBrowse(&(qxt_d().service), 0, qxt_d().iface, subtypes.join(",_").toUtf8().constData(), domain().isEmpty() ? 0 : domain().toUtf8().constData(), QxtServiceBrowserPrivate::browseServiceCallback, &qxt_d()); if(err) { emit browsingFailed(err); } else { qxt_d().notifier = new QSocketNotifier(DNSServiceRefSockFD(qxt_d().service), QSocketNotifier::Read, this); QObject::connect(qxt_d().notifier, SIGNAL(activated(int)), &qxt_d(), SLOT(socketData())); } }
void BonjourBrowser::browseForServiceType (const QString& serviceType) { DNSServiceErrorType err; err = DNSServiceBrowse(&d->dnssref, 0, 0, serviceType.toUtf8().constData(), 0, bonjourBrowseReply, this); if (err != kDNSServiceErr_NoError) { setError(err); } else { int sockfd = DNSServiceRefSockFD(d->dnssref); if (sockfd == -1) { setError(kDNSServiceErr_Invalid); } else { d->bonjourSocket = new QSocketNotifier( sockfd, QSocketNotifier::Read, this); connect(d->bonjourSocket, SIGNAL(activated(int)), SLOT(bonjourSocketReadyRead())); } } }
void ZeroconfBrowser::browseForType(const QString& type) { DNSServiceErrorType err = DNSServiceBrowse(&m_DnsServiceRef, 0, 0, type.toUtf8().constData(), 0, browseReply, this); if (err != kDNSServiceErr_NoError) { emit error(err); } else { int sockFD = DNSServiceRefSockFD(m_DnsServiceRef); if (sockFD == -1) { emit error(kDNSServiceErr_Invalid); } else { m_pSocket = new QSocketNotifier(sockFD, QSocketNotifier::Read, this); connect(m_pSocket, SIGNAL(activated(int)), this, SLOT(socketReadyRead())); } } }
bool CZeroconfBrowserWIN::doAddServiceType(const CStdString& fcr_service_type) { DNSServiceErrorType err; DNSServiceRef browser = NULL; if(m_browser == NULL) { err = DNSServiceCreateConnection(&m_browser); if (err != kDNSServiceErr_NoError) { CLog::Log(LOGERROR, "ZeroconfBrowserWIN: DNSServiceCreateConnection failed with error = %ld", (int) err); return false; } err = WSAAsyncSelect( (SOCKET) DNSServiceRefSockFD( m_browser ), g_hWnd, BONJOUR_BROWSER_EVENT, FD_READ | FD_CLOSE ); if (err != kDNSServiceErr_NoError) CLog::Log(LOGERROR, "ZeroconfBrowserWIN: WSAAsyncSelect failed with error = %ld", (int) err); } { CSingleLock lock(m_data_guard); browser = m_browser; err = DNSServiceBrowse(&browser, kDNSServiceFlagsShareConnection, kDNSServiceInterfaceIndexAny, fcr_service_type.c_str(), NULL, BrowserCallback, this); } if( err != kDNSServiceErr_NoError ) { if (browser) DNSServiceRefDeallocate(browser); CLog::Log(LOGERROR, "ZeroconfBrowserWIN: DNSServiceBrowse returned (error = %ld)", (int) err); return false; } //store the browser { CSingleLock lock(m_data_guard); m_service_browsers.insert(std::make_pair(fcr_service_type, browser)); } return true; }
vvBonjour::ErrorType vvBonjourBrowser::browseForServiceType(const std::string& serviceType, const std::string domain, const double to) { #ifdef HAVE_BONJOUR DNSServiceErrorType error; DNSServiceRef serviceRef; _bonjourEntries.clear(); error = DNSServiceBrowse(&serviceRef, 0, // no flags 0, // all network interfaces serviceType.c_str(), // service type domain.c_str(), // default domains BrowseCallBack, // call back function this); // adress of pointer to eventloop if (error == kDNSServiceErr_NoError) { _timeout = to; _eventLoop = new vvBonjourEventLoop(serviceRef); if(to != -1.0) _eventLoop->run(false, to); else _eventLoop->run(true, to); } else { std::ostringstream errmsg; errmsg << "vvBonjourBrowser::browseForServiceType(): DNSServiceBrowse() returned with error no " << error; vvDebugMsg::msg(2, errmsg.str().c_str()); return vvBonjour::VV_ERROR; } return vvBonjour::VV_OK; #else (void)serviceType; (void)domain; (void)to; return vvBonjour::VV_ERROR; #endif }
bool CZeroconfBrowserMDNS::doAddServiceType(const std::string& fcr_service_type) { DNSServiceErrorType err; DNSServiceRef browser = NULL; #if !defined(HAS_MDNS_EMBEDDED) if(m_browser == NULL) { err = DNSServiceCreateConnection(&m_browser); if (err != kDNSServiceErr_NoError) { CLog::Log(LOGERROR, "ZeroconfBrowserMDNS: DNSServiceCreateConnection failed with error = %ld", (int) err); return false; } } #endif //!HAS_MDNS_EMBEDDED { CSingleLock lock(m_data_guard); browser = m_browser; err = DNSServiceBrowse(&browser, kDNSServiceFlagsShareConnection, kDNSServiceInterfaceIndexAny, fcr_service_type.c_str(), NULL, BrowserCallback, this); } if( err != kDNSServiceErr_NoError ) { if (browser) DNSServiceRefDeallocate(browser); CLog::Log(LOGERROR, "ZeroconfBrowserMDNS: DNSServiceBrowse returned (error = %ld)", (int) err); return false; } //store the browser { CSingleLock lock(m_data_guard); m_service_browsers.insert(std::make_pair(fcr_service_type, browser)); } return true; }
JNIEXPORT jint JNICALL Java_com_apple_dnssd_AppleBrowser_CreateBrowser( JNIEnv *pEnv, jobject pThis, jint flags, jint ifIndex, jstring regType, jstring domain) { jclass cls = (*pEnv)->GetObjectClass( pEnv, pThis); jfieldID contextField = (*pEnv)->GetFieldID( pEnv, cls, "fNativeContext", "J"); OpContext *pContext = NULL; DNSServiceErrorType err = kDNSServiceErr_NoError; if ( contextField != 0) pContext = NewContext( pEnv, pThis, "serviceFound", "(Lcom/apple/dnssd/DNSSDService;IILjava/lang/String;Ljava/lang/String;Ljava/lang/String;)V"); else err = kDNSServiceErr_BadParam; if ( pContext != NULL) { const char *regStr = SafeGetUTFChars( pEnv, regType); const char *domainStr = SafeGetUTFChars( pEnv, domain); pContext->Callback2 = (*pEnv)->GetMethodID( pEnv, (*pEnv)->GetObjectClass( pEnv, pContext->ClientObj), "serviceLost", "(Lcom/apple/dnssd/DNSSDService;IILjava/lang/String;Ljava/lang/String;Ljava/lang/String;)V"); err = DNSServiceBrowse( &pContext->ServiceRef, flags, ifIndex, regStr, domainStr, ServiceBrowseReply, pContext); if ( err == kDNSServiceErr_NoError) { (*pEnv)->SetLongField(pEnv, pThis, contextField, (long) pContext); } SafeReleaseUTFChars( pEnv, regType, regStr); SafeReleaseUTFChars( pEnv, domain, domainStr); } else err = kDNSServiceErr_NoMemory; return err; }
static void DNSSD_API KprZeroconfPlatformWildcardCallback(DNSServiceRef serviceRef, DNSServiceFlags flags, uint32_t interfaceIndex, DNSServiceErrorType errorCode, const char* name, const char* type, const char* domain, void* context) { FskErr err = kFskErrNone; KprZeroconfBrowser self = context; KprZeroconfPlatformBrowser browser = self->platform; char* ptr = NULL; char* serviceType = NULL; if (errorCode != kDNSServiceErr_NoError) { FskInstrumentedItemPrintfDebug(browser, "KprZeroconfPlatformWildcardCallback returned %d\n", errorCode); } else if (flags & kDNSServiceFlagsAdd) { char* ptr = FskStrStr(type, "local."); if (ptr) { *ptr = 0; bailIfError(FskMemPtrNew(FskStrLen(name) + FskStrLen(type) + 2, &serviceType)); FskStrCopy(serviceType, name); FskStrCat(serviceType, "."); FskStrCat(serviceType, type); if (!KprZeroconfPlatformServiceFindType(browser->types, serviceType)) { KprZeroconfPlatformService service = NULL; DNSServiceErrorType error; FskInstrumentedItemPrintfDebug(browser, "WILDCARD: %d %s", interfaceIndex, serviceType); error = DNSServiceBrowse(&serviceRef, 0, 0, serviceType, NULL, KprZeroconfPlatformBrowseCallback, self); if (error != kDNSServiceErr_NoError) { bailIfError(kFskErrNetworkErr); } bailIfError(KprZeroconfPlatformServiceNew(&service, NULL, serviceRef, serviceType, 0)); FskListAppend(&browser->types, service); } } } bail: if (ptr) *ptr = 'l'; FskMemPtrDispose(serviceType); return; }
void MDnsSdListener::Handler::discover(SocketClient *cli, const char *iface, const char *regType, const char *domain, const int requestId, const int requestFlags) { if (VDBG) { ALOGD("discover(%s, %s, %s, %d, %d)", iface, regType, domain, requestId, requestFlags); } Context *context = new Context(requestId, mListener); DNSServiceRef *ref = mMonitor->allocateServiceRef(requestId, context); if (ref == NULL) { ALOGE("requestId %d already in use during discover call", requestId); cli->sendMsg(ResponseCode::CommandParameterError, "RequestId already in use during discover call", false); return; } if (VDBG) ALOGD("using ref %p", ref); DNSServiceFlags nativeFlags = iToFlags(requestFlags); int interfaceInt = ifaceNameToI(iface); DNSServiceErrorType result = DNSServiceBrowse(ref, nativeFlags, interfaceInt, regType, domain, &MDnsSdListenerDiscoverCallback, context); if (result != kDNSServiceErr_NoError) { ALOGE("Discover request %d got an error from DNSServiceBrowse %d", requestId, result); mMonitor->freeServiceRef(requestId); cli->sendMsg(ResponseCode::CommandParameterError, "Discover request got an error from DNSServiceBrowse", false); return; } mMonitor->startMonitoring(requestId); if (VDBG) ALOGD("discover successful"); cli->sendMsg(ResponseCode::CommandOkay, "Discover operation started", false); return; }
int /* O - Exit status */ main(int argc, /* I - Number of command-line args */ char *argv[]) /* I - Command-line arguments */ { const char *name; /* Backend name */ cups_array_t *devices; /* Device array */ cups_device_t *device; /* Current device */ char uriName[1024]; /* Unquoted fullName for URI */ #ifdef HAVE_DNSSD int fd; /* Main file descriptor */ fd_set input; /* Input set for select() */ struct timeval timeout; /* Timeout for select() */ DNSServiceRef main_ref, /* Main service reference */ fax_ipp_ref, /* IPP fax service reference */ ipp_ref, /* IPP service reference */ ipp_tls_ref, /* IPP w/TLS service reference */ ipps_ref, /* IPP service reference */ local_fax_ipp_ref, /* Local IPP fax service reference */ local_ipp_ref, /* Local IPP service reference */ local_ipp_tls_ref, /* Local IPP w/TLS service reference */ local_ipps_ref, /* Local IPP service reference */ local_printer_ref, /* Local LPD service reference */ pdl_datastream_ref, /* AppSocket service reference */ printer_ref, /* LPD service reference */ riousbprint_ref; /* Remote IO service reference */ #endif /* HAVE_DNSSD */ #ifdef HAVE_AVAHI AvahiClient *client; /* Client information */ int error; /* Error code, if any */ #endif /* HAVE_AVAHI */ #if defined(HAVE_SIGACTION) && !defined(HAVE_SIGSET) struct sigaction action; /* Actions for POSIX signals */ #endif /* HAVE_SIGACTION && !HAVE_SIGSET */ /* * Don't buffer stderr, and catch SIGTERM... */ setbuf(stderr, NULL); #ifdef HAVE_SIGSET /* Use System V signals over POSIX to avoid bugs */ sigset(SIGTERM, sigterm_handler); #elif defined(HAVE_SIGACTION) memset(&action, 0, sizeof(action)); sigemptyset(&action.sa_mask); action.sa_handler = sigterm_handler; sigaction(SIGTERM, &action, NULL); #else signal(SIGTERM, sigterm_handler); #endif /* HAVE_SIGSET */ /* * Check command-line... */ if (argc >= 6) exec_backend(argv); else if (argc != 1) { _cupsLangPrintf(stderr, _("Usage: %s job-id user title copies options [file]"), argv[0]); return (1); } /* * Only do discovery when run as "dnssd"... */ if ((name = strrchr(argv[0], '/')) != NULL) name ++; else name = argv[0]; if (strcmp(name, "dnssd")) return (0); /* * Create an array to track devices... */ devices = cupsArrayNew((cups_array_func_t)compare_devices, NULL); /* * Browse for different kinds of printers... */ #ifdef HAVE_DNSSD if (DNSServiceCreateConnection(&main_ref) != kDNSServiceErr_NoError) { perror("ERROR: Unable to create service connection"); return (1); } fd = DNSServiceRefSockFD(main_ref); fax_ipp_ref = main_ref; DNSServiceBrowse(&fax_ipp_ref, kDNSServiceFlagsShareConnection, 0, "_fax-ipp._tcp", NULL, browse_callback, devices); ipp_ref = main_ref; DNSServiceBrowse(&ipp_ref, kDNSServiceFlagsShareConnection, 0, "_ipp._tcp", NULL, browse_callback, devices); ipp_tls_ref = main_ref; DNSServiceBrowse(&ipp_tls_ref, kDNSServiceFlagsShareConnection, 0, "_ipp-tls._tcp", NULL, browse_callback, devices); ipps_ref = main_ref; DNSServiceBrowse(&ipps_ref, kDNSServiceFlagsShareConnection, 0, "_ipps._tcp", NULL, browse_callback, devices); local_fax_ipp_ref = main_ref; DNSServiceBrowse(&local_fax_ipp_ref, kDNSServiceFlagsShareConnection, kDNSServiceInterfaceIndexLocalOnly, "_fax-ipp._tcp", NULL, browse_local_callback, devices); local_ipp_ref = main_ref; DNSServiceBrowse(&local_ipp_ref, kDNSServiceFlagsShareConnection, kDNSServiceInterfaceIndexLocalOnly, "_ipp._tcp", NULL, browse_local_callback, devices); local_ipp_tls_ref = main_ref; DNSServiceBrowse(&local_ipp_tls_ref, kDNSServiceFlagsShareConnection, kDNSServiceInterfaceIndexLocalOnly, "_ipp-tls._tcp", NULL, browse_local_callback, devices); local_ipps_ref = main_ref; DNSServiceBrowse(&local_ipps_ref, kDNSServiceFlagsShareConnection, kDNSServiceInterfaceIndexLocalOnly, "_ipps._tcp", NULL, browse_local_callback, devices); local_printer_ref = main_ref; DNSServiceBrowse(&local_printer_ref, kDNSServiceFlagsShareConnection, kDNSServiceInterfaceIndexLocalOnly, "_printer._tcp", NULL, browse_local_callback, devices); pdl_datastream_ref = main_ref; DNSServiceBrowse(&pdl_datastream_ref, kDNSServiceFlagsShareConnection, 0, "_pdl-datastream._tcp", NULL, browse_callback, devices); printer_ref = main_ref; DNSServiceBrowse(&printer_ref, kDNSServiceFlagsShareConnection, 0, "_printer._tcp", NULL, browse_callback, devices); riousbprint_ref = main_ref; DNSServiceBrowse(&riousbprint_ref, kDNSServiceFlagsShareConnection, 0, "_riousbprint._tcp", NULL, browse_callback, devices); #endif /* HAVE_DNSSD */ #ifdef HAVE_AVAHI if ((simple_poll = avahi_simple_poll_new()) == NULL) { fputs("DEBUG: Unable to create Avahi simple poll object.\n", stderr); return (0); } avahi_simple_poll_set_func(simple_poll, poll_callback, NULL); client = avahi_client_new(avahi_simple_poll_get(simple_poll), 0, client_callback, simple_poll, &error); if (!client) { fputs("DEBUG: Unable to create Avahi client.\n", stderr); return (0); } browsers = 6; avahi_service_browser_new(client, AVAHI_IF_UNSPEC, AVAHI_PROTO_UNSPEC, "_fax-ipp._tcp", NULL, 0, browse_callback, devices); avahi_service_browser_new(client, AVAHI_IF_UNSPEC, AVAHI_PROTO_UNSPEC, "_ipp._tcp", NULL, 0, browse_callback, devices); avahi_service_browser_new(client, AVAHI_IF_UNSPEC, AVAHI_PROTO_UNSPEC, "_ipp-tls._tcp", NULL, 0, browse_callback, devices); avahi_service_browser_new(client, AVAHI_IF_UNSPEC, AVAHI_PROTO_UNSPEC, "_ipps._tcp", NULL, 0, browse_callback, devices); avahi_service_browser_new(client, AVAHI_IF_UNSPEC, AVAHI_PROTO_UNSPEC, "_pdl-datastream._tcp", NULL, 0, browse_callback, devices); avahi_service_browser_new(client, AVAHI_IF_UNSPEC, AVAHI_PROTO_UNSPEC, "_printer._tcp", NULL, 0, browse_callback, devices); #endif /* HAVE_AVAHI */ /* * Loop until we are killed... */ while (!job_canceled) { int announce = 0; /* Announce printers? */ #ifdef HAVE_DNSSD FD_ZERO(&input); FD_SET(fd, &input); timeout.tv_sec = 0; timeout.tv_usec = 500000; if (select(fd + 1, &input, NULL, NULL, &timeout) < 0) continue; if (FD_ISSET(fd, &input)) { /* * Process results of our browsing... */ DNSServiceProcessResult(main_ref); } else announce = 1; #elif defined(HAVE_AVAHI) got_data = 0; if ((error = avahi_simple_poll_iterate(simple_poll, 500)) > 0) { /* * We've been told to exit the loop. Perhaps the connection to * Avahi failed. */ break; } if (!got_data) announce = 1; #endif /* HAVE_DNSSD */ /* fprintf(stderr, "DEBUG: announce=%d\n", announce);*/ if (announce) { /* * Announce any devices we've found... */ #ifdef HAVE_DNSSD DNSServiceErrorType status; /* DNS query status */ #endif /* HAVE_DNSSD */ cups_device_t *best; /* Best matching device */ char device_uri[1024]; /* Device URI */ int count; /* Number of queries */ int sent; /* Number of sent */ for (device = (cups_device_t *)cupsArrayFirst(devices), best = NULL, count = 0, sent = 0; device; device = (cups_device_t *)cupsArrayNext(devices)) { if (device->sent) sent ++; if (device->ref) count ++; if (!device->ref && !device->sent) { /* * Found the device, now get the TXT record(s) for it... */ if (count < 50) { fprintf(stderr, "DEBUG: Querying \"%s\"...\n", device->fullName); #ifdef HAVE_DNSSD device->ref = main_ref; status = DNSServiceQueryRecord(&(device->ref), kDNSServiceFlagsShareConnection, 0, device->fullName, kDNSServiceType_TXT, kDNSServiceClass_IN, query_callback, device); if (status != kDNSServiceErr_NoError) fprintf(stderr, "ERROR: Unable to query \"%s\" for TXT records: %d\n", device->fullName, status); /* Users never see this */ else count ++; #else if ((device->ref = avahi_record_browser_new(client, AVAHI_IF_UNSPEC, AVAHI_PROTO_UNSPEC, device->fullName, AVAHI_DNS_CLASS_IN, AVAHI_DNS_TYPE_TXT, 0, query_callback, device)) == NULL) fprintf(stderr, "ERROR: Unable to query \"%s\" for TXT records: %s\n", device->fullName, avahi_strerror(avahi_client_errno(client))); /* Users never see this */ else count ++; #endif /* HAVE_AVAHI */ } } else if (!device->sent) { #ifdef HAVE_DNSSD /* * Got the TXT records, now report the device... */ DNSServiceRefDeallocate(device->ref); #else avahi_record_browser_free(device->ref); #endif /* HAVE_DNSSD */ device->ref = NULL; if (!best) best = device; else if (_cups_strcasecmp(best->name, device->name) || _cups_strcasecmp(best->domain, device->domain)) { unquote(uriName, best->fullName, sizeof(uriName)); if (best->uuid) httpAssembleURIf(HTTP_URI_CODING_ALL, device_uri, sizeof(device_uri), "dnssd", NULL, uriName, 0, best->cups_shared ? "/cups?uuid=%s" : "/?uuid=%s", best->uuid); else httpAssembleURI(HTTP_URI_CODING_ALL, device_uri, sizeof(device_uri), "dnssd", NULL, uriName, 0, best->cups_shared ? "/cups" : "/"); cupsBackendReport("network", device_uri, best->make_and_model, best->name, best->device_id, NULL); best->sent = 1; best = device; sent ++; } else if (best->priority > device->priority || (best->priority == device->priority && best->type < device->type)) { best->sent = 1; best = device; sent ++; } else { device->sent = 1; sent ++; } } } if (best) { unquote(uriName, best->fullName, sizeof(uriName)); if (best->uuid) httpAssembleURIf(HTTP_URI_CODING_ALL, device_uri, sizeof(device_uri), "dnssd", NULL, uriName, 0, best->cups_shared ? "/cups?uuid=%s" : "/?uuid=%s", best->uuid); else httpAssembleURI(HTTP_URI_CODING_ALL, device_uri, sizeof(device_uri), "dnssd", NULL, uriName, 0, best->cups_shared ? "/cups" : "/"); cupsBackendReport("network", device_uri, best->make_and_model, best->name, best->device_id, NULL); best->sent = 1; sent ++; } fprintf(stderr, "DEBUG: sent=%d, count=%d\n", sent, count); #ifdef HAVE_AVAHI if (sent == cupsArrayCount(devices) && browsers == 0) #else if (sent == cupsArrayCount(devices)) #endif /* HAVE_AVAHI */ break; } } return (CUPS_BACKEND_OK); }