Re: [Freeciv-Dev] (PR#40296) [Patch] IPv6

2008-07-24 Thread Marko Lindqvist

URL: http://bugs.freeciv.org/Ticket/Display.html?id=40296 

 - Updated against svn
 - Crude dual-stack implementation (improvements to that will be left
to future tickets)

 I'm still going to commit some parts of this separately as they get
cleaned up enough.


 - ML

diff -Nurd -X.diff_ignore freeciv/client/clinet.c freeciv/client/clinet.c
--- freeciv/client/clinet.c 2008-07-25 00:22:34.0 +0300
+++ freeciv/client/clinet.c 2008-07-25 00:22:41.0 +0300
@@ -167,8 +167,13 @@
 port = DEFAULT_SOCK_PORT;
 
   /* use name to find TCP/IP address of server */
-  if (!hostname)
+  if (!hostname) {
+#ifdef IPV6_USED
+hostname = ip6-localhost;
+#else  /* IPV6 used */
 hostname = localhost;
+#endif /* IPV6 used */
+  }
 
   if (!net_lookup_service(hostname, port, server_addr)) {
 (void) mystrlcpy(errbuf, _(Failed looking up host.), errbufsize);
@@ -198,7 +203,7 @@
 (void) mystrlcpy(errbuf, _(Connection in progress.), errbufsize);
 return -1;
   }
-  
+
   if ((client.conn.sock = socket(server_addr.saddr.sa_family,
  SOCK_STREAM, 0)) == -1) {
 (void) mystrlcpy(errbuf, mystrerror(), errbufsize);
diff -Nurd -X.diff_ignore freeciv/client/connectdlg_common.c 
freeciv/client/connectdlg_common.c
--- freeciv/client/connectdlg_common.c  2008-07-14 21:49:09.0 +0300
+++ freeciv/client/connectdlg_common.c  2008-07-25 00:22:41.0 +0300
@@ -206,7 +206,13 @@
   append_output_window(_(Starting server...));
 
   /* find a free port */ 
-  internal_server_port = find_next_free_port(DEFAULT_SOCK_PORT);
+  internal_server_port = find_next_free_port(DEFAULT_SOCK_PORT,
+#ifdef IPV6_USED
+  TRUE
+#else  /* IPv6 used */
+  FALSE
+#endif /* IPv6 used */
+  );
 
 # ifdef HAVE_WORKING_FORK
   server_pid = fork();
@@ -258,7 +264,7 @@
   fchmod(1, 0644);
 }
 
-/* If it's still attatched to our terminal, things get messed up, 
+/* If it's still attached to our terminal, things get messed up, 
   but civserver needs *something* */ 
 fclose(stdin);
 fd = open(/dev/null, O_RDONLY);
diff -Nurd -X.diff_ignore freeciv/client/servers.c freeciv/client/servers.c
--- freeciv/client/servers.c2008-07-25 00:22:34.0 +0300
+++ freeciv/client/servers.c2008-07-25 00:22:41.0 +0300
@@ -413,14 +413,14 @@
 (scan-error_func)(scan, _(Failed looking up metaserver's host));
 return FALSE;
   }
-  
+
   if ((s = socket(addr.saddr.sa_family, SOCK_STREAM, 0)) == -1) {
 (scan-error_func)(scan, mystrerror());
 return FALSE;
   }
 
   my_nonblock(s);
-  
+
   if (my_connect(s, addr.saddr, sockaddr_size(addr)) == -1) {
 if (errno == EINPROGRESS) {
   /* With non-blocking sockets this is the expected result. */
@@ -538,15 +538,27 @@
 #else  /* HAVE_WINSOCK */
   char buffer[MAX_LEN_PACKET];
 #endif /* HAVE_WINSOCK */
-  struct ip_mreq mreq;
+  struct ip_mreq mreq4;
   const char *group;
   size_t size;
+  int family;
+
+#ifdef IPV6_SUPPORT
+  struct ipv6_mreq mreq6;
+#endif
+
 #ifndef HAVE_WINSOCK
   unsigned char ttl;
-#endif
+#endif /* WINSOCK */
+
+#ifdef IPV6_USED
+  family = AF_INET6;
+#else  /* IPv6 used */
+  family = AF_INET;
+#endif /* IPv6 used */
 
   /* Create a socket for broadcasting to servers. */
-  if ((sock = socket(AF_INET, SOCK_DGRAM, 0))  0) {
+  if ((sock = socket(family, SOCK_DGRAM, 0))  0) {
 freelog(LOG_ERROR, socket failed: %s, mystrerror());
 return FALSE;
   }
@@ -559,9 +571,20 @@
   /* Set the UDP Multicast group IP address. */
   group = get_multicast_group();
   memset(addr, 0, sizeof(addr));
-  addr.saddr_in4.sin_family = AF_INET;
-  addr.saddr_in4.sin_addr.s_addr = inet_addr(get_multicast_group());
-  addr.saddr_in4.sin_port = htons(SERVER_LAN_PORT);
+#ifndef IPV6_SUPPORT
+  {
+inet_aton(group, addr.saddr_in4.sin_addr);
+#else  /* IPv6 support */
+  if (family == AF_INET6) {
+addr.saddr.sa_family = AF_INET6;
+inet_pton(AF_INET6, group, addr.saddr_in6.sin6_addr);
+addr.saddr_in6.sin6_port = htons(SERVER_LAN_PORT);
+  } else {
+inet_pton(AF_INET, group, addr.saddr_in4.sin_addr);
+#endif /* IPv6 support */
+addr.saddr.sa_family = AF_INET;
+addr.saddr_in4.sin_port = htons(SERVER_LAN_PORT);
+  }
 
 /* this setsockopt call fails on Windows 98, so we stick with the default
  * value of 1 on Windows, which should be fine in most cases */
@@ -573,7 +596,7 @@
 freelog(LOG_ERROR, setsockopt failed: %s, mystrerror());
 return FALSE;
   }
-#endif
+#endif /* HAVE_WINSOCK */
 
   if (setsockopt(sock, SOL_SOCKET, SO_BROADCAST, (const char*)opt, 
  sizeof(opt))) {
@@ -587,7 +610,7 @@
  
 
   if (sendto(sock, buffer, size, 0, addr.saddr,
-  sockaddr_size(addr))  0) {
+ sockaddr_size(addr))  0) {
 /* This can happen when there's no network connection - it should
  * give an in-game message. */
 freelog(LOG_ERROR, lanserver scan sendto failed: %s, mystrerror());
@@ -599,7 +622,7 @@
   my_closesocket(sock);
 

Re: [Freeciv-Dev] (PR#40296) [Patch] IPv6

2008-07-06 Thread Marko Lindqvist

URL: http://bugs.freeciv.org/Ticket/Display.html?id=40296 

 - A lot of cleanup
 - IPv6 multicast works


 I've already started splitting ready parts of this in to separate
patches ready for commit.


 - ML



IPv6_40296-3.diff.bz2
Description: BZip2 compressed data
___
Freeciv-dev mailing list
Freeciv-dev@gna.org
https://mail.gna.org/listinfo/freeciv-dev


Re: [Freeciv-Dev] (PR#40296) [Patch] IPv6

2008-07-03 Thread Marko Lindqvist

URL: http://bugs.freeciv.org/Ticket/Display.html?id=40296 

2008/6/20 Marko Lindqvist:

  This is my take of IPv6 support.

 Mostly rewritten for this second version...

 - Cleanup
 - Fourth configuration value for --enable-ipv6; support. Like
test, except will fail if IPv6 support cannot be built in
 - Default configuration is now to use IPv4 with old functions. No
problems of the new implementation should affect default build
 - Metaserver connections work with support and test configurations


 TODO:
 - IPv6 lan broadcast
 - Runtime support for simultaneous IPv4 and IPv6 connections
(connection to metaserver might be different from client connections)
 - More cleanup


 - ML



IPv6_40296-2.diff.bz2
Description: BZip2 compressed data
___
Freeciv-dev mailing list
Freeciv-dev@gna.org
https://mail.gna.org/listinfo/freeciv-dev