From: Wouter Wijngaards Date: Mon, 15 Oct 2007 14:42:37 +0000 (+0000) Subject: fixup addr6 check. X-Git-Tag: release-0.6~67 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=fed59bca843f29735043dc3542c183f5b6473662;p=thirdparty%2Funbound.git fixup addr6 check. git-svn-id: file:///svn/unbound/trunk@677 be551aaa-1e26-0410-a405-d3ace91eadb9 --- diff --git a/doc/Changelog b/doc/Changelog index d33539d5f..6a2d58c2b 100644 --- a/doc/Changelog +++ b/doc/Changelog @@ -4,6 +4,7 @@ - fixup the fact that the query section was not compressed to, the code was there but was called by value instead of by reference. And test for the case, uses xxd and nc. + - more portable ip6 check for sockaddr types. 8 October 2007: Wouter - --disable-rpath option in configure for 64bit systems with diff --git a/iterator/iter_utils.c b/iterator/iter_utils.c index bfa266ea1..80ae55d3a 100644 --- a/iterator/iter_utils.c +++ b/iterator/iter_utils.c @@ -136,7 +136,7 @@ iter_filter_unsuitable(struct iter_env* iter_env, struct module_env* env, if(donotq_lookup(iter_env->donotq, &a->addr, a->addrlen)) { return -1; /* server is on the donotquery list */ } - if(!iter_env->supports_ipv6 && addr_is_ip6(&a->addr)) { + if(!iter_env->supports_ipv6 && addr_is_ip6(&a->addr, a->addrlen)) { return -1; /* there is no ip6 available */ } /* check lameness - need zone , class info */ diff --git a/services/outside_network.c b/services/outside_network.c index 8e9105095..986674875 100644 --- a/services/outside_network.c +++ b/services/outside_network.c @@ -124,7 +124,7 @@ outnet_tcp_take_into_use(struct waiting_tcp* w, uint8_t* pkt, size_t pkt_len) log_assert(pkt); /* open socket */ #ifdef INET6 - if(addr_is_ip6(&w->addr)) + if(addr_is_ip6(&w->addr, w->addrlen)) s = socket(PF_INET6, SOCK_STREAM, IPPROTO_TCP); else #endif @@ -643,7 +643,7 @@ select_port(struct outside_network* outnet, struct pending* pend, log_assert(outnet && pend); /* first select ip4 or ip6. */ - if(addr_is_ip6(&pend->addr)) + if(addr_is_ip6(&pend->addr, pend->addrlen)) nummax = (int)outnet->num_udp6; else nummax = (int)outnet->num_udp4; @@ -663,7 +663,7 @@ select_port(struct outside_network* outnet, struct pending* pend, if(chosen < 0) chosen = 0; if(chosen >= nummax) chosen = nummax-1; - if(addr_is_ip6(&pend->addr)) + if(addr_is_ip6(&pend->addr, pend->addrlen)) pend->c = outnet->udp6_ports[chosen]; else pend->c = outnet->udp4_ports[chosen]; log_assert(pend->c); diff --git a/util/net_help.c b/util/net_help.c index 871199455..bddcf0dbe 100644 --- a/util/net_help.c +++ b/util/net_help.c @@ -312,10 +312,10 @@ sockaddr_cmp(struct sockaddr_storage* addr1, socklen_t len1, } int -addr_is_ip6(struct sockaddr_storage* addr) +addr_is_ip6(struct sockaddr_storage* addr, socklen_t len) { - short family = *(short*)addr; - if(family == AF_INET6) + if(len == (socklen_t)sizeof(struct sockaddr_in6) && + ((struct sockaddr_in6*)addr)->sin6_family == AF_INET6) return 1; else return 0; } diff --git a/util/net_help.h b/util/net_help.h index 097e586d1..83e631e8e 100644 --- a/util/net_help.h +++ b/util/net_help.h @@ -203,8 +203,9 @@ int sockaddr_cmp(struct sockaddr_storage* addr1, socklen_t len1, /** * Checkout address family. * @param addr: the sockaddr to examine. + * @param len: the length of addr. * return: true if sockaddr is ip6. */ -int addr_is_ip6(struct sockaddr_storage* addr); +int addr_is_ip6(struct sockaddr_storage* addr, socklen_t len); #endif /* NET_HELP_H */