[avahi] Follow-up: Bonjour compatibility layer - no results from DNSServiceBrowse

Joshua Foster jfoster at dtiweb.net
Tue Jan 5 09:24:46 PST 2010


> Please provide us with a minimal test case for your code so that we
> can reproduce your issue.

Ok, provided below.  On Windows with Bonjour a service is found immediately:

  Looking for services of type _ipp._tcp...
   * Got a result!  processing...
   * Found a _ipp._tcp. service at "Dell Laser Printer 1720dn"!

On Linux with Avahi, no browse results are received and select() times out:

  Looking for services of type _ipp._tcp...
  *** WARNING *** The program 'AvahiBonjourTest' uses the Apple Bonjour compatibility layer   of Avahi.
  *** WARNING *** Please fix your application to use the native API of Avahi!
  *** WARNING *** For more information see <http://0pointer.de/avahiompat?s=libdns_sd&e=AvahiBonjourTest>
   * select() timed out

...even though avahi-discover shows 4 services of type _ipp._tcp".

-------------------------------------

/**
 * Spends 5 seconds browsing for services of the given regtype. If any are
 * found, their names are output.
 *
 * Build: g++ AvahiBonjourTest.cpp -o AvahiBonjourTest -ldns_sd
 *
 * Run: ./AvahiBonjourTest [regType]
 *  - If no regtype is given, _ipp._tcp" is used.
 */

#ifndef WIN32
#include <sys/select.h>
#endif // ndef WIN32

#include <dns_sd.h>
#include <stdio.h>
#include <iostream>
using namespace std;

void DNSSD_API ProcessBrowseResult( DNSServiceRef sdRef, DNSServiceFlags flags,
	uint32_t interfaceIndex, DNSServiceErrorType errorCode,
	const char *serviceName, const char *regtype, const char *replyDomain,
	void *context )
{
	if( errorCode == kDNSServiceErr_NoError )
	{
		cout << " * Found a " << regtype << " service at \"" << serviceName
			 << "\"!" << endl;
	}
	else
	{
		cout << " * ProcessBrowseResult(): Bonjour error " << errorCode << endl;
	}
}

int main( int argc, const char* argv[] )
{
	const char* regType = ( argc > 1 ? argv[1] : "_ipp._tcp" );
	DNSServiceRef browseSvc = 0;
	
	cout << "Looking for services of type " << regType << "..." << endl;
	
	// Start the browse operation
	int errorCode = DNSServiceBrowse( &browseSvc, 0, 0, regType, 0,
		ProcessBrowseResult, 0 );
	
	if( errorCode != kDNSServiceErr_NoError )
	{
		cout << " * DNSServiceBrowse(): Bonjour error " << errorCode << endl;
		DNSServiceRefDeallocate( browseSvc );
		return 0;
	}
	
	fd_set readfds;
	FD_ZERO( &readfds );
	FD_SET( DNSServiceRefSockFD( browseSvc ), &readfds );
	
	timeval tv;
	tv.tv_sec = 5;
	tv.tv_usec = 0;
	
	// Wait for a response from mDNSResponder, or until timeout, whichever is
	// first
	int result = select( 1, &readfds, NULL, NULL, &tv );
	if( result == -1 )
	{
		perror( " * select() threw an error" );
		
	}
	else if( result > 0 )
	{
		cout << " * Got a result!  processing..." << endl;
		// Read the response and call ProcessBrowseResult()
		errorCode = DNSServiceProcessResult( browseSvc );
	}
	else
	{
		cout << " * select() timed out" << endl;
	}
	
	DNSServiceRefDeallocate( browseSvc );
	return 0;
}

-------------------------------------

> Also, please do not send HTML emails to this ML and do set a
> subject. 

Whoops, sorry about the lack of subject.

>> This message may contain sensitive, proprietary and/or privileged
>> information. Disclosure is not authorized unless provided in writing by
>> Defense Technologies, Inc. If you are not the addressee or authorized to
>> receive this for the addressee, you must not use, copy, disclose, or
>> take any action based on this message or any information herein. If you
>> have received this message in error, please advise the sender
>> immediately by reply e-mail and delete this message. Thank you for your
>> cooperation.
>
> You probably should not send emails to this mailing list (which
> archives every mail you send to it) if you take this legal blurb
> seriously...

I don't.  It's added automatically by my employer; I have no control over it.  There is no classified information in this email, and I make no copyright claim to the sample code I'm providing.

> Thanks,
>
> Lennart


Thanks again for your help!


________________________________________

Joshua Foster
Sr. Computer Programmer
2721 X-Ray Drive
Gastonia, NC 28054
(704) 824-0199 x217
(704) 824-0241 Fax

jfoster at dtiweb.net
www.dtiweb.net
This message may contain sensitive, proprietary and/or privileged information. Disclosure is not authorized unless provided in writing by Defense Technologies, Inc. If you are not the addressee or authorized to receive this for the addressee, you must not use, copy, disclose, or take any action based on this message or any information herein. If you have received this message in error, please advise the sender immediately by reply e-mail and delete this message. Thank you for your cooperation.
 


More information about the avahi mailing list