1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
|
$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;
}
|