-
Notifications
You must be signed in to change notification settings - Fork 43
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
getaddrinfo fails to parse IPv6 address on some systems #34
Comments
I just personally ran into this problem on one of our nodes, and whipped up the following fix. It'll need to be tested more, but it seems to work... bgpstream_addr_storage_t *bgpstream_str2addr(char *addr_str,
bgpstream_addr_storage_t *addr)
{
if (addr_str == NULL || addr == NULL) {
return NULL;
}
if (strchr(addr_str, ':') != NULL) {
/* this looks like it will be an IPv6 address */
if (inet_pton(AF_INET6, addr_str, &addr->ipv6) != 1) {
fprintf(stderr, "ERROR: Could not parse address string %s\n", addr_str);
return NULL;
}
addr->version = BGPSTREAM_ADDR_VERSION_IPV6;
} else {
/* probably a v4 address */
if (inet_pton(AF_INET, addr_str, &addr->ipv4) != 1) {
fprintf(stderr, "ERROR: Could not parse address string %s\n", addr_str);
return NULL;
}
addr->version = BGPSTREAM_ADDR_VERSION_IPV4;
}
return addr;
} |
This seems to solve the problem described at CAIDA/bgpstream#34 @digizeph is going to do a full review of this problem and fix, but for now this should be good enough.
"The getaddrinfo() function combines the functionality provided by the gethostbyname(3) and getservbyname(3) functions into a single interface"
The usage of Name Service Switch was pointed out to be problematic in here and here. Addding
In any case, we don't seem to use DNS at all in the context, thus using |
the issue should be fixed by #69 . |
As reported by @vgiotsas
It seems that the way we use
getaddrinfo
(https://github.com/CAIDA/bgpstream/blob/master/lib/utils/bgpstream_utils_addr.c#L209) will fail to parse an IPv6 address on (some?) IPv6-only systems. Probably omittingAI_ADDRCONFIG
from hints would fix this, but it seems there can be issues withgetaddrinfo
(see https://blog.powerdns.com/2014/05/21/a-surprising-discovery-on-converting-ipv6-addresses-we-no-longer-prefer-getaddrinfo/), so we may want to consider switching toinet_pton
...The text was updated successfully, but these errors were encountered: