BIT-1827: fix error on initializing DNS w/ IPv6 nameserver.

This just skips over IPv6 nameserver addresses for now and uses the
first IPv4 one in the resolver config.  Should be possible to support
IPv6, but that may need more testing (e.g. need to make sure the code
will be portable to various platforms).
This commit is contained in:
Jon Siwek 2017-11-20 11:28:59 -06:00
parent 105cdb5aaf
commit 26dc94c31d
3 changed files with 38 additions and 19 deletions

View file

@ -131,27 +131,40 @@ nb_dns_init(char *errstr)
free(nd);
return (NULL);
}
nd->s = socket(PF_INET, SOCK_DGRAM, 0);
if (nd->s < 0) {
snprintf(errstr, NB_DNS_ERRSIZE, "socket(): %s",
my_strerror(errno));
free(nd);
return (NULL);
}
/* XXX should use resolver config */
nd->server = _res.nsaddr_list[0];
for ( int i = 0; i < _res.nscount; ++i )
{
nd->server = _res.nsaddr_list[i];
if (connect(nd->s, (struct sockaddr *)&nd->server,
sizeof(struct sockaddr)) < 0) {
snprintf(errstr, NB_DNS_ERRSIZE, "connect(%s): %s",
inet_ntoa(nd->server.sin_addr), my_strerror(errno));
close(nd->s);
free(nd);
return (NULL);
}
/* XXX support IPv6 */
if ( nd->server.sin_family != AF_INET )
continue;
return (nd);
nd->s = socket(nd->server.sin_family, SOCK_DGRAM, 0);
if ( nd->s < 0 )
{
snprintf(errstr, NB_DNS_ERRSIZE, "socket(): %s",
my_strerror(errno));
free(nd);
return (NULL);
}
if ( connect(nd->s, (struct sockaddr *)&nd->server,
sizeof(struct sockaddr)) < 0 )
{
snprintf(errstr, NB_DNS_ERRSIZE, "connect(%s): %s",
inet_ntoa(nd->server.sin_addr), my_strerror(errno));
close(nd->s);
free(nd);
return (NULL);
}
return (nd);
}
snprintf(errstr, NB_DNS_ERRSIZE, "no valid nameservers in resolver config");
return (NULL);
}
void