Author: cazfi
Date: Thu Oct 15 19:09:39 2015
New Revision: 30098

URL: http://svn.gna.org/viewcvs/freeciv?rev=30098&view=rev
Log:
Limit search for free port to 10000 ports instead of infinity if for
some reason it's not possible to bind() any ports.

See patch #6423

Modified:
    trunk/client/connectdlg_common.c
    trunk/utility/netintf.c
    trunk/utility/netintf.h

Modified: trunk/client/connectdlg_common.c
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/client/connectdlg_common.c?rev=30098&r1=30097&r2=30098&view=diff
==============================================================================
--- trunk/client/connectdlg_common.c    (original)
+++ trunk/client/connectdlg_common.c    Thu Oct 15 19:09:39 2015
@@ -174,8 +174,8 @@
 }   
 
 /**************************************************************** 
-forks a server if it can. returns FALSE is we find we couldn't start
-the server.
+  Forks a server if it can. Returns FALSE if we find we
+  couldn't start the server.
 *****************************************************************/ 
 bool client_start_server(void)
 {
@@ -220,9 +220,12 @@
    * used by standalone server on Windows where this is known to be buggy
    * by not starting from DEFAULT_SOCK_PORT but from one higher. */
   internal_server_port = find_next_free_port(DEFAULT_SOCK_PORT + 1,
+                                             DEFAULT_SOCK_PORT + 1 + 10000,
                                              family, "localhost", TRUE);
 
   if (internal_server_port < 0) {
+    log_verbose("None of the ports %d - %d is available to start freeciv 
server on.",
+                DEFAULT_SOCK_PORT + 1, DEFAULT_SOCK_PORT + 1 + 10000);
     output_window_append(ftc_client, _("Couldn't start the server."));
     output_window_append(ftc_client,
                          _("You'll have to start one manually. Sorry..."));

Modified: trunk/utility/netintf.c
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/utility/netintf.c?rev=30098&r1=30097&r2=30098&view=diff
==============================================================================
--- trunk/utility/netintf.c     (original)
+++ trunk/utility/netintf.c     Thu Oct 15 19:09:39 2015
@@ -541,7 +541,8 @@
 /************************************************************************** 
   Finds the next (lowest) free port.
 **************************************************************************/ 
-int find_next_free_port(int starting_port, enum fc_addr_family family,
+int find_next_free_port(int starting_port, int highest_port,
+                        enum fc_addr_family family,
                         char *net_interface, bool not_avail_ok)
 {
   int port;
@@ -571,7 +572,7 @@
      return -1;
   }
 
-  for (port = starting_port; !found ; port++) {
+  for (port = starting_port; !found && highest_port > port; port++) {
     /* HAVE_GETADDRINFO implies IPv6 support */
 #ifdef HAVE_GETADDRINFO
     struct addrinfo hints;
@@ -646,9 +647,13 @@
 #endif /* HAVE_GETADDRINFO */
   }
 
+  if (!found) {
+    return -1;
+  }
+
   /* Rollback the last increment from the loop, back to port
    * number found to be free. */
   port--;
-  
+
   return port;
 }

Modified: trunk/utility/netintf.h
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/utility/netintf.h?rev=30098&r1=30097&r2=30098&view=diff
==============================================================================
--- trunk/utility/netintf.h     (original)
+++ trunk/utility/netintf.h     Thu Oct 15 19:09:39 2015
@@ -127,7 +127,8 @@
                                            enum fc_addr_family family);
 bool fc_inet_aton(const char *cp, struct in_addr *inp, bool addr_none_ok);
 fz_FILE *fc_querysocket(int sock, void *buf, size_t size);
-int find_next_free_port(int starting_port, enum fc_addr_family family,
+int find_next_free_port(int starting_port, int highest_port,
+                        enum fc_addr_family family,
                         char *net_interface, bool not_avail_ok);
 
 void sockaddr_debug(union fc_sockaddr *addr, enum log_level lvl);


_______________________________________________
Freeciv-commits mailing list
Freeciv-commits@gna.org
https://mail.gna.org/listinfo/freeciv-commits

Reply via email to