From e2b56361b819c9a03692fb887babd4ce62026161 Mon Sep 17 00:00:00 2001 From: Jordi Albornoz Date: Sat, 19 Oct 2002 19:37:42 +0000 Subject: [PATCH] patch from Cougar which adds IPv6 support. --- ChangeLog | 7 +++++++ configure.in | 8 +++++++- po/ca.po | 2 +- src/client.c | 57 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 72 insertions(+), 2 deletions(-) diff --git a/ChangeLog b/ChangeLog index 96a0167..9f01c9d 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,10 @@ +2002-10-19 Jordi Mallach + + * Patch from Cougar which adds IPv6 support. + * configure.in: add --enable-ipv6 option. + * src/client.c: add support to ipv6 connections using getaddrinfo() & + friends. + 2002-10-18 Jordi Mallach * src/client.c: tidy spacing between copyright header and code. diff --git a/configure.in b/configure.in index 3cafbb0..39a537e 100644 --- a/configure.in +++ b/configure.in @@ -35,10 +35,16 @@ if test $ac_cv_func_setenv = no; then dnl configure options AC_ARG_ENABLE(detach, [ --enable-detach Enable page detaching (default=no)], - [if test x$enable_detach != xno; then + [if test "x$enable_detach" = "xyes"; then AC_DEFINE(ENABLE_DETACH, 1, [Define this to enable page detaching.]) fi]) +AC_ARG_ENABLE(ipv6, +[ --enable-ipv6 Enable IPv6 support (default=no)], + [if test "x$enable_ipv6" = "xyes"; then + AC_DEFINE(USE_IPV6, 1, [Define this to enable IPv6 support.]) + fi]) + AM_GNU_GETTEXT([external]) AC_OUTPUT([ diff --git a/po/ca.po b/po/ca.po index 8d8536c..c827485 100644 --- a/po/ca.po +++ b/po/ca.po @@ -6,7 +6,7 @@ msgid "" msgstr "" "Project-Id-Version: gtetrinet 0.4.2\n" -"POT-Creation-Date: 2002-10-18 02:41+0200\n" +"POT-Creation-Date: 2002-10-19 21:34+0200\n" "PO-Revision-Date: 2002-10-18 02:51+0200\n" "Last-Translator: Jordi Mallach \n" "Language-Team: Catalan \n" diff --git a/src/client.c b/src/client.c index 0bbbc62..0f37f09 100644 --- a/src/client.c +++ b/src/client.c @@ -339,11 +339,53 @@ clientend: int client_connect (void) { +#ifdef USE_IPV6 + char hbuf[NI_MAXHOST]; + struct addrinfo hints, *res, *res0; + struct sockaddr_in6 sa; + char service[10]; +#else struct hostent *h; struct sockaddr_in sa; +#endif /* set up the connection */ +#ifdef USE_IPV6 + snprintf(service, 9, "%d", spectating?SPECPORT:PORT); + memset(&hints, 0, sizeof(hints)); + hints.ai_family = AF_UNSPEC; + hints.ai_socktype = SOCK_STREAM; + if (getaddrinfo(server, service, &hints, &res0)) { + /* set errno = 0 so that we know it's a getaddrinfo error */ + errno = 0; + return -1; + } + 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 -1; + } + } + getnameinfo(res->ai_addr, res->ai_addrlen, hbuf, sizeof(hbuf), NULL, 0, 0); + if (connect(sock, res->ai_addr, res->ai_addrlen) < 0) { + if (res->ai_next) { + close(sock); + continue; + } else { + close(sock); + freeaddrinfo(res0); + return -1; + } + } + break; + } + freeaddrinfo(res0); +#else h = gethostbyname (server); if (h == 0) { /* set errno = 0 so that we know it's a gethostbyname error */ @@ -360,6 +402,7 @@ int client_connect (void) if (connect (sock, (struct sockaddr *)&sa, sizeof(sa)) < 0) return -1; +#endif /* say hello to the server */ { @@ -442,11 +485,25 @@ int client_readmsg (char *str, int len) void server_ip (unsigned char buf[4]) { +#ifdef USE_IPV6 + struct sockaddr_in6 sin; + struct sockaddr_in *sin4; +#else struct sockaddr_in sin; +#endif int len = sizeof(sin); getpeername (sock, (struct sockaddr *)&sin, &len); +#ifdef USE_IPV6 + if (sin.sin6_family == AF_INET6) { + memcpy (buf, ((char *) &sin.sin6_addr) + 12, 4); + } else { + sin4 = (struct sockaddr_in *) &sin; + memcpy (buf, &sin4->sin_addr, 4); + } +#else memcpy (buf, &sin.sin_addr, 4); +#endif } enum inmsg_type inmsg_translate (char *str) -- 2.50.1