tBindAddress configuration variable added, to allow the server to bind to non-default addresses (e.g. "localhost") - vaccinewars - be a doctor and try to vaccinate the world
(HTM) git clone git://src.adamsgaard.dk/vaccinewars
(DIR) Log
(DIR) Files
(DIR) Refs
(DIR) README
(DIR) LICENSE
---
(DIR) commit 2aa4bafdef44d5998a737aaf213a4ec4db2c7d2e
(DIR) parent 96cf0691f76b33e00cb3e37aa267333b70212d99
(HTM) Author: Ben Webb <ben@salilab.org>
Date: Tue, 16 Jul 2002 12:02:43 +0000
BindAddress configuration variable added, to allow the server to bind to
non-default addresses (e.g. "localhost")
Diffstat:
M ChangeLog | 2 ++
M doc/configfile.html | 14 ++++++++++++--
M src/dopewars.c | 7 ++++++-
M src/dopewars.h | 2 +-
M src/network.c | 16 +++++++++++++---
M src/network.h | 3 ++-
M src/serverside.c | 2 +-
7 files changed, 37 insertions(+), 9 deletions(-)
---
(DIR) diff --git a/ChangeLog b/ChangeLog
t@@ -1,5 +1,7 @@
cvs
- Options dialog now allows sounds for all supported game events to be set
+ - BindAddress config variable added, to allow the server to be bound to
+ a non-default IP address
1.5.7 25-06-2002
- Sound support; Windows multimedia, ESD and SDL outputs are supported;
(DIR) diff --git a/doc/configfile.html b/doc/configfile.html
t@@ -89,7 +89,10 @@ list the servers available at the metaserver, prompt the user to enter a
server name and port, or play in single player mode, respectively.
This option can be overridden with the -o <a href="commandline.html#server">
command line option</a> (but be sure to protect the brackets from the shell
-if you use one of the "special" names).</dd>
+if you use one of the "special" names). <b>Note</b> that this only changes
+the name of the server that the client connects to - if you're running your
+own server it does not change the address that it binds to. For that, see
+the <b>BindAddress</b> variable.</dd>
<dt><b>ServerMOTD=<i>"Welcome to my dopewars server"</i></b></dt>
<dd>When running a server, any client that connects displays the welcome
t@@ -97,6 +100,13 @@ if you use one of the "special" names).</dd>
be used, for example, to inform users of any special features that the
server has.</dd>
+<dt><b>BindAddress=<i>"localhost"</i></b></dt>
+<dd>Forces your dopewars server (if you run one) to accept network connections
+only on the <i>localhost</i> network interface. (This can be a host name,
+or an IP address.) If this is left blank (the default) then the server will
+accept connections coming in on any valid network interface.
+</dd>
+
<dt><b>Socks.Active=<i>FALSE</i></b></dt>
<dd>Instructs the dopewars client to connect directly to the given server,
without using an intermediate SOCKS server. If this is set to TRUE, all
t@@ -635,7 +645,7 @@ can be configured in the same way are: <b>FightMiss</b>, <b>FightReload</b>,
<li><a href="index.html">Main index</a></li>
</ul>
<p>
- Last update: <b>15-07-2002</b><br />
+ Last update: <b>16-07-2002</b><br />
Valid <a href="http://validator.w3.org/check/referer">XHTML 1.1</a>
</p>
</body>
(DIR) diff --git a/src/dopewars.c b/src/dopewars.c
t@@ -79,7 +79,7 @@ gboolean Network, Client, Server, NotifyMetaServer, AIPlayer;
unsigned Port = 7902;
gboolean Sanitized, ConfigVerbose, DrugValue;
gchar *HiScoreFile = NULL, *ServerName = NULL, *ConvertFile = NULL;
-gchar *ServerMOTD = NULL, *WantedPlugin = NULL;
+gchar *ServerMOTD = NULL, *WantedPlugin = NULL, *BindAddress = NULL;
gboolean WantHelp, WantVersion, WantAntique, WantColour, WantNetwork;
gboolean WantConvert, WantAdmin;
t@@ -235,6 +235,9 @@ struct GLOBALS Globals[] = {
{NULL, NULL, NULL, &ServerMOTD, NULL, "ServerMOTD",
N_("Server's welcome message of the day"), NULL, NULL, 0, "", NULL,
NULL, FALSE, 0},
+ {NULL, NULL, NULL, &BindAddress, NULL, "BindAddress",
+ N_("Network address for the server to listen on"), NULL, NULL, 0, "",
+ NULL, NULL, FALSE, 0},
#ifdef NETWORKING
{NULL, &UseSocks, NULL, NULL, NULL, "Socks.Active",
N_("TRUE if a SOCKS server should be used for networking"),
t@@ -2304,8 +2307,10 @@ void SetupParameters(void)
/* Set hard-coded default values */
g_free(ServerName);
g_free(ServerMOTD);
+ g_free(BindAddress);
ServerName = g_strdup("localhost");
ServerMOTD = g_strdup("");
+ BindAddress = g_strdup("");
g_free(WebBrowser);
WebBrowser = g_strdup("/usr/bin/mozilla");
(DIR) diff --git a/src/dopewars.h b/src/dopewars.h
t@@ -168,7 +168,7 @@ extern gboolean Sanitized, ConfigVerbose, DrugValue;
extern int NumLocation, NumGun, NumCop, NumDrug, NumSubway, NumPlaying,
NumStoppedTo;
extern gchar *HiScoreFile, *ServerName, *ConvertFile, *ServerMOTD,
- *WantedPlugin;
+ *WantedPlugin, *BindAddress;
extern gboolean WantHelp, WantVersion, WantAntique, WantColour,
WantNetwork, WantConvert, WantAdmin;
#ifdef CYGWIN
(DIR) diff --git a/src/network.c b/src/network.c
t@@ -968,7 +968,7 @@ void QueueMessageForSend(NetworkBuffer *NetBuf, gchar *data)
CommitWriteBuffer(NetBuf, conn, addpt, addlen);
}
-static struct hostent *LookupHostname(gchar *host, LastError **error)
+static struct hostent *LookupHostname(const gchar *host, LastError **error)
{
struct hostent *he;
t@@ -1518,14 +1518,24 @@ int CreateTCPSocket(LastError **error)
return fd;
}
-gboolean BindTCPSocket(int sock, unsigned port, LastError **error)
+gboolean BindTCPSocket(int sock, const gchar *addr, unsigned port,
+ LastError **error)
{
struct sockaddr_in bindaddr;
int retval;
+ struct hostent *he;
bindaddr.sin_family = AF_INET;
bindaddr.sin_port = htons(port);
- bindaddr.sin_addr.s_addr = INADDR_ANY;
+ if (addr && addr[0]) {
+ he = LookupHostname(addr, error);
+ if (!he) {
+ return FALSE;
+ }
+ bindaddr.sin_addr = *((struct in_addr *)he->h_addr);
+ } else {
+ bindaddr.sin_addr.s_addr = INADDR_ANY;
+ }
memset(bindaddr.sin_zero, 0, sizeof(bindaddr.sin_zero));
retval =
(DIR) diff --git a/src/network.h b/src/network.h
t@@ -226,7 +226,8 @@ gboolean HandleHttpCompletion(HttpConnection *conn);
gboolean IsHttpError(HttpConnection *conn);
int CreateTCPSocket(LastError **error);
-gboolean BindTCPSocket(int sock, unsigned port, LastError **error);
+gboolean BindTCPSocket(int sock, const gchar *addr, unsigned port,
+ LastError **error);
void StartNetworking(void);
void StopNetworking(void);
(DIR) diff --git a/src/serverside.c b/src/serverside.c
t@@ -859,7 +859,7 @@ static gboolean StartServer(void)
SetBlocking(ListenSock, FALSE);
- if (!BindTCPSocket(ListenSock, Port, &sockerr)) {
+ if (!BindTCPSocket(ListenSock, BindAddress, Port, &sockerr)) {
errstr = g_string_new("");
g_string_assign_error(errstr, sockerr);
g_log(NULL, G_LOG_LEVEL_CRITICAL,