]> hydra-www.ietfng.org Git - gtetrinet/commitdiff
patch from Cougar <cougar@random.ee> which adds IPv6 support.
authorJordi Albornoz <jordi@src.gnome.org>
Sat, 19 Oct 2002 19:37:42 +0000 (19:37 +0000)
committerJordi Albornoz <jordi@src.gnome.org>
Sat, 19 Oct 2002 19:37:42 +0000 (19:37 +0000)
ChangeLog
configure.in
po/ca.po
src/client.c

index 96a016768aced0a4a3401793a187091fb91be825..9f01c9d9a77635b5bcdbe88d92ad4bd53ed88312 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,10 @@
+2002-10-19  Jordi Mallach  <jordi@sindominio.net>
+
+       * Patch from Cougar <cougar@random.ee> 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  <jordi@sindominio.net>
 
        * src/client.c: tidy spacing between copyright header and code.
index 3cafbb06d74fd787693c0bf2c0a465941fd91226..39a537ecca54c9cf4be3d431c477f6601f8f34cb 100644 (file)
@@ -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([
index 8d8536c47abd51298d886838e95c55f7d9906f31..c8274850979f844099e0c977677ee64a6799c505 100644 (file)
--- 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 <jordi@debian.org>\n"
 "Language-Team: Catalan <ca@dodds.net>\n"
index 0bbbc620b19eb58738efb550b28530aaf5f5e117..0f37f090e955047ade23fbc5b650515f248f05a6 100644 (file)
@@ -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)