while(do_again) {
rc = gethostbyname_r(host, &hbuf, tmp, TMPLEN, &hp, &my_h_errno);
if (rc != 0) {
if(my_h_errno == TRY_AGAIN) {
printf("HOST NOT FOUND: got a TRY_AGAIN response from gethostbyname_r()\n");
continue;
} else if (my_h_errno == HOST_NOT_FOUND) {
printf("HOST NOT FOUND: Got an authoritative answer\n");
exit(0);
} else {
printf("Other errors..\n");
exit(0);
}
}
do_again = false;
}
Above code always returning with my_h_errno
set to TRY_AGAIN
for non-resolvable hostnames on Ubuntu 19.04 and 20.04. On previous versions of the OS or on other Linux flavors, it usually returns a more authoritative version, HOST_NOT_FOUND
.
How does the call(gethostbyname_r
) exactly work? And are there any changes on the dns or lookup mechanism on the latest versions of Ubuntu which is causing such behavior?
From the manual