From: Mark Wooding Date: Sat, 3 May 2014 21:22:27 +0000 (+0100) Subject: src/types.c: IPv4 networks match IPv6-mapped IPv4 addresses in sortlist. X-Git-Tag: wip.base.getaddrinfo~28 X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~mdw/git/adns/commitdiff_plain/4e8966f30fe4b53960581503c29677ec41f589ed src/types.c: IPv4 networks match IPv6-mapped IPv4 addresses in sortlist. Signed-off-by: Mark Wooding --- diff --git a/src/types.c b/src/types.c index a2ddee3..0cbbdef 100644 --- a/src/types.c +++ b/src/types.c @@ -254,11 +254,28 @@ static adns_status pa_inaddr(const parseinfo *pai, int cbyte, static int search_sortlist(adns_state ads, int af, const void *ad) { const struct sortlist *slp; + const struct in6_addr *a6; + union gen_addr a; int i; - + int v6mappedp = 0; + + if (af == AF_INET6) { + a6 = ad; + if (IN6_IS_ADDR_V4MAPPED(a6)) { + a.v4.s_addr = htonl(((unsigned long)a6->s6_addr[12] << 24) | + ((unsigned long)a6->s6_addr[13] << 16) | + ((unsigned long)a6->s6_addr[14] << 8) | + ((unsigned long)a6->s6_addr[15] << 0)); + v6mappedp = 1; + } + } + for (i=0, slp=ads->sortlist; - insortlist && (af != slp->ai->af || - !slp->ai->matchp(ad, &slp->base, &slp->mask)); + insortlist && + !(af == slp->ai->af && + slp->ai->matchp(ad, &slp->base, &slp->mask)) && + !(v6mappedp && slp->ai->af == AF_INET && + slp->ai->matchp(&a, &slp->base, &slp->mask)); i++, slp++); return i; }