Add runtime detection of ipv6 support on Linux and Solaris. Bugzilla 25153. NSPRPUB_RELEASE_4_0_BRANCH
authorsrinivas%netscape.com
Mon, 31 Jan 2000 16:01:54 +0000
branchNSPRPUB_RELEASE_4_0_BRANCH
changeset 1120 65ac6293d35ebb5c0f0ea62707c837a9548fe760
parent 1119 2ff157f9e3d1b6dfa7acb3f33a31b1a2262c70e5
child 1121 0e8af6b83ed411f7fd58685094ca5cfc1b4db5fc
push idunknown
push userunknown
push dateunknown
bugs25153
Add runtime detection of ipv6 support on Linux and Solaris. Bugzilla 25153.
pr/src/pthreads/ptio.c
--- a/pr/src/pthreads/ptio.c
+++ b/pr/src/pthreads/ptio.c
@@ -2683,17 +2683,33 @@ PR_IMPLEMENT(PRFileDesc*) PR_AllocFileDe
     fd->secret->inheritable = PR_TRUE;
     return fd;
     
 failed:
     PR_SetError(PR_OUT_OF_MEMORY_ERROR, 0);
     return fd;
 }  /* PR_AllocFileDesc */
 
-extern PRStatus _pr_push_ipv6toipv4_layer(PRFileDesc *fd);
+#if !defined(_PR_INET6) || defined(_PR_INET6_PROBE)
+PR_EXTERN(PRStatus) _pr_push_ipv6toipv4_layer(PRFileDesc *fd);
+#if defined(_PR_INET6_PROBE)
+PR_EXTERN(PRBool) _pr_ipv6_is_present;
+PR_IMPLEMENT(PRBool) _pr_test_ipv6_socket()
+{
+PRInt32 osfd;
+
+	osfd = socket(AF_INET6, SOCK_STREAM, 0);
+	if (osfd != -1) {
+		close(osfd);
+		return PR_TRUE;
+	}
+	return PR_FALSE;
+}
+#endif	/* _PR_INET6_PROBE */
+#endif
 
 PR_IMPLEMENT(PRFileDesc*) PR_Socket(PRInt32 domain, PRInt32 type, PRInt32 proto)
 {
     PRIntn osfd;
     PRDescType ftype;
     PRFileDesc *fd = NULL;
 	PRInt32 tmp_domain = domain;
 
@@ -2711,37 +2727,50 @@ PR_IMPLEMENT(PRFileDesc*) PR_Socket(PRIn
 	if (type == SOCK_STREAM) ftype = PR_DESC_SOCKET_TCP;
 	else if (type == SOCK_DGRAM) ftype = PR_DESC_SOCKET_UDP;
 	else
 	{
 		(void)PR_SetError(PR_ADDRESS_NOT_SUPPORTED_ERROR, 0);
 		return fd;
 	}
 #if defined(_PR_INET6)
-	if (PR_AF_INET6 == domain)
+	if (PR_AF_INET6 == domain) {
+#if defined(_PR_INET6_PROBE)
+        if (_pr_ipv6_is_present == PR_FALSE) 
+            domain = AF_INET;
+        else
+#endif
 		domain = AF_INET6;
+    }
+#elif defined(_PR_INET6_PROBE)
+	if (PR_AF_INET6 == domain) {
+		if (_pr_ipv6_is_present == PR_FALSE) 
+			domain = AF_INET;
+		else
+			domain = AF_INET6;
+	}
 #else
 	if (PR_AF_INET6 == domain)
 		domain = AF_INET;
 #endif
 
     osfd = socket(domain, type, proto);
     if (osfd == -1) pt_MapError(_PR_MD_MAP_SOCKET_ERROR, errno);
     else
     {
         fd = pt_SetMethods(osfd, ftype, PR_FALSE);
         if (fd == NULL) close(osfd);
     }
-#if !defined(_PR_INET6)
+#if !defined(_PR_INET6) || defined(_PR_INET6_PROBE)
 	if (fd != NULL) {
 		/*
 		 * For platforms with no support for IPv6 
 		 * create layered socket for IPv4-mapped IPv6 addresses
 		 */
-		if (PR_AF_INET6 == tmp_domain) {
+		if (PR_AF_INET6 == tmp_domain && PR_AF_INET == domain) {
 			if (PR_FAILURE == _pr_push_ipv6toipv4_layer(fd)) {
 				PR_Close(fd);
 				fd = NULL;
 			}
 		}
 	}
 #endif
     return fd;