<URL: http://bugs.freeciv.org/Ticket/Display.html?id=40394 >

 Use address family from sockaddr instead of hardcoded AF_INET (IPv4).
Difference between IPv4 and IPv6 version of Broadcast/Multicast is
more complex one, so those parts not touched.


 - ML

diff -Nurd -X.diff_ignore freeciv/client/clinet.c freeciv/client/clinet.c
--- freeciv/client/clinet.c     2008-07-22 16:57:42.000000000 +0300
+++ freeciv/client/clinet.c     2008-07-22 17:23:40.000000000 +0300
@@ -199,7 +199,8 @@
     return -1;
   }
   
-  if ((client.conn.sock = socket(AF_INET, SOCK_STREAM, 0)) == -1) {
+  if ((client.conn.sock = socket(server_addr.saddr.sa_family,
+                                 SOCK_STREAM, 0)) == -1) {
     (void) mystrlcpy(errbuf, mystrerror(), errbufsize);
     return -1;
   }
diff -Nurd -X.diff_ignore freeciv/client/servers.c freeciv/client/servers.c
--- freeciv/client/servers.c    2008-07-22 16:57:42.000000000 +0300
+++ freeciv/client/servers.c    2008-07-22 17:24:36.000000000 +0300
@@ -414,14 +414,14 @@
     return FALSE;
   }
   
-  if ((s = socket(AF_INET, SOCK_STREAM, 0)) == -1) {
+  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, (struct sockaddr *) &addr.saddr, sockaddr_size(&addr)) == 
-1) {
+  if (my_connect(s, &addr.saddr, sockaddr_size(&addr)) == -1) {
     if (errno == EINPROGRESS) {
       /* With non-blocking sockets this is the expected result. */
       scan->meta.state = META_CONNECTING;
diff -Nurd -X.diff_ignore freeciv/server/meta.c freeciv/server/meta.c
--- freeciv/server/meta.c       2008-07-22 16:57:41.000000000 +0300
+++ freeciv/server/meta.c       2008-07-22 17:26:46.000000000 +0300
@@ -214,14 +214,14 @@
     return FALSE;
   }
 
-  if ((sock = socket(AF_INET, SOCK_STREAM, 0)) == -1) {
+  if ((sock = socket(meta_addr.saddr.sa_family, SOCK_STREAM, 0)) == -1) {
     freelog(LOG_ERROR, "Metaserver: can't open stream socket: %s",
            mystrerror());
     metaserver_failed();
     return FALSE;
   }
 
-  if (my_connect(sock, (struct sockaddr *) &meta_addr,
+  if (my_connect(sock, &meta_addr.saddr,
                  sockaddr_size(&meta_addr)) == -1) {
     freelog(LOG_ERROR, "Metaserver: connect failed: %s", mystrerror());
     metaserver_failed();
diff -Nurd -X.diff_ignore freeciv/server/sernet.c freeciv/server/sernet.c
--- freeciv/server/sernet.c     2008-07-22 16:57:41.000000000 +0300
+++ freeciv/server/sernet.c     2008-07-22 17:29:23.000000000 +0300
@@ -906,25 +906,26 @@
   const char *group;
   int opt;
 
+  if (!net_lookup_service(srvarg.bind_addr, srvarg.port, &src)) {
+    freelog(LOG_FATAL, _("Server: bad address: [%s:%d]."),
+           srvarg.bind_addr, srvarg.port);
+    exit(EXIT_FAILURE);
+  }
+
   /* Create socket for client connections. */
-  if((sock = socket(AF_INET, SOCK_STREAM, 0)) == -1) {
+  if((sock = socket(src.saddr.sa_family, SOCK_STREAM, 0)) == -1) {
     die("socket failed: %s", mystrerror());
   }
 
-  opt=1; 
+  opt = 1;
   if(setsockopt(sock, SOL_SOCKET, SO_REUSEADDR, 
                (char *)&opt, sizeof(opt)) == -1) {
     freelog(LOG_ERROR, "SO_REUSEADDR failed: %s", mystrerror());
   }
 
-  if (!net_lookup_service(srvarg.bind_addr, srvarg.port, &src)) {
-    freelog(LOG_FATAL, _("Server: bad address: [%s:%d]."),
-           srvarg.bind_addr, srvarg.port);
-    exit(EXIT_FAILURE);
-  }
-
   if(bind(sock, &src.saddr, sockaddr_size(&src)) == -1) {
-    freelog(LOG_FATAL, "bind failed: %s", mystrerror());
+    freelog(LOG_FATAL, "Server bind failed: %s", mystrerror());
+    sockaddr_debug(&src);
     exit(EXIT_FAILURE);
   }
 
_______________________________________________
Freeciv-dev mailing list
Freeciv-dev@gna.org
https://mail.gna.org/listinfo/freeciv-dev

Reply via email to