1

我正在完成在我的嵌入式 Linux 3.14 中从 bonjour 切换到 avahi 的过程。一切正常,除了 gethostbyname() 的问题。

Mdns 广告设备由各种 avahi 实用程序(avahi-browse、resolve 等)和 dns_sd 回调(我安装了 avahi 的 libdns_sd_compat 库)解析,除了 mdns 广告设备的 IP 地址(some_device.local)。

为了测试 gethostbyname() 我在 C 中使用代码 gethostbyname

代码 :

#include <stdio.h>
#include <netdb.h>

int main (int argc, char *argv[])
{
    struct hostent *hstnm;
    if (argc != 2) {
        fprintf(stderr, "usage: %s hostname\n", argv[0]);
        return 1;
    }
    hstnm = gethostbyname (argv[1]);
    if (!hstnm)
        return 1;
    printf ("Name: %s\n", hstnm->h_name);
    return 0;
}

当我切换回 bonjour 时,该函数返回一个正确的结构(我可以从中提取 IP 地址),而在 avahi 中它总是返回 NULL。我可能会错过配置文件和/或库文件中的某些条目。有人知道它们是什么吗?

谢谢你

4

0 回答 0