From cf2a9bb772d9bdd30b5ef981119fbbba5ffe025d Mon Sep 17 00:00:00 2001 From: darkeye Date: Mon, 11 Apr 2005 19:34:23 +0000 Subject: [PATCH] added IPv6 support, thanks to --- darkice/trunk/AUTHORS | 1 + darkice/trunk/ChangeLog | 1 + darkice/trunk/configure.in | 2 ++ darkice/trunk/man/darkice.1 | 1 + darkice/trunk/src/TcpSocket.cpp | 25 +++++++++++++++++++++++-- 5 files changed, 28 insertions(+), 2 deletions(-) diff --git a/darkice/trunk/AUTHORS b/darkice/trunk/AUTHORS index 4addae9..4aa1749 100644 --- a/darkice/trunk/AUTHORS +++ b/darkice/trunk/AUTHORS @@ -24,4 +24,5 @@ with contributions by: Deti Fliegl Nicholas J. Humfrey Joel Ebel + diff --git a/darkice/trunk/ChangeLog b/darkice/trunk/ChangeLog index 6d024e6..9004acb 100644 --- a/darkice/trunk/ChangeLog +++ b/darkice/trunk/ChangeLog @@ -9,6 +9,7 @@ DarkIce next release Thanks to Nicholas J. Humfrey o various improvements by Joel Ebel o added option to turn off automatic reconnect feature + o added IPv6 support, thanks to 15-02-2004: DarkIce 0.14 released diff --git a/darkice/trunk/configure.in b/darkice/trunk/configure.in index ae91a07..53d48de 100644 --- a/darkice/trunk/configure.in +++ b/darkice/trunk/configure.in @@ -25,6 +25,8 @@ AC_CHECK_LIB( socket, socket) AC_CHECK_LIB( nsl, gethostbyname) AC_CHECK_LIB( rt, sched_getscheduler) +AC_CHECK_FUNC( getaddrinfo, AC_DEFINE(HAVE_GETADDRINFO, 1, [Does function getaddrinfo exist?] )) + dnl----------------------------------------------------------------------------- dnl funky posix threads checking, thanks to dnl Steven G. Johnson diff --git a/darkice/trunk/man/darkice.1 b/darkice/trunk/man/darkice.1 index 35fb1e9..a53daa3 100644 --- a/darkice/trunk/man/darkice.1 +++ b/darkice/trunk/man/darkice.1 @@ -92,6 +92,7 @@ Developed with contributions by Deti Fliegl Nicholas J. Humfrey Joel Ebel + .SH LINKS Project homepage: diff --git a/darkice/trunk/src/TcpSocket.cpp b/darkice/trunk/src/TcpSocket.cpp index cfbdb15..c33ad33 100644 --- a/darkice/trunk/src/TcpSocket.cpp +++ b/darkice/trunk/src/TcpSocket.cpp @@ -186,13 +186,31 @@ TcpSocket :: operator= ( const TcpSocket & ss ) throw ( Exception ) bool TcpSocket :: open ( void ) throw ( Exception ) { +#ifdef HAVE_ADDRINFO + struct addrinfo hints + struct addrinfo * ptr; + struct sockaddr_storage addr; + char portstr[6]; +#else struct sockaddr_in addr; struct hostent * pHostEntry; - +#endif + if ( isOpen() ) { return false; } +#ifdef HAVE_ADDRINFO + memset(&hints, 0, sizeof(hints)); + hints.ai_socktype = SOCK_STREAM; + hints.ai_family = AF_ANY; + snprintf(portstr, sizeof(portstr), "%d", port); + + if (getaddrinfo(host , portstr, &hints, &ptr)) + throw Exception( __FILE__, __LINE__, "getaddrinfo error", errno); + memcpy ( addr, ptr->ai_addr, ptr->ai_addrlen); + freeaddrinfo(ptr); +#else if ( !(pHostEntry = gethostbyname( host)) ) { throw Exception( __FILE__, __LINE__, "gethostbyname error", errno); } @@ -205,7 +223,7 @@ TcpSocket :: open ( void ) throw ( Exception ) addr.sin_family = AF_INET; addr.sin_port = htons(port); addr.sin_addr.s_addr = *((long*) pHostEntry->h_addr_list[0]); - +#endif if ( connect( sockfd, (struct sockaddr*)&addr, sizeof(addr)) == -1 ) { ::close( sockfd); sockfd = 0; @@ -352,6 +370,9 @@ TcpSocket :: close ( void ) throw ( Exception ) $Source$ $Log$ + Revision 1.10 2005/04/11 19:34:23 darkeye + added IPv6 support, thanks to + Revision 1.9 2002/10/19 12:22:27 darkeye cosmetic change