09127ac
diff -up openssl-1.0.0c/apps/s_socket.c.ipv6listen openssl-1.0.0c/apps/s_socket.c
09127ac
--- openssl-1.0.0c/apps/s_socket.c.ipv6listen	2011-01-24 16:44:18.000000000 +0100
09127ac
+++ openssl-1.0.0c/apps/s_socket.c	2011-01-24 16:56:25.000000000 +0100
09127ac
@@ -335,15 +335,16 @@ int do_server(char *port, int type, int 
09127ac
 
09127ac
 static int init_server(int *sock, char *port, int type)
09127ac
 	{
09127ac
-	struct addrinfo *res, *res0, hints;
09127ac
+	struct addrinfo *res, *res0 = NULL, hints;
09127ac
 	char * failed_call = NULL;
09127ac
-	char port_name[8];
09127ac
 	int s;
09127ac
 	int e;
09127ac
 
09127ac
 	if (!ssl_sock_init()) return(0);
09127ac
 
09127ac
 	memset(&hints, '\0', sizeof(hints));
09127ac
+        hints.ai_family = AF_INET6;
09127ac
+tryipv4:
09127ac
 	hints.ai_socktype = type;
09127ac
 	hints.ai_flags = AI_PASSIVE | AI_ADDRCONFIG;
09127ac
 	
09127ac
@@ -365,6 +366,12 @@ static int init_server(int *sock, char *
09127ac
 			failed_call = "socket";
09127ac
 			goto nextres;
09127ac
 			}
09127ac
+		if (hints.ai_family == AF_INET6)
09127ac
+			{
09127ac
+			int j = 0;
09127ac
+			setsockopt(s, IPPROTO_IPV6, IPV6_V6ONLY,
09127ac
+				   (void *) &j, sizeof j);
09127ac
+			}
09127ac
 #if defined SOL_SOCKET && defined SO_REUSEADDR
09127ac
 		{
09127ac
 		int j = 1;
09127ac
@@ -392,9 +399,19 @@ nextres:
09127ac
 			close(s);
09127ac
 		res = res->ai_next;
09127ac
 	}
09127ac
-	freeaddrinfo(res0);
09127ac
+	if (res0)
09127ac
+		freeaddrinfo(res0);
09127ac
 
09127ac
-	if (s == INVALID_SOCKET) { perror("socket"); return(0); }
09127ac
+	if (s == INVALID_SOCKET)
09127ac
+	{
09127ac
+		if (hints.ai_family == AF_INET6)
09127ac
+		{
09127ac
+			hints.ai_family = AF_INET;
09127ac
+			goto tryipv4;
09127ac
+		}
09127ac
+		perror("socket");
09127ac
+		return(0);
09127ac
+	}
09127ac
 
09127ac
 	perror(failed_call);
09127ac
 	return(0);