tHave a server that is bound to a non-default IP (via. BindAddress) also bind c… | |
git clone git://src.adamsgaard.dk/vaccinewars | |
Log | |
Files | |
Refs | |
README | |
LICENSE | |
--- | |
commit 9918e1db7bd81607c915ab626ff744b39dff40d8 | |
parent da267b014539dfa6bf4c6862dc3a2bc4f9108fd9 | |
Author: Ben Webb <[email protected]> | |
Date: Tue, 30 Jul 2002 19:40:02 +0000 | |
Have a server that is bound to a non-default IP (via. BindAddress) also | |
bind client sockets to that same IP when talking to the metaserver, so | |
tthat the latter gets the originating IP correct. | |
Diffstat: | |
M src/AIPlayer.c | 2 +- | |
M src/curses_client/curses_client.c | 2 +- | |
M src/gui_client/newgamedia.c | 2 +- | |
M src/message.c | 1 + | |
M src/network.c | 24 ++++++++++++++++-------- | |
M src/network.h | 8 +++++--- | |
M src/serverside.c | 1 + | |
7 files changed, 26 insertions(+), 14 deletions(-) | |
--- | |
diff --git a/src/AIPlayer.c b/src/AIPlayer.c | |
t@@ -157,7 +157,7 @@ void AIPlayerLoop() | |
oldstatus = netbuf->status; | |
oldsocks = netbuf->sockstat; | |
- if (!StartNetworkBufferConnect(netbuf, ServerName, Port)) { | |
+ if (!StartNetworkBufferConnect(netbuf, NULL, ServerName, Port)) { | |
AIConnectFailed(netbuf); | |
return; | |
} else { | |
diff --git a/src/curses_client/curses_client.c b/src/curses_client/curses_clien… | |
t@@ -518,7 +518,7 @@ static gboolean DoConnect(Player *Play, GString *errstr) | |
oldstatus = netbuf->status; | |
oldsocks = netbuf->sockstat; | |
- if (!StartNetworkBufferConnect(netbuf, ServerName, Port)) { | |
+ if (!StartNetworkBufferConnect(netbuf, NULL, ServerName, Port)) { | |
doneOK = FALSE; | |
} else { | |
SetNetworkBufferUserPasswdFunc(netbuf, SocksAuthFunc, NULL); | |
diff --git a/src/gui_client/newgamedia.c b/src/gui_client/newgamedia.c | |
t@@ -154,7 +154,7 @@ static void DoConnect(void) | |
oldstatus = NetBuf->status; | |
oldsocks = NetBuf->sockstat; | |
- if (StartNetworkBufferConnect(NetBuf, ServerName, Port)) { | |
+ if (StartNetworkBufferConnect(NetBuf, NULL, ServerName, Port)) { | |
DisplayConnectStatus(FALSE, oldstatus, oldsocks); | |
SetNetworkBufferUserPasswdFunc(NetBuf, SocksAuthDialog, NULL); | |
SetNetworkBufferCallBack(NetBuf, stgam.sockstat, NULL); | |
diff --git a/src/message.c b/src/message.c | |
t@@ -413,6 +413,7 @@ gboolean OpenMetaHttpConnection(HttpConnection **conn) | |
MetaServer.Path, METAVERSION); | |
retval = OpenHttpConnection(conn, MetaServer.Name, MetaServer.Port, | |
MetaServer.ProxyName, MetaServer.ProxyPort, | |
+ "", | |
UseSocks | |
&& MetaServer.UseSocks ? &Socks : NULL, | |
"GET", query, NULL, NULL); | |
diff --git a/src/network.c b/src/network.c | |
t@@ -70,7 +70,7 @@ typedef enum { | |
static gboolean StartSocksNegotiation(NetworkBuffer *NetBuf, | |
gchar *RemoteHost, | |
unsigned RemotePort); | |
-static gboolean StartConnect(int *fd, gchar *RemoteHost, | |
+static gboolean StartConnect(int *fd, const gchar *bindaddr, gchar *RemoteHost, | |
unsigned RemotePort, gboolean *doneOK, | |
LastError **error); | |
t@@ -260,6 +260,7 @@ gboolean IsNetworkBufferActive(NetworkBuffer *NetBuf) | |
} | |
gboolean StartNetworkBufferConnect(NetworkBuffer *NetBuf, | |
+ const gchar *bindaddr, | |
gchar *RemoteHost, unsigned RemotePort) | |
{ | |
gchar *realhost; | |
t@@ -276,7 +277,7 @@ gboolean StartNetworkBufferConnect(NetworkBuffer *NetBuf, | |
realport = RemotePort; | |
} | |
- if (StartConnect(&NetBuf->fd, realhost, realport, &doneOK, | |
+ if (StartConnect(&NetBuf->fd, bindaddr, realhost, realport, &doneOK, | |
&NetBuf->error)) { | |
/* If we connected immediately, then set status, otherwise signal that | |
* we're waiting for the connect to complete */ | |
t@@ -1203,7 +1204,8 @@ static gboolean StartHttpConnect(HttpConnection *conn) | |
ConnectPort = conn->Port; | |
} | |
- if (!StartNetworkBufferConnect(&conn->NetBuf, ConnectHost, ConnectPort)) { | |
+ if (!StartNetworkBufferConnect(&conn->NetBuf, conn->bindaddr, ConnectHost, | |
+ ConnectPort)) { | |
return FALSE; | |
} | |
return TRUE; | |
t@@ -1211,9 +1213,9 @@ static gboolean StartHttpConnect(HttpConnection *conn) | |
gboolean OpenHttpConnection(HttpConnection **connpt, gchar *HostName, | |
unsigned Port, gchar *Proxy, | |
- unsigned ProxyPort, SocksServer *socks, | |
- gchar *Method, gchar *Query, gchar *Headers, | |
- gchar *Body) | |
+ unsigned ProxyPort, const gchar *bindaddr, | |
+ SocksServer *socks, gchar *Method, | |
+ gchar *Query, gchar *Headers, gchar *Body) | |
{ | |
HttpConnection *conn; | |
t@@ -1225,6 +1227,7 @@ gboolean OpenHttpConnection(HttpConnection **connpt, gch… | |
conn->HostName = g_strdup(HostName); | |
if (Proxy && Proxy[0]) | |
conn->Proxy = g_strdup(Proxy); | |
+ conn->bindaddr = g_strdup(bindaddr); | |
conn->Method = g_strdup(Method); | |
conn->Query = g_strdup(Query); | |
if (Headers && Headers[0]) | |
t@@ -1248,6 +1251,7 @@ void CloseHttpConnection(HttpConnection *conn) | |
ShutdownNetworkBuffer(&conn->NetBuf); | |
g_free(conn->HostName); | |
g_free(conn->Proxy); | |
+ g_free(conn->bindaddr); | |
g_free(conn->Method); | |
g_free(conn->Query); | |
g_free(conn->Headers); | |
t@@ -1546,8 +1550,8 @@ gboolean BindTCPSocket(int sock, const gchar *addr, unsi… | |
return (retval != SOCKET_ERROR); | |
} | |
-gboolean StartConnect(int *fd, gchar *RemoteHost, unsigned RemotePort, | |
- gboolean *doneOK, LastError **error) | |
+gboolean StartConnect(int *fd, const gchar *bindaddr, gchar *RemoteHost, | |
+ unsigned RemotePort, gboolean *doneOK, LastError **error) | |
{ | |
struct sockaddr_in ClientAddr; | |
struct hostent *he; | |
t@@ -1562,6 +1566,10 @@ gboolean StartConnect(int *fd, gchar *RemoteHost, unsig… | |
if (*fd == SOCKET_ERROR) | |
return FALSE; | |
+ if (bindaddr && bindaddr[0] && !BindTCPSocket(*fd, bindaddr, 0, error)) { | |
+ return FALSE; | |
+ } | |
+ | |
ClientAddr.sin_family = AF_INET; | |
ClientAddr.sin_port = htons(RemotePort); | |
ClientAddr.sin_addr = *((struct in_addr *)he->h_addr); | |
diff --git a/src/network.h b/src/network.h | |
t@@ -154,6 +154,7 @@ struct _HttpConnection { | |
gchar *Proxy; /* If non-NULL, a web proxy to use */ | |
unsigned ProxyPort; /* The port to use for talking to | |
* the proxy */ | |
+ char *bindaddr; /* local IP address to bind to */ | |
gchar *Method; /* e.g. GET, POST */ | |
gchar *Query; /* e.g. the path of the desired webpage */ | |
gchar *Headers; /* if non-NULL, e.g. Content-Type */ | |
t@@ -188,6 +189,7 @@ void SetNetworkBufferUserPasswdFunc(NetworkBuffer *NetBuf, | |
gboolean IsNetworkBufferActive(NetworkBuffer *NetBuf); | |
void BindNetworkBufferToSocket(NetworkBuffer *NetBuf, int fd); | |
gboolean StartNetworkBufferConnect(NetworkBuffer *NetBuf, | |
+ const gchar *bindaddr, | |
gchar *RemoteHost, unsigned RemotePort); | |
void ShutdownNetworkBuffer(NetworkBuffer *NetBuf); | |
void SetSelectForNetworkBuffer(NetworkBuffer *NetBuf, fd_set *readfds, | |
t@@ -213,9 +215,9 @@ void CommitWriteBuffer(NetworkBuffer *NetBuf, ConnBuf *con… | |
gboolean OpenHttpConnection(HttpConnection **conn, gchar *HostName, | |
unsigned Port, gchar *Proxy, | |
- unsigned ProxyPort, SocksServer *socks, | |
- gchar *Method, gchar *Query, gchar *Headers, | |
- gchar *Body); | |
+ unsigned ProxyPort, const gchar *bindaddr, | |
+ SocksServer *socks, gchar *Method, | |
+ gchar *Query, gchar *Headers, gchar *Body); | |
void CloseHttpConnection(HttpConnection *conn); | |
gchar *ReadHttpResponse(HttpConnection *conn, gboolean *doneOK); | |
void SetHttpAuthentication(HttpConnection *conn, gboolean proxy, | |
diff --git a/src/serverside.c b/src/serverside.c | |
t@@ -289,6 +289,7 @@ void RegisterWithMetaServer(gboolean Up, gboolean SendData, | |
retval = OpenHttpConnection(&MetaConn, MetaServer.Name, MetaServer.Port, | |
MetaServer.ProxyName, MetaServer.ProxyPort, | |
+ BindAddress, | |
UseSocks && MetaServer.UseSocks ? &Socks : NULL, | |
"POST", MetaServer.Path, headers->str, | |
body->str); |