Background
I m working on a cross-platform Zeroconf/Bonjour/DNS-SD library for Haskell, and figured my best bet would bet would be to target the dns_sd.h
API. Under Linux, the implementation of this interface is provided by Avahi, which claims to support a subset of the Bonjour API.
Problem
作为我的图书馆的疗效检查,我在C撰写了一个小的测试方案,仅使用APIC光带。 http://www.tcp。
#include <dns_sd.h>
#include <stdio.h>
#include <stdlib.h>
void cb(DNSServiceRef sdRef,
DNSServiceFlags flags,
uint32_t interfaceIndex,
DNSServiceErrorType errorCode,
const char *serviceName,
const char *regtype,
const char *replyDomain,
void *context) {
printf("called!
");
}
int main() {
DNSServiceRef sd = malloc(sizeof(DNSServiceRef));
const char *regtype = "_http._tcp";
DNSServiceErrorType err1 = DNSServiceBrowse(&sd, 0, 0, regtype, NULL, &cb, NULL);
printf("err1=%d
", err1);
DNSServiceErrorType err2 = DNSServiceProcessResult(sd);
printf("err2=%d
", err2);
return 0;
}
在我的Mac,这一试验方案在C和等同的Haskell(发现我的打印机;引诱!)两处都进行了罚款。
$ gcc test.c -o test
$ ./test
err1=0
called!
err2=0
但是,在我的无赖机器上,该方案在我离开之前就向我发出警告:
$ gcc test.c -o test -ldns_sd
$ ./test
*** WARNING *** The program test 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/avahi-compat?s=libdns_sd&e=test>
err1=0
err2=0
Questions
- Is the Avahi
dns_sd
compatibility layer still a suitable target for a cross-platform binding? Or is that warning message serious enough about using the native Avahi API that I should consider retargeting? - What is the state of the art for cross-platform Zeroconf in C?