Download raw body.
gethostbyname(3) should always set ai_canonname
Consulting the Book of Armaments:
| If nodename is not null, and if requested by the AI_CANONNAME flag, the
| ai_canonname field of the first returned addrinfo structure shall point
| to a null-terminated string containing the canonical name corresponding
| to the input nodename; if the canonical name is not available, then
| ai_canonname shall refer to the nodename argument or a string with the
| same contents.
| --- https://pubs.opengroup.org/onlinepubs/9799919799/functions/freeaddrinfo.html
Our documentation also claims that ai_canonname is set:
AI_CANONNAME If the AI_CANONNAME bit is set, a
successful call to getaddrinfo() will
return a NUL-terminated string containing
the canonical name of the specified host
name in the ai_canonname element of the
first addrinfo structure returned.
OK?
(There is a check in addrinfo_add to see if the AI_CANONNAME flag is
set.)
diff --git lib/libc/asr/getaddrinfo_async.c lib/libc/asr/getaddrinfo_async.c
index 23262f5163f..d5cf56cd0d7 100644
--- lib/libc/asr/getaddrinfo_async.c
+++ lib/libc/asr/getaddrinfo_async.c
@@ -280,7 +280,7 @@ getaddrinfo_async_run(struct asr_query *as, struct asr_result *ar)
as->as.ai.hostname) == -1)
continue;
- if ((r = addrinfo_add(as, &sa.sa, NULL)))
+ if ((r = addrinfo_add(as, &sa.sa, as->as.ai.hostname)))
ar->ar_gai_errno = r;
break;
}
@@ -681,7 +681,7 @@ addrinfo_from_pkt(struct asr_query *as, char *pkt, size_t pktlen)
if (as->as.ai.hints.ai_flags & AI_CANONNAME) {
_asr_strdname(rr.rr_dname, buf, sizeof buf);
buf[strlen(buf) - 1] = '\0';
- c = res_hnok(buf) ? buf : NULL;
+ c = res_hnok(buf) ? buf : as->as.ai.hostname;
} else if (as->as.ai.hints.ai_flags & AI_FQDN)
c = as->as.ai.fqdn;
else
--
In my defence, I have been left unsupervised.
gethostbyname(3) should always set ai_canonname