diff --git a/src/network/lookup_name.c b/src/network/lookup_name.c index a1851f1f..0e6db9ef 100644 --- a/src/network/lookup_name.c +++ b/src/network/lookup_name.c @@ -355,36 +355,53 @@ int __lookup_name(struct address buf[static MAXADDRS], char canon[static 256], c * excessive runtime and code size cost and dubious benefit. * So far the label/precedence table cannot be customized. */ for (i=0; ilabel; int dprec = dpolicy->prec; int prefixlen = 0; - int fd = socket(AF_INET6, SOCK_DGRAM|SOCK_CLOEXEC, IPPROTO_UDP); + int fd = socket(family, SOCK_DGRAM|SOCK_CLOEXEC, IPPROTO_UDP); if (fd >= 0) { - if (!connect(fd, (void *)&da, sizeof da)) { + if (!connect(fd, da, dalen)) { key |= DAS_USABLE; - if (!getsockname(fd, (void *)&sa, - &(socklen_t){sizeof sa})) { - if (dscope == scopeof(&sa.sin6_addr)) + if (!getsockname(fd, sa, &salen)) { + if (family == AF_INET) memcpy( + &sa6.sin6_addr.s6_addr+12, + &sa4.sin_addr, 4); + if (dscope == scopeof(&sa6.sin6_addr)) key |= DAS_MATCHINGSCOPE; - if (dlabel == labelof(&sa.sin6_addr)) + if (dlabel == labelof(&sa6.sin6_addr)) key |= DAS_MATCHINGLABEL; - prefixlen = prefixmatch(&sa.sin6_addr, - &da.sin6_addr); + prefixlen = prefixmatch(&sa6.sin6_addr, + &da6.sin6_addr); } } close(fd);