Index: mozilla/nsprpub/pr/include/md/_darwin.h =================================================================== RCS file: /cvsroot/mozilla/nsprpub/pr/include/md/_darwin.h,v retrieving revision 3.10.4.3 diff -c -r3.10.4.3 _darwin.h *** mozilla/nsprpub/pr/include/md/_darwin.h 22 Feb 2003 15:08:27 -0000 3.10.4.3 --- mozilla/nsprpub/pr/include/md/_darwin.h 21 Apr 2003 15:08:35 -0000 *************** *** 67,73 **** * getipnodebyname(3) man page on Mac OS X 10.2 says they are not * thread-safe. AI_V4MAPPED|AI_ADDRCONFIG doesn't work either. */ ! #define _PR_HAVE_GETHOSTBYNAME2 /* * On Mac OS X 10.2, gethostbyaddr fails with h_errno=NO_RECOVERY * if you pass an IPv4-mapped IPv6 address to it. --- 67,73 ---- * getipnodebyname(3) man page on Mac OS X 10.2 says they are not * thread-safe. AI_V4MAPPED|AI_ADDRCONFIG doesn't work either. */ ! /*#define _PR_HAVE_GETHOSTBYNAME2*/ /* * On Mac OS X 10.2, gethostbyaddr fails with h_errno=NO_RECOVERY * if you pass an IPv4-mapped IPv6 address to it. *************** *** 75,81 **** #define _PR_GHBA_DISALLOW_V4MAPPED /* socket(AF_INET6) fails with EPROTONOSUPPORT on Mac OS X 10.1. */ #if MACOS_DEPLOYMENT_TARGET < 100200 ! #define _PR_INET6_PROBE #endif /* Mac OS X 10.2 has inet_ntop and inet_pton. */ #if MACOS_DEPLOYMENT_TARGET >= 100200 --- 75,81 ---- #define _PR_GHBA_DISALLOW_V4MAPPED /* socket(AF_INET6) fails with EPROTONOSUPPORT on Mac OS X 10.1. */ #if MACOS_DEPLOYMENT_TARGET < 100200 ! /*#define _PR_INET6_PROBE*/ #endif /* Mac OS X 10.2 has inet_ntop and inet_pton. */ #if MACOS_DEPLOYMENT_TARGET >= 100200 *************** *** 96,101 **** --- 96,104 ---- #endif /* __ppc__ */ #define USE_SETJMP + + /*#define _PR_HAVE_GETIPNODEBYNAME*/ + #define _PR_HAVE_MACOSX_GETADDRINFO #if !defined(_PR_PTHREADS) Index: mozilla/nsprpub/pr/src/misc/prnetdb.c =================================================================== RCS file: /cvsroot/mozilla/nsprpub/pr/src/misc/prnetdb.c,v retrieving revision 3.21.2.12 diff -c -r3.21.2.12 prnetdb.c *** mozilla/nsprpub/pr/src/misc/prnetdb.c 25 Feb 2003 15:08:45 -0000 3.21.2.12 --- mozilla/nsprpub/pr/src/misc/prnetdb.c 21 Apr 2003 15:08:39 -0000 *************** *** 50,55 **** --- 50,59 ---- #define _MD_GETHOST_ERRNO() _MD_ERRNO() #endif + + #define DEBUG_QUERY_IFS + + /* * The meaning of the macros related to gethostbyname, gethostbyaddr, * and gethostbyname2 is defined below. *************** *** 163,169 **** #define _PR_IN6_V4MAPPED_TO_IPADDR(a) ((a)->pr_s6_addr32[3]) ! #if defined(_PR_INET6) && defined(_PR_HAVE_GETHOSTBYNAME2) /* * The _pr_QueryNetIfs() function finds out if the system has --- 167,173 ---- #define _PR_IN6_V4MAPPED_TO_IPADDR(a) ((a)->pr_s6_addr32[3]) ! #if defined(_PR_INET6) && (defined(_PR_HAVE_GETHOSTBYNAME2) || defined(_PR_HAVE_MACOSX_GETADDRINFO)) /* * The _pr_QueryNetIfs() function finds out if the system has *************** *** 424,430 **** #if !defined(_PR_HAVE_GETPROTO_R) _getproto_lock = PR_NewLock(); #endif ! #if defined(_PR_INET6) && defined(_PR_HAVE_GETHOSTBYNAME2) _pr_query_ifs_lock = PR_NewLock(); #endif } --- 428,434 ---- #if !defined(_PR_HAVE_GETPROTO_R) _getproto_lock = PR_NewLock(); #endif ! #if defined(_PR_INET6) && (defined(_PR_HAVE_GETHOSTBYNAME2) || defined(_PR_HAVE_MACOSX_GETADDRINFO)) _pr_query_ifs_lock = PR_NewLock(); #endif } *************** *** 443,449 **** _getproto_lock = NULL; } #endif ! #if defined(_PR_INET6) && defined(_PR_HAVE_GETHOSTBYNAME2) if (_pr_query_ifs_lock) { PR_DestroyLock(_pr_query_ifs_lock); _pr_query_ifs_lock = NULL; --- 447,453 ---- _getproto_lock = NULL; } #endif ! #if defined(_PR_INET6) && (defined(_PR_HAVE_GETHOSTBYNAME2) || defined(_PR_HAVE_MACOSX_GETADDRINFO)) if (_pr_query_ifs_lock) { PR_DestroyLock(_pr_query_ifs_lock); _pr_query_ifs_lock = NULL; *************** *** 726,732 **** extern void * _pr_freehostent_fp; #endif ! #if defined(_PR_INET6) && defined(_PR_HAVE_GETHOSTBYNAME2) /* ** Append the V4 addresses to the end of the list */ --- 730,736 ---- extern void * _pr_freehostent_fp; #endif ! #if defined(_PR_INET6) && (defined(_PR_HAVE_GETHOSTBYNAME2) || defined(_PR_HAVE_MACOSX_GETADDRINFO)) /* ** Append the V4 addresses to the end of the list */ *************** *** 766,771 **** --- 770,855 ---- } #endif + #if defined(_PR_INET6) && defined(_PR_HAVE_MACOSX_GETADDRINFO) + #define MAXLISTS 35 + #define MAXBUFF 1024 + + static char *host_aliases[2]; + static struct hostent hostent; + static char *host_addr_lists[MAXLISTS]; + static char hostbuffer[MAXBUFF]; + #define BUFFRESTLEN(p) (MAXBUFF - (p - hostbuffer)) + + static struct hostent * + gethostentwithgetaddrinfo(hostname, af) + char *hostname; + int af; + { + struct addrinfo hints, *res0, *ai; + char *cname = NULL, *p = hostbuffer; + int addrlen = (af == AF_INET6) ? sizeof(struct in6_addr) : sizeof(struct in_addr); + struct hostent *h = NULL; + int i; + + bzero(&hints, sizeof(hints)); + hints.ai_family = af; + hints.ai_flags = AI_CANONNAME; + hints.ai_socktype = SOCK_STREAM; + if (getaddrinfo(hostname, NULL, &hints, &res0)) + return (NULL); + if (res0 == NULL) + goto done; + + for (ai = res0; ai; ai = ai->ai_next) { + if (!cname && ai->ai_canonname && strcmp(ai->ai_canonname, hostname) != 0) { + cname = ai->ai_canonname; + } + } + + bzero(&hostent, sizeof(hostent)); + + hostent.h_name = p; + if (BUFFRESTLEN(p + strlen(cname ? cname : hostname) + 1) < 0) + goto done; + strncpy(hostent.h_name, cname ? cname : hostname, BUFFRESTLEN(p)); + p += strlen(hostent.h_name) + 1; + + bzero(&host_aliases, sizeof(host_aliases)); + hostent.h_aliases = host_aliases; + if (cname) { + p += sizeof(host_aliases); + host_aliases[0] = p; + if (BUFFRESTLEN(p + strlen(hostname) + 1) < 0) + goto done; + strncpy(host_aliases[0], hostname, BUFFRESTLEN(p)); + p += strlen(hostname) + 1; + } + + hostent.h_addrtype = af; + hostent.h_length = addrlen; + + hostent.h_addr_list = host_addr_lists; + bzero(&host_addr_lists, sizeof(host_addr_lists)); + + for (ai = res0, i = 0; ai && i < MAXLISTS; ai = ai->ai_next, i++) { + hostent.h_addr_list[i] = p; + if (BUFFRESTLEN(p + addrlen) < 0) + goto done; + if (af == AF_INET6) + bcopy(&((struct sockaddr_in6 *)ai->ai_addr)->sin6_addr, p, addrlen); + else + bcopy(&((struct sockaddr_in *)ai->ai_addr)->sin_addr, p, addrlen); + p += addrlen; + } + + h = &hostent; + + done: + freeaddrinfo(res0); + return (h); + } + #endif + PR_IMPLEMENT(PRStatus) PR_GetIPNodeByName( const char *name, PRUint16 af, PRIntn flags, char *buf, PRIntn bufsize, PRHostEnt *hp) *************** *** 783,789 **** int error_num; int tmp_flags = 0; #endif ! #if defined(_PR_HAVE_GETHOSTBYNAME2) PRBool did_af_inet = PR_FALSE; #endif --- 867,873 ---- int error_num; int tmp_flags = 0; #endif ! #if defined(_PR_HAVE_GETHOSTBYNAME2) || defined(_PR_HAVE_MACOSX_GETADDRINFO) PRBool did_af_inet = PR_FALSE; #endif *************** *** 794,800 **** return PR_FAILURE; } ! #if defined(_PR_INET6) && defined(_PR_HAVE_GETHOSTBYNAME2) PR_Lock(_pr_query_ifs_lock); /* * Keep querying the presence of IPv4 and IPv6 interfaces until --- 878,884 ---- return PR_FAILURE; } ! #if defined(_PR_INET6) && (defined(_PR_HAVE_GETHOSTBYNAME2) || defined(_PR_HAVE_MACOSX_GETADDRINFO)) PR_Lock(_pr_query_ifs_lock); /* * Keep querying the presence of IPv4 and IPv6 interfaces until *************** *** 869,874 **** --- 953,981 ---- } #elif defined(_PR_HAVE_GETIPNODEBYNAME) h = getipnodebyname(name, md_af, tmp_flags, &error_num); + #elif defined(_PR_HAVE_MACOSX_GETADDRINFO) + LOCK_DNS(); + if (af == PR_AF_INET6) + { + if ((flags & PR_AI_ADDRCONFIG) == 0 || _pr_have_inet6_if) + { + h = gethostentwithgetaddrinfo(name, AF_INET6); + } + if ((NULL == h) && (flags & PR_AI_V4MAPPED) + && ((flags & PR_AI_ADDRCONFIG) == 0 || _pr_have_inet_if)) + { + did_af_inet = PR_TRUE; + h = gethostentwithgetaddrinfo(name, AF_INET); + } + } + else + { + if ((flags & PR_AI_ADDRCONFIG) == 0 || _pr_have_inet_if) + { + did_af_inet = PR_TRUE; + h = gethostentwithgetaddrinfo(name, af); + } + } #else #error "Unknown name-to-address translation function" #endif /* _PR_HAVE_GETHOSTBYNAME2 */ *************** *** 916,922 **** if (_pr_ipv6_is_present == PR_TRUE) (*((_pr_freehostent_t)_pr_freehostent_fp))(h); #endif ! #if defined(_PR_INET6) && defined(_PR_HAVE_GETHOSTBYNAME2) if ((PR_SUCCESS == rv) && (flags & PR_AI_V4MAPPED) && ((flags & PR_AI_ALL) || ((flags & PR_AI_ADDRCONFIG) && _pr_have_inet_if)) --- 1023,1029 ---- if (_pr_ipv6_is_present == PR_TRUE) (*((_pr_freehostent_t)_pr_freehostent_fp))(h); #endif ! #if defined(_PR_INET6) && (defined(_PR_HAVE_GETHOSTBYNAME2) || defined(_PR_HAVE_MACOSX_GETADDRINFO)) if ((PR_SUCCESS == rv) && (flags & PR_AI_V4MAPPED) && ((flags & PR_AI_ALL) || ((flags & PR_AI_ADDRCONFIG) && _pr_have_inet_if)) *************** *** 930,936 **** /* Must match the convoluted logic above for LOCK_DNS() */ #ifdef _PR_INET6 ! #ifdef _PR_HAVE_GETHOSTBYNAME2 UNLOCK_DNS(); #endif /* _PR_HAVE_GETHOSTBYNAME2 */ #elif defined(_PR_INET6_PROBE) && defined(_PR_HAVE_GETIPNODEBYNAME) --- 1037,1043 ---- /* Must match the convoluted logic above for LOCK_DNS() */ #ifdef _PR_INET6 ! #if defined(_PR_HAVE_GETHOSTBYNAME2) || defined(_PR_HAVE_MACOSX_GETADDRINFO) UNLOCK_DNS(); #endif /* _PR_HAVE_GETHOSTBYNAME2 */ #elif defined(_PR_INET6_PROBE) && defined(_PR_HAVE_GETIPNODEBYNAME)