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

@ -1,4 +1,10 @@
2.5-345 | 2017-11-20 11:28:59 -0600
* BIT-1827: fix error on initializing DNS w/ IPv6 nameserver. (Corelight)
* Add --build-type flag to configure wrapper. (Corelight)
2.5-343 | 2017-11-17 15:27:04 -0800 2.5-343 | 2017-11-17 15:27:04 -0800
* Fix ASCII logging of very large values of type "double". * Fix ASCII logging of very large values of type "double".

View file

@ -1 +1 @@
2.5-343 2.5-345

View file

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