Following up on this for a third time because I have received no responses.
Has anyone on the list had a chance to look at this issue?
I have an app that uses Bonjour to detect other services of its type on the
network. It works as expected with Bonjour under Win32, however I need it to
work on Linux as well. It's not feasible to rewrite the code with the Avahi
API because I need it to work primarily on Win32. So I'm trying to use the
Bonjour compatibility layer in Avahi, but having problems with the most basic
of operations: Browsing.
Sample code is provided below. It's just a simple service discovery.
-------------------------------------
/**
* 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;
}
-------------------------------------
There are 4 printers on the network. 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
But I know Avahi is working, because avahi-discover shows 4 services of type
_ipp._tcp". So... why does the browse socket not returning anything? What am
I missing?
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
[email protected]
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.
_______________________________________________
avahi mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/avahi