9549c46
diff --git a/channels.c b/channels.c
9549c46
--- a/channels.c
9549c46
+++ b/channels.c
9549c46
@@ -3933,16 +3933,26 @@ x11_create_display_inet(int x11_display_
9549c46
 			if (ai->ai_family == AF_INET6)
9549c46
 				sock_set_v6only(sock);
9549c46
 			if (x11_use_localhost)
9549c46
 				set_reuseaddr(sock);
9549c46
 			if (bind(sock, ai->ai_addr, ai->ai_addrlen) == -1) {
d482358
 				debug2_f("bind port %d: %.100s", port,
d482358
 				    strerror(errno));
9549c46
 				close(sock);
9549c46
+
9549c46
+				/* do not remove successfully opened
9549c46
+				 * sockets if the request failed because
9549c46
+				 * the protocol IPv4/6 is not available
9549c46
+				 * (e.g. IPv6 may be disabled while being
9549c46
+				 * supported)
9549c46
+				 */
9549c46
+				if (EADDRNOTAVAIL == errno)
9549c46
+    					continue;
9549c46
+
9549c46
 				for (n = 0; n < num_socks; n++)
9549c46
 					close(socks[n]);
9549c46
 				num_socks = 0;
9549c46
 				break;
9549c46
 			}
9549c46
 			socks[num_socks++] = sock;
9549c46
 			if (num_socks == NUM_SOCKS)
9549c46
 				break;