From 101b3e40507b1e32bd22d11a0fd1d10a7fbcc9dd Mon Sep 17 00:00:00 2001 From: Jarrod Baumann Date: Wed, 22 Apr 2015 18:04:37 +0000 Subject: [PATCH] Reverted to original logic based on comments from @bogdan-iancu and @etamme but preferring v6 records if dns_try_ipv6 is enabled --- resolve.c | 96 +++++++++++++++++++++++++++++-------------------------- 1 file changed, 50 insertions(+), 46 deletions(-) diff --git a/resolve.c b/resolve.c index dc74aec554f..86ac6e575c5 100644 --- a/resolve.c +++ b/resolve.c @@ -447,54 +447,58 @@ struct hostent* own_gethostbyname2(char *name,int af) inline struct hostent* resolvehost(char* name, int no_ip_test) { - static struct hostent* he=0; + static struct hostent* he=0; #ifdef HAVE_GETIPNODEBYNAME - int err; - static struct hostent* he2=0; + int err; + static struct hostent* he2=0; #endif - struct ip_addr* ip; - str s; - - if (!no_ip_test) { - s.s = (char*)name; - s.len = strlen(name); - - /* check if it's an ip address */ - if ( ((ip=str2ip(&s))!=0) - || ((ip=str2ip6(&s))!=0) - ){ - /* we are lucky, this is an ip address */ - return ip_addr2he(&s, ip); - } - } - - if (dnscache_fetch_func != NULL) { - he = own_gethostbyname2(name,AF_INET); - } - else { - he=gethostbyname(name); - } - if(he==0 && dns_try_ipv6){ - /*try ipv6*/ - #ifdef HAVE_GETHOSTBYNAME2 - if (dnscache_fetch_func != NULL) { - he = own_gethostbyname2(name,AF_INET6); - } - else { - he=gethostbyname2(name, AF_INET6); - } - - #elif defined HAVE_GETIPNODEBYNAME - /* on solaris 8 getipnodebyname has a memory leak, - * after some time calls to it will fail with err=3 - * solution: patch your solaris 8 installation */ - if (he2) freehostent(he2); - he=he2=getipnodebyname(name, AF_INET6, 0, &err); - #else - #error neither gethostbyname2 or getipnodebyname present - #endif - } - return he; + struct ip_addr* ip; + str s; + + if (!no_ip_test) { + s.s = (char*)name; + s.len = strlen(name); + + /* check if it's an ip address */ + if ( ((ip=str2ip(&s))!=0) + || ((ip=str2ip6(&s))!=0) + ){ + /* we are lucky, this is an ip address */ + return ip_addr2he(&s, ip); + } + } + + if(dns_try_ipv6){ + /*try ipv6*/ + #ifdef HAVE_GETHOSTBYNAME2 + if (dnscache_fetch_func != NULL) { + he = own_gethostbyname2(name,AF_INET6); + } + else { + he=gethostbyname2(name, AF_INET6); + } + + #elif defined HAVE_GETIPNODEBYNAME + /* on solaris 8 getipnodebyname has a memory leak, + * after some time calls to it will fail with err=3 + * solution: patch your solaris 8 installation */ + if (he2) freehostent(he2); + he=he2=getipnodebyname(name, AF_INET6, 0, &err); + #else + #error neither gethostbyname2 or getipnodebyname present + #endif + if (he != 0) + /* return the inet6 result if exists */ + return he; + } + + if (dnscache_fetch_func != NULL) { + he = own_gethostbyname2(name,AF_INET); + } + else { + he=gethostbyname(name); + } + return he; } struct hostent * own_gethostbyaddr(void *addr, socklen_t len, int af)