added IPv6 support, thanks to <jochen2@users.sourceforge.net>

This commit is contained in:
darkeye 2005-04-11 19:34:23 +00:00
parent 426a126181
commit cf2a9bb772
5 changed files with 28 additions and 2 deletions

View File

@ -24,4 +24,5 @@ with contributions by:
Deti Fliegl <deti@fliegl.de>
Nicholas J. Humfrey <njh@ecs.soton.ac.uk>
Joel Ebel <jbebel@ncsu.edu>
<jochen2@users.sourceforge.net>

View File

@ -9,6 +9,7 @@ DarkIce next release
Thanks to Nicholas J. Humfrey <njh@ecs.soton.ac.uk>
o various improvements by Joel Ebel <jbebel@ncsu.edu>
o added option to turn off automatic reconnect feature
o added IPv6 support, thanks to <jochen2@users.sourceforge.net>
15-02-2004: DarkIce 0.14 released

View File

@ -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 <stevenj@alum.mit.edu>

View File

@ -92,6 +92,7 @@ Developed with contributions by
Deti Fliegl <deti@fliegl.de>
Nicholas J. Humfrey <njh@ecs.soton.ac.uk>
Joel Ebel <jbebel@ncsu.edu>
<jochen2@users.sourceforge.net>
.SH LINKS
Project homepage:

View File

@ -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 <jochen2@users.sourceforge.net>
Revision 1.9 2002/10/19 12:22:27 darkeye
cosmetic change