Why doesn't this Avahi client code work to add a CNAME alias to my Linux machine?

Jer*_*ner 2 c++ linux client cname

I'm trying to write a little program that will add mDNS CNAME aliases to my Linux device, so that it can be accessed via more than one "something.local." domain name.

该程序的预期功能与avahi-aliases Python脚本相同,但为了避免Python依赖,我试图用C++实现它.

我的代码(现在)基于Avahi源代码发行版中包含的client-publish-service.c示例.当我将该示例保持不变时,它按预期工作:特别是,我看到"MegaPrinter"出现在Mac上的Bonjour浏览器中,等等.

我的下一步是修改示例代码以添加CNAME记录而不是添加服务.所以我#ifdef了avahi_entry_group_add_service()调用并将其放入:

 const int TTL = 60;

 char rdata[] = "\0msli-10135114\0local";   // "msli10135114.local." is the device's normal FQDN, which I want to make aliases to
 rdata[0]   = 13;
 rdata[14]  = 5;

 printf("rdata=[%s] _moduleName=[%s]\n", rdata, _moduleName);
 printf("add_record: %s\n", avahi_strerror(avahi_entry_group_add_record (group, AVAHI_IF_UNSPEC, AVAHI_PROTO_UNSPEC, (AvahiPublishFlags)0, "TestX", 0x01, 0x10, 120, "\5booya", 6)));

 if ((ret = avahi_entry_group_add_record(
    group,                 //AvahiEntryGroup *group,
    AVAHI_IF_UNSPEC,       //AvahiIfIndex interface,
    AVAHI_PROTO_UNSPEC,    //AvahiProtocol protocol,
    (AvahiPublishFlags)0,  //AvahiPublishFlags flags,
    _moduleName,           //const char *name,
    AVAHI_DNS_CLASS_IN,    //uint16_t clazz,
    AVAHI_DNS_TYPE_CNAME,  //uint16_t type,
    TTL,                   //uint32_t ttl,
    rdata,                 //const void *rdata,
    sizeof(rdata)          //size_t size
    )) < 0)
 {
    if (ret == AVAHI_ERR_COLLISION) goto collision;
    fprintf(stderr, "Failed to add module record: %s\n", avahi_strerror(ret));
    goto fail;
 }
Run Code Online (Sandbox Code Playgroud)

....但它不起作用; 特别是,运行例程只给我这个输出:

msli-10135114local] _moduleName=[Wild-Tracks-1]
add_record: Not supported 
Failed to add module record: Not supported
Run Code Online (Sandbox Code Playgroud)

What's strange is, not only does my own call to avahi_entry_group_add_record() fail with code AVAHI_ERR_NOT_SUPPORTED, but also my throw-away test call (inside the printf("add_record")) also fails with the same error code. But that call is copied verbatim out of the avahi-client/client-test.c file that comes with Avahi, so it seems like it should be a valid call.

Can anyone suggest why these calls might be failing, or what I am doing wrong here?

In case it helps, the complete source code for the test is here.

Jer*_*ner 6

我终于想出了这个......问题是avahi_entry_group_add_record的(AvahiPublishFlags)参数需要包含AVAHI_PUBLISH_USE_MULTICAST位,而不仅仅是零.奇怪的是,我用作示例的Python脚本没有包括那个位.

在任何情况下,如果有人感兴趣,源代码的工作版本就在这里.