$NetBSD: patch-ad,v 1.3 2002/10/14 09:47:00 rh Exp $

--- Input/cdaudio/http.c.orig	Fri Jul 21 18:54:17 2000
+++ Input/cdaudio/http.c
@@ -25,9 +25,45 @@
 gint http_open_connection(gchar * server, gint port)
 {
 	gint sock;
+#ifdef USE_IPV6
+	struct addrinfo hints, *res, *res0;
+	char service[6];
+#else
 	struct hostent *host;
 	struct sockaddr_in address;
+#endif
 
+#ifdef USE_IPV6
+	snprintf(service, 6, "%d", port);
+	memset(&hints, 0, sizeof(hints));
+	hints.ai_socktype = SOCK_STREAM;
+
+	if (getaddrinfo(server, service, &hints, &res0))
+		return 0;
+
+	for (res = res0; res; res = res->ai_next) {
+		sock = socket (res->ai_family, res->ai_socktype, res->ai_protocol);
+		if (sock < 0) {
+			if (res->ai_next)
+				continue;
+			else {
+				freeaddrinfo(res0);
+				return 0;
+			}
+		}
+		if (connect(sock, res->ai_addr, res->ai_addrlen) < 0) {
+			if (res->ai_next) {
+				close(sock);
+				continue;
+			} else {
+				freeaddrinfo(res0);
+				return 0;
+			}
+		}
+		freeaddrinfo(res0);
+		return sock;
+	}
+#else
 	sock = socket(AF_INET, SOCK_STREAM, 0);
 	address.sin_family = AF_INET;
 
@@ -40,6 +76,7 @@ gint http_open_connection(gchar * server
 	if (connect(sock, (struct sockaddr *) &address, sizeof (struct sockaddr_in)) == -1)
 		return 0;
 
+#endif
 	return sock;
 }
 
