我正在做一些 dns 的事情,我需要对 SRV 进行 A 记录查找并从中提取 ttl 和 ip 地址:
我可以使用以下代码提取 ip,但是如何提取 TTL?
l = res_query(argv[1], ns_c_any, ns_t_a, nsbuf, sizeof(nsbuf));
if (l < 0)
{
perror(argv[1]);
}
ns_initparse(nsbuf, l, &msg);
l = ns_msg_count(msg, ns_s_an);
for (i = 0; i < l; i++)
{
ns_parserr(&msg, ns_s_an, 0, &rr);
ns_sprintrr(&msg, &rr, NULL, NULL, dispbuf, sizeof(dispbuf));
printf("\t%s \n", dispbuf);
inet_ntop(AF_INET, ns_rr_rdata(rr), debuf, sizeof(debuf));
printf("\t%s \n", debuf);
}
输出:
./a.out sip-anycast-1.voice.google.com
sip-anycast-1.voice.google.com. 21h55m46s IN A 216.239.32.1
216.239.32.1