gpt4 book ai didi

c - 意外的 getnameinfo() 主机名

转载 作者:行者123 更新时间:2023-11-30 18:13:33 26 4
gpt4 key购买 nike

我使用 C 代码通过 getnameinfo api 从 IPv6 地址获取主机名。它返回 0 表示成功,但目标字符串为“空”。不知道错在哪里。

error_info = getnameinfo(who, wholen, host, NI_MAXHOST, serv, NI_MAXSERV, NI_NOFQDN);

if(error_info){
fprintf(stderr, "\ngetnameinfo is success.");
fprintf(stderr, "\nstring @ host :: %s and serv :: %s", host, serv);
}

输出:

getnameinfo is success.
string @ host :: and serv ::

最佳答案

IP 到主机名需要 DNS 服务器中的反向 DNS 条目。此处,对于提供的 IP 地址,没有可用的反向 DNS,因此它返回成功并带有 NULL 条目。使用反向 DNS 条目检查其他主机名。

关于c - 意外的 getnameinfo() 主机名,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24237170/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com