From 9e1001fac72be45fca76b36d7e9ebe35d0602bc2 Mon Sep 17 00:00:00 2001 From: Mark Vejvoda Date: Tue, 27 Mar 2012 05:39:02 +0000 Subject: [PATCH] - headless server will only give network status info to the locahost now and not on any other ip (for security purposes) --- source/glest_game/network/server_interface.cpp | 3 +++ source/shared_lib/include/platform/posix/socket.h | 3 +++ source/shared_lib/sources/platform/posix/socket.cpp | 8 +++++++- 3 files changed, 13 insertions(+), 1 deletion(-) diff --git a/source/glest_game/network/server_interface.cpp b/source/glest_game/network/server_interface.cpp index 3635a95b..d1c8a8cc 100644 --- a/source/glest_game/network/server_interface.cpp +++ b/source/glest_game/network/server_interface.cpp @@ -73,9 +73,12 @@ ServerInterface::ServerInterface(bool publishEnabled) :GameNetworkInterface() { lastGlobalLagCheckTime = 0; masterserverAdminRequestLaunch = false; + // This is an admin port listening only on the localhost intended to + // give current connection status info serverSocketAdmin = new ServerSocket(true); serverSocketAdmin->setBlock(false); serverSocketAdmin->setBindPort(Config::getInstance().getInt("ServerAdminPort", intToStr(GameConstants::serverAdminPort).c_str())); + serverSocketAdmin->setBindSpecificAddress("127.0.0.1"); serverSocketAdmin->listen(5); maxFrameCountLagAllowed = Config::getInstance().getInt("MaxFrameCountLagAllowed", intToStr(maxFrameCountLagAllowed).c_str()); diff --git a/source/shared_lib/include/platform/posix/socket.h b/source/shared_lib/include/platform/posix/socket.h index 54b1eba2..c730dee6 100644 --- a/source/shared_lib/include/platform/posix/socket.h +++ b/source/shared_lib/include/platform/posix/socket.h @@ -234,6 +234,7 @@ protected: bool portBound; int boundPort; + string bindSpecificAddress; static int externalPort; static int ftpServerPort; @@ -269,6 +270,8 @@ public: int getBindPort() const { return boundPort; } bool isPortBound() const { return portBound; } + void setBindSpecificAddress(string value) { bindSpecificAddress = value;} + static void setExternalPort(int port) { externalPort = port; } static int getExternalPort() { return externalPort; } diff --git a/source/shared_lib/sources/platform/posix/socket.cpp b/source/shared_lib/sources/platform/posix/socket.cpp index f3458af3..bd6120bb 100644 --- a/source/shared_lib/sources/platform/posix/socket.cpp +++ b/source/shared_lib/sources/platform/posix/socket.cpp @@ -2046,6 +2046,7 @@ ServerSocket::ServerSocket(bool basicMode) : Socket() { if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] basicMode = %d\n",__FILE__,__FUNCTION__,__LINE__,basicMode); this->basicMode = basicMode; + this->bindSpecificAddress = ""; //printf("SERVER SOCKET CONSTRUCTOR\n"); //MutexSafeWrapper safeMutexUPNP(&ServerSocket::mutexUpnpdiscoverThread,CODE_AT_LINE); //ServerSocket::upnpdiscoverThread = NULL; @@ -2178,7 +2179,12 @@ void ServerSocket::bind(int port) { //sockaddr structure sockaddr_in addr; addr.sin_family= AF_INET; - addr.sin_addr.s_addr= INADDR_ANY; + if(this->bindSpecificAddress != "") { + addr.sin_addr.s_addr= inet_addr(this->bindSpecificAddress.c_str()); + } + else { + addr.sin_addr.s_addr= INADDR_ANY; + } addr.sin_port= htons(port); int val = 1;