Return ipv4 and ipv6 addresses when PR_AI_ADDRCONFIG or PR_AI_ALL is set. NSPRPUB_RELEASE_4_0_BRANCH
authorsrinivas%netscape.com
Wed, 26 Jan 2000 19:05:30 +0000
branchNSPRPUB_RELEASE_4_0_BRANCH
changeset 1094 8115e504809f832393a49c3ae94499b0179c390e
parent 1093 d4eac823ba63bdf7d7cd9a7f3bcf3a359394cdce
child 1098 2fe6994a1592eea21e8889c341237d894edd12aa
push idunknown
push userunknown
push dateunknown
bugs24673
Return ipv4 and ipv6 addresses when PR_AI_ADDRCONFIG or PR_AI_ALL is set. Bugzilla #24673.
pr/src/misc/prnetdb.c
--- a/pr/src/misc/prnetdb.c
+++ b/pr/src/misc/prnetdb.c
@@ -414,17 +414,17 @@ PR_IMPLEMENT(PRStatus) PR_GetIPNodeByNam
 #endif
 	LOCK_DNS();
 
 #ifdef _PR_INET6
 #ifdef _PR_HAVE_GETHOSTBYNAME2
     if (af == PR_AF_INET6)
     {
         h = gethostbyname2(name, AF_INET6); 
-        if ((NULL == h) && (flags & (PR_AI_V4MAPPED|PR_AI_ALL)))
+        if ((NULL == h) && (flags & PR_AI_V4MAPPED))
         {
             did_af_inet = PR_TRUE;
             h = gethostbyname2(name, AF_INET);
         }
     }
     else
     {
         did_af_inet = PR_TRUE;
@@ -463,48 +463,48 @@ PR_IMPLEMENT(PRStatus) PR_GetIPNodeByNam
 
 		if (af == PR_AF_INET6) conversion = _PRIPAddrIPv4Mapped;
 		rv = CopyHostent(h, &buf, &bufsize, conversion, hp);
 		if (PR_SUCCESS != rv)
 		    PR_SetError(PR_INSUFFICIENT_RESOURCES_ERROR, 0);
 #if defined(_PR_INET6) && defined(_PR_HAVE_GETIPNODEBYNAME)
 		freehostent(h);
 #endif
+#if defined(_PR_INET6) && defined(_PR_HAVE_GETHOSTBYNAME2)
+		if ((flags & PR_AI_V4MAPPED) && (flags & (PR_AI_ALL|PR_AI_ADDRCONFIG))
+				&& !did_af_inet && (h = gethostbyname2(name, AF_INET)) != 0) {
+			/* Append the V4 addresses to the end of the list */
+			PRIntn na, na_old;
+			char **ap;
+			
+			/* Count the addresses, then grow storage for the pointers */
+			for (na_old = 0, ap = hp->h_addr_list; *ap != 0; na_old++, ap++)
+					{;} /* nothing to execute */
+			for (na = na_old + 1, ap = h->h_addr_list; *ap != 0; na++, ap++)
+					{;} /* nothing to execute */
+			new_addr_list = (char**)Alloc(
+				na * sizeof(char*), &buf, &bufsize, sizeof(char**));
+			if (!new_addr_list) return PR_FAILURE;
+
+			/* Copy the V6 addresses, one at a time */
+			for (na = 0, ap = hp->h_addr_list; *ap != 0; na++, ap++) {
+				new_addr_list[na] = hp->h_addr_list[na];
+			}
+			hp->h_addr_list = new_addr_list;
+
+			/* Copy the V4 addresses, one at a time */
+			for (ap = h->h_addr_list; *ap != 0; na++, ap++) {
+				hp->h_addr_list[na] = Alloc(hp->h_length, &buf, &bufsize, 0);
+				if (!hp->h_addr_list[na]) return PR_FAILURE;
+				MakeIPv4MappedAddr(*ap, hp->h_addr_list[na]);
+			}
+			hp->h_addr_list[na] = 0;
+		}
+#endif
 	}
-#if defined(_PR_INET6) && defined(_PR_HAVE_GETHOSTBYNAME2)
-    if ((flags & PR_AI_ALL) && !did_af_inet &&
-						(h = gethostbyname2(name, AF_INET)) != 0) {
-        /* Append the V4 addresses to the end of the list */
-        PRIntn na, na_old;
-        char **ap;
-        
-        /* Count the addresses, then grow storage for the pointers */
-        for (na_old = 0, ap = hp->h_addr_list; *ap != 0; na_old++, ap++)
-				{;} /* nothing to execute */
-        for (na = na_old + 1, ap = h->h_addr_list; *ap != 0; na++, ap++)
-				{;} /* nothing to execute */
-        new_addr_list = (char**)Alloc(
-            na * sizeof(char*), &buf, &bufsize, sizeof(char**));
-        if (!new_addr_list) return PR_FAILURE;
-
-        /* Copy the V6 addresses, one at a time */
-        for (na = 0, ap = hp->h_addr_list; *ap != 0; na++, ap++) {
-            new_addr_list[na] = hp->h_addr_list[na];
-        }
-        hp->h_addr_list = new_addr_list;
-
-        /* Copy the V4 addresses, one at a time */
-        for (ap = h->h_addr_list; *ap != 0; na++, ap++) {
-            hp->h_addr_list[na] = Alloc(hp->h_length, &buf, &bufsize, 0);
-            if (!hp->h_addr_list[na]) return PR_FAILURE;
-            MakeIPv4MappedAddr(*ap, hp->h_addr_list[na]);
-        }
-        hp->h_addr_list[na] = 0;
-    }
-#endif
 
 	UNLOCK_DNS();
 #ifdef XP_UNIX
 	ENABLECLOCK(&oldset);
 #endif
 	return rv;
 }