Bug 192589: keep querying the presence of IPv4 and IPv6 interfaces until at MOZILLA_1_3_BRANCH
authorwtc%netscape.com
Thu, 27 Feb 2003 22:23:19 +0000
branchMOZILLA_1_3_BRANCH
changeset 2742 9090710320cf
parent 2711 a17ed345e74f
child 2743 b2a0e949a5a6
push idunknown
push userunknown
push dateunknown
bugs192589
Bug 192589: keep querying the presence of IPv4 and IPv6 interfaces until at least one is up. This allows us to detect the local machine going from offline to online. Tag: MOZILLA_1_3_BRANCH
pr/src/misc/prnetdb.c
--- a/pr/src/misc/prnetdb.c
+++ b/pr/src/misc/prnetdb.c
@@ -172,16 +172,17 @@ const PRIPv6Addr _pr_in6addr_loopback = 
  *
  * We have an implementation using SIOCGIFCONF ioctl and a
  * default implementation that simply sets _pr_have_inet_if
  * and _pr_have_inet6_if to true.  A better implementation
  * would be to use the routing sockets (see Chapter 17 of
  * W. Richard Stevens' Unix Network Programming, Vol. 1, 2nd. Ed.)
  */
 
+static PRLock *_pr_query_ifs_lock = NULL;
 static PRBool _pr_have_inet_if = PR_FALSE;
 static PRBool _pr_have_inet6_if = PR_FALSE;
 
 #undef DEBUG_QUERY_IFS
 
 #if defined(AIX) \
     || (defined(DARWIN) && (!defined(HAVE_GETIFADDRS) \
         || (defined(MACOS_DEPLOYMENT_TARGET) \
@@ -418,23 +419,17 @@ void _PR_InitNet(void)
 #endif
 #if !defined(_PR_NO_DNS_LOCK)
 	_pr_dnsLock = PR_NewLock();
 #endif
 #if !defined(_PR_HAVE_GETPROTO_R)
 	_getproto_lock = PR_NewLock();
 #endif
 #if defined(_PR_INET6) && defined(_PR_HAVE_GETHOSTBYNAME2)
-	_pr_QueryNetIfs();
-#ifdef DEBUG_QUERY_IFS
-	if (_pr_have_inet_if)
-		printf("Have IPv4 source address\n");
-	if (_pr_have_inet6_if)
-		printf("Have IPv6 source address\n");
-#endif
+	_pr_query_ifs_lock = PR_NewLock();
 #endif
 }
 
 void _PR_CleanupNet(void)
 {
 #if !defined(_PR_NO_DNS_LOCK)
     if (_pr_dnsLock) {
         PR_DestroyLock(_pr_dnsLock);
@@ -442,16 +437,22 @@ void _PR_CleanupNet(void)
     }
 #endif
 #if !defined(_PR_HAVE_GETPROTO_R)
     if (_getproto_lock) {
         PR_DestroyLock(_getproto_lock);
         _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;
+    }
+#endif
 }
 
 /*
 ** Allocate space from the buffer, aligning it to "align" before doing
 ** the allocation. "align" must be a power of 2.
 */
 static char *Alloc(PRIntn amount, char **bufp, PRIntn *buflenp, PRIntn align)
 {
@@ -787,16 +788,35 @@ PR_IMPLEMENT(PRStatus) PR_GetIPNodeByNam
 
     if (!_pr_initialized) _PR_ImplicitInitialization();
 
     if (af != PR_AF_INET && af != PR_AF_INET6) {
         PR_SetError(PR_INVALID_ARGUMENT_ERROR, 0);
         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
+     * at least one is up.  This allows us to detect the local
+     * machine going from offline to online.
+     */
+    if (!_pr_have_inet_if && !_pr_have_inet6_if) {
+	_pr_QueryNetIfs();
+#ifdef DEBUG_QUERY_IFS
+	if (_pr_have_inet_if)
+		printf("Have IPv4 source address\n");
+	if (_pr_have_inet6_if)
+		printf("Have IPv6 source address\n");
+#endif
+    }
+    PR_Unlock(_pr_query_ifs_lock);
+#endif
+
 #if defined(_PR_HAVE_GETIPNODEBYNAME)
 	if (flags & PR_AI_V4MAPPED)
 		tmp_flags |= AI_V4MAPPED;
 	if (flags & PR_AI_ADDRCONFIG)
 		tmp_flags |= AI_ADDRCONFIG;
 	if (flags & PR_AI_ALL)
 		tmp_flags |= AI_ALL;
     if (af == PR_AF_INET6)