diff -uNr bmp-0.9.7.orig/Input/cdaudio/http.c bmp-0.9.7/Input/cdaudio/http.c --- bmp-0.9.7.orig/Input/cdaudio/http.c Mon Jun 21 03:48:50 2004 +++ bmp-0.9.7/Input/cdaudio/http.c Sun Oct 9 13:55:42 2005 @@ -22,13 +22,51 @@ #include "http.h" +#define USE_IPV6 /* enable IPv6 support */ + gint http_open_connection(const 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; @@ -44,6 +82,7 @@ sizeof(struct sockaddr_in)) == -1) return 0; +#endif return sock; } diff -uNr bmp-0.9.7.orig/Input/mpg123/http.c bmp-0.9.7/Input/mpg123/http.c --- bmp-0.9.7.orig/Input/mpg123/http.c Sat Dec 4 18:29:05 2004 +++ bmp-0.9.7/Input/mpg123/http.c Sun Oct 9 13:57:34 2005 @@ -40,6 +40,7 @@ #include "mpg123.h" +#define USE_IPV6 /* enable IPv6 support */ #define min(x,y) ((x)<(y)?(x):(y)) #define min3(x,y,z) (min(x,y)<(z)?min(x,y):(z)) @@ -345,8 +346,13 @@ gboolean redirect; gint udp_sock = 0; fd_set set; +#ifdef USE_IPV6 + struct addrinfo hints, *res, *res0; + char service[6]; +#else struct hostent *hp; struct sockaddr_in address; +#endif struct timeval tv; url = (gchar *) arg; @@ -367,6 +373,45 @@ chost = mpg123_cfg.use_proxy ? mpg123_cfg.proxy_host : host; cport = mpg123_cfg.use_proxy ? mpg123_cfg.proxy_port : port; +#ifdef USE_IPV6 + snprintf(service, 6, "%d", cport); + memset(&hints, 0, sizeof(hints)); + hints.ai_socktype = SOCK_STREAM; + if (! getaddrinfo(chost, service, &hints, &res0)) { + eof = TRUE; + for (res = res0; res; res = res->ai_next) { + if ((sock = socket (res->ai_family, res->ai_socktype, res->ai_protocol)) < 0) + continue; + fcntl(sock, F_SETFL, O_NONBLOCK); + status = g_strdup_printf(_("CONNECTING TO %s:%d"), chost, cport); + mpg123_ip.set_info_text(status); + g_free(status); + ((struct sockaddr_in6 *)res->ai_addr)->sin6_port = htons(cport); + if (connect(sock, res->ai_addr, res->ai_addrlen) < 0) { + if (errno != EINPROGRESS) { + close(sock); + continue; + } + } + eof = FALSE; + break; + } + freeaddrinfo(res0); + if (eof) { + status = g_strdup_printf(_("Couldn't connect to host %s:%d"), chost, cport); + show_error_message(status); + g_free(status); + mpg123_ip.set_info_text(NULL); + } + } else { + status = g_strdup_printf(_("Couldn't look up host %s"), chost); + show_error_message(status); + g_free(status); + + mpg123_ip.set_info_text(NULL); + eof = TRUE; + } +#else sock = socket(AF_INET, SOCK_STREAM, 0); fcntl(sock, F_SETFL, O_NONBLOCK); address.sin_family = AF_INET; @@ -383,8 +428,10 @@ mpg123_ip.set_info_text(NULL); eof = TRUE; } +#endif if (!eof) { +#ifndef USE_IPV6 memcpy(&address.sin_addr.s_addr, *(hp->h_addr_list), sizeof(address.sin_addr.s_addr)); address.sin_port = g_htons(cport); @@ -406,6 +453,7 @@ eof = TRUE; } } +#endif while (going) { tv.tv_sec = 0; tv.tv_usec = 10000; @@ -710,22 +758,36 @@ static gint udp_establish_listener(gint * sock) { +#ifdef USE_IPV6 + struct sockaddr_in6 sin; + socklen_t sinlen = sizeof (struct sockaddr_in6); +#else struct sockaddr_in sin; socklen_t sinlen = sizeof(struct sockaddr_in); +#endif #ifdef DEBUG_UDP fprintf(stderr, "Establishing udp listener\n"); #endif - if ((*sock = socket(AF_INET, SOCK_DGRAM, 0)) < 0) { +#ifdef USE_IPV6 + if ((*sock = socket(AF_INET6, SOCK_DGRAM, 0)) < 0) +#else + if ((*sock = socket(AF_INET, SOCK_DGRAM, 0)) < 0) +#endif + { g_log(NULL, G_LOG_LEVEL_CRITICAL, "udp_establish_listener(): unable to create socket"); return -1; } memset(&sin, 0, sinlen); +#ifdef USE_IPV6 + sin.sin6_family = AF_INET6; +#else sin.sin_family = AF_INET; sin.sin_addr.s_addr = g_htonl(INADDR_ANY); +#endif if (bind(*sock, (struct sockaddr *) &sin, sinlen) < 0) { g_log(NULL, G_LOG_LEVEL_CRITICAL, @@ -755,7 +817,11 @@ g_ntohs(sin.sin_port)); #endif +#ifdef USE_IPV6 + return g_ntohs(sin.sin6_port); +#else return g_ntohs(sin.sin_port); +#endif } static int @@ -765,10 +831,14 @@ char *valptr; gchar *title; gint len, i; +#ifdef USE_IPV6 + struct sockaddr_in6 from; +#else struct sockaddr_in from; +#endif socklen_t fromlen; - fromlen = sizeof(struct sockaddr_in); + fromlen = sizeof(from); if ((len = recvfrom(sock, buf, 1024, 0, (struct sockaddr *) &from, @@ -850,8 +920,15 @@ #ifdef DEBUG_UDP else fprintf(stderr, "Sent ack: %s", obuf); +#ifdef USE_IPV6 +{ + char adr[INET6_ADDRSTRLEN]; + inet_ntop(AF_INET6, &from.sin6_addr, adr, INET6_ADDRSTRLEN); + fprintf (stderr,"Remote: [%s]:%d\n", adr, g_ntohs(from.sin6_port)); +#else fprintf(stderr, "Remote: %s:%d\n", inet_ntoa(from.sin_addr), g_ntohs(from.sin_port)); +#endif #endif } } diff -uNr bmp-0.9.7.orig/Input/vorbis/http.c bmp-0.9.7/Input/vorbis/http.c --- bmp-0.9.7.orig/Input/vorbis/http.c Sat Dec 4 18:29:06 2004 +++ bmp-0.9.7/Input/vorbis/http.c Sun Oct 9 13:59:15 2005 @@ -44,6 +44,7 @@ #include "libbeep/util.h" #include "beep/plugin.h" +#define USE_IPV6 /* enable IPv6 support */ #define min(x,y) ((x)<(y)?(x):(y)) #define min3(x,y,z) (min(x,y)<(z)?min(x,y):(z)) @@ -297,8 +298,13 @@ gint cnt, written, error, err_len, port, cport; gboolean redirect; fd_set set; +#ifdef USE_IPV6 + struct addrinfo hints, *res, *res0; + char service[6]; +#else struct hostent *hp; struct sockaddr_in address; +#endif struct timeval tv; url = (gchar *) arg; @@ -319,6 +325,44 @@ chost = vorbis_cfg.use_proxy ? vorbis_cfg.proxy_host : host; cport = vorbis_cfg.use_proxy ? vorbis_cfg.proxy_port : port; +#ifdef USE_IPV6 + snprintf(service, 6, "%d", cport); + memset(&hints, 0, sizeof(hints)); + hints.ai_socktype = SOCK_STREAM; + if (! getaddrinfo(chost, service, &hints, &res0)) { + eof = TRUE; + for (res = res0; res; res = res->ai_next) { + if ((sock = socket (res->ai_family, res->ai_socktype, res->ai_protocol)) < 0) + continue; + fcntl(sock, F_SETFL, O_NONBLOCK); + status = g_strdup_printf(_("CONNECTING TO %s:%d"), chost, cport); + vorbis_ip.set_info_text(status); + g_free(status); + ((struct sockaddr_in6 *)res->ai_addr)->sin6_port = htons(cport); + if (connect(sock, res->ai_addr, res->ai_addrlen) < 0) { + if (errno != EINPROGRESS) { + close(sock); + continue; + } + } + eof = FALSE; + break; + } + freeaddrinfo(res0); + if (eof) { + status = g_strdup_printf(_("Couldn't connect to host %s:%d"), chost, cport); + vorbis_ip.set_info_text(status); + g_free(status); + eof = TRUE; + break; + } + } else { + status = g_strdup_printf(_("Couldn't look up host %s"), chost); + vorbis_ip.set_info_text(status); + g_free(status); + eof = TRUE; + } +#else sock = socket(AF_INET, SOCK_STREAM, 0); fcntl(sock, F_SETFL, O_NONBLOCK); address.sin_family = AF_INET; @@ -335,8 +379,10 @@ vorbis_ip.set_info_text(NULL); eof = TRUE; } +#endif if (!eof) { +#ifndef USE_IPV6 memcpy(&address.sin_addr.s_addr, *(hp->h_addr_list), sizeof(address.sin_addr.s_addr)); address.sin_port = g_htons(cport); @@ -358,6 +404,7 @@ eof = TRUE; } } +#endif while (going) { tv.tv_sec = 0; tv.tv_usec = 10000;