[Freeciv-Dev] (PR#6887) Patch to allow server to listen
[Top] [All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
To: |
undisclosed-recipients: ; |
Subject: |
[Freeciv-Dev] (PR#6887) Patch to allow server to listen |
From: |
"Guest" <rt-guest@xxxxxxxxxxx> |
Date: |
Sun, 16 Nov 2003 09:31:31 -0800 |
Reply-to: |
rt@xxxxxxxxxxx |
<URL: http://rt.freeciv.org/Ticket/Display.html?id=6887 >
The small attached patch adds an extra option "--bind ADDR" to
civserver. This causes the listening socket to be bound to a particular
address instead of INADDR_ANY, so that in the frequent case of having
server and client(s) on the same machine you aren't forced to open a
port to the rest of the Internet.
The vast majority of people will want to use "--bind localhost", but
I've allowed any address to be specified in case it's useful to someone
(e.g. to specify an internal network).
The patch is against 1.14.0, but looking at CVS I don't see that
there'll be any trouble applying it. I've tested in on Linux (Debian
3.0), but I don't believe I have introduced any new portability issues,
so it should be OK on other platforms.
diff -ur freeciv-1.14.0-orig/server/civserver.c
freeciv-1.14.0/server/civserver.c
--- freeciv-1.14.0-orig/server/civserver.c Wed Jun 12 08:24:48 2002
+++ freeciv-1.14.0/server/civserver.c Sun Nov 16 16:26:45 2003
@@ -91,7 +91,9 @@
showhelp = TRUE;
break;
}
- } else if ((option = get_option("--read", argv, &inx, argc)))
+ } else if ((option = get_option("--bind", argv, &inx, argc)))
+ srvarg.bind_addr = option;
+ else if ((option = get_option("--read", argv, &inx, argc)))
srvarg.script_filename = option;
else if ((option = get_option("--quitidle", argv, &inx, argc))) {
if (sscanf(option, "%d", &srvarg.quitidle) != 1) {
@@ -127,6 +129,7 @@
if (showhelp) {
fprintf(stderr, _("Usage: %s [option ...]\nValid options are:\n"),
argv[0]);
+ fprintf(stderr, _(" -b, --bind ADDR\tBind to address ADDR (eg
127.0.0.1)\n"));
#ifdef DEBUG
fprintf(stderr, _(" -d, --debug NUM\tSet debug log level (0 to 4,"
" or 4:file1,min,max:...)\n"));
diff -ur freeciv-1.14.0-orig/server/sernet.c freeciv-1.14.0/server/sernet.c
--- freeciv-1.14.0-orig/server/sernet.c Sat Oct 12 00:35:50 2002
+++ freeciv-1.14.0/server/sernet.c Sun Nov 16 17:01:41 2003
@@ -743,8 +743,15 @@
}
memset(&src, 0, sizeof(src));
- src.sin_family = AF_INET;
- src.sin_addr.s_addr = htonl(INADDR_ANY);
+ if (srvarg.bind_addr) {
+ if (!fc_lookup_host(srvarg.bind_addr, &src)) {
+ freelog(LOG_FATAL, "bad bind address [%s]", srvarg.bind_addr);
+ exit(EXIT_FAILURE);
+ }
+ } else {
+ src.sin_family = AF_INET;
+ src.sin_addr.s_addr = htonl(INADDR_ANY);
+ }
src.sin_port = htons(srvarg.port);
if(bind(sock, (struct sockaddr *) &src, sizeof (src)) == -1) {
diff -ur freeciv-1.14.0-orig/server/srv_main.c freeciv-1.14.0/server/srv_main.c
--- freeciv-1.14.0-orig/server/srv_main.c Sat Oct 12 00:35:50 2002
+++ freeciv-1.14.0/server/srv_main.c Sun Nov 16 16:31:03 2003
@@ -164,6 +164,7 @@
srvarg.metaserver_port = DEFAULT_META_SERVER_PORT;
srvarg.port = DEFAULT_SOCK_PORT;
+ srvarg.bind_addr = NULL; /* INADDR_ANY */
srvarg.loglevel = LOG_NORMAL;
diff -ur freeciv-1.14.0-orig/server/srv_main.h freeciv-1.14.0/server/srv_main.h
--- freeciv-1.14.0-orig/server/srv_main.h Sat Oct 12 00:35:50 2002
+++ freeciv-1.14.0/server/srv_main.h Sun Nov 16 16:30:46 2003
@@ -27,6 +27,8 @@
unsigned short int metaserver_port;
/* this server's listen port */
int port;
+ /* address this server is to listen on (NULL => INADDR_ANY) */
+ char *bind_addr;
/* the log level */
int loglevel;
/* filenames */
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Freeciv-Dev] (PR#6887) Patch to allow server to listen,
Guest <=
|
|