Bugzilla bug 404399: getaddrinfo with AI_NUMERICHOST is slow on Mac OS X NSPR_HEAD_20071218
authorwtc%google.com
Wed, 19 Dec 2007 02:32:28 +0000
changeset 3899 c0097673210be8cc63f9847f2e80f6ebebbf7830
parent 3898 b8daba273af4c8eab7a00dae80af264bec870705
child 3900 8c6449bc4cbf49445d4d74fde872f0cfa658f6e0
push idunknown
push userunknown
push dateunknown
bugs404399
Bugzilla bug 404399: getaddrinfo with AI_NUMERICHOST is slow on Mac OS X (10.4). So we only use it to convert IPv6 address strings with scope IDs. r=dwitte.
pr/src/misc/prnetdb.c
--- a/pr/src/misc/prnetdb.c
+++ b/pr/src/misc/prnetdb.c
@@ -2181,17 +2181,17 @@ static PRStatus pr_StringToNetAddrGAI(co
         status = PR_FAILURE;
     }
 
     FREEADDRINFO(res);
     return status;
 }
 #endif  /* _PR_HAVE_GETADDRINFO */
 
-#if !defined(_PR_HAVE_GETADDRINFO) || defined(_PR_INET6_PROBE)
+#if !defined(_PR_HAVE_GETADDRINFO) || defined(_PR_INET6_PROBE) || defined(DARWIN)
 static PRStatus pr_StringToNetAddrFB(const char *string, PRNetAddr *addr)
 {
     PRStatus status = PR_SUCCESS;
     PRIntn rv;
 
 #if defined(_PR_HAVE_INET_NTOP)
     rv = inet_pton(AF_INET6, string, &addr->ipv6.ip);
     if (1 == rv)
@@ -2238,29 +2238,39 @@ static PRStatus pr_StringToNetAddrFB(con
          */
         PR_SetError(PR_INVALID_ARGUMENT_ERROR, 0);
         status = PR_FAILURE;
     }
 #endif /* _PR_HAVE_INET_NTOP */
 
     return status;
 }
-#endif /* !_PR_HAVE_GETADDRINFO || _PR_INET6_PROBE */
+#endif /* !_PR_HAVE_GETADDRINFO || _PR_INET6_PROBE || DARWIN */
 
 PR_IMPLEMENT(PRStatus) PR_StringToNetAddr(const char *string, PRNetAddr *addr)
 {
     if (!_pr_initialized) _PR_ImplicitInitialization();
 
 #if !defined(_PR_HAVE_GETADDRINFO)
     return pr_StringToNetAddrFB(string, addr);
 #else
 #if defined(_PR_INET6_PROBE)
     if (!_pr_ipv6_is_present)
         return pr_StringToNetAddrFB(string, addr);
 #endif
+#if defined(DARWIN)
+    /*
+     * On Mac OS X, getaddrinfo with AI_NUMERICHOST is slow.
+     * So we only use it to convert literal IP addresses that
+     * contain IPv6 scope IDs, which pr_StringToNetAddrFB
+     * cannot convert.  (See bug 404399.)
+     */
+    if (!strchr(string, '%'))
+        return pr_StringToNetAddrFB(string, addr);
+#endif
     return pr_StringToNetAddrGAI(string, addr);
 #endif
 }
 
 #if defined(_PR_HAVE_GETADDRINFO)
 static PRStatus pr_NetAddrToStringGNI(
     const PRNetAddr *addr, char *string, PRUint32 size)
 {