diff options
Diffstat (limited to 'nxcomp/Loop.cpp')
-rw-r--r-- | nxcomp/Loop.cpp | 64 |
1 files changed, 41 insertions, 23 deletions
diff --git a/nxcomp/Loop.cpp b/nxcomp/Loop.cpp index 92b6fc28f..8069af598 100644 --- a/nxcomp/Loop.cpp +++ b/nxcomp/Loop.cpp @@ -952,6 +952,7 @@ static char listenHost[DEFAULT_STRING_LENGTH] = { 0 }; static char displayHost[DEFAULT_STRING_LENGTH] = { 0 }; static char authCookie[DEFAULT_STRING_LENGTH] = { 0 }; +static int loopbackBind = DEFAULT_LOOPBACK_BIND; static int proxyPort = DEFAULT_NX_PROXY_PORT; static int xPort = DEFAULT_NX_X_PORT; @@ -3959,7 +3960,14 @@ int SetupTcpSocket() tcpAddr.sin_family = AF_INET; tcpAddr.sin_port = htons(proxyPortTCP); - tcpAddr.sin_addr.s_addr = htonl(INADDR_ANY); + if ( loopbackBind ) + { + tcpAddr.sin_addr.s_addr = htonl(INADDR_LOOPBACK); + } + else + { + tcpAddr.sin_addr.s_addr = htonl(INADDR_ANY); + } if (bind(tcpFD, (sockaddr *) &tcpAddr, sizeof(tcpAddr)) == -1) { @@ -4512,7 +4520,14 @@ int ListenConnection(int port, const char *label) tcpAddr.sin_family = AF_INET; tcpAddr.sin_port = htons(portTCP); - tcpAddr.sin_addr.s_addr = htonl(INADDR_ANY); + if ( loopbackBind ) + { + tcpAddr.sin_addr.s_addr = htonl(INADDR_LOOPBACK); + } + else + { + tcpAddr.sin_addr.s_addr = htonl(INADDR_ANY); + } if (bind(newFD, (sockaddr *) &tcpAddr, sizeof(tcpAddr)) == -1) { @@ -5884,20 +5899,9 @@ void InstallSignal(int signal, int action) struct sigaction newAction; - newAction.sa_handler = HandleSignal; - - // - // This field doesn't exist on most OSes except - // Linux. We keep setting the field to NULL to - // avoid side-effects in the case the field is - // a value return. - // + memset(&newAction, 0, sizeof(newAction)); - #if defined(__linux__) - - newAction.sa_restorer = NULL; - - #endif + newAction.sa_handler = HandleSignal; sigemptyset(&(newAction.sa_mask)); @@ -6509,13 +6513,9 @@ void SetTimer(int value) struct sigaction action; - action.sa_handler = HandleTimer; - - #if defined(__linux__) - - action.sa_restorer = NULL; + memset(&action, 0, sizeof(action)); - #endif + action.sa_handler = HandleTimer; sigemptyset(&action.sa_mask); @@ -6695,7 +6695,14 @@ int WaitForRemote(int portNum) #ifdef __APPLE__ - tcpAddr.sin_addr.s_addr = htonl(INADDR_ANY); + if ( loopbackBind ) + { + tcpAddr.sin_addr.s_addr = htonl(INADDR_LOOPBACK); + } + else + { + tcpAddr.sin_addr.s_addr = htonl(INADDR_ANY); + } #else @@ -8374,6 +8381,10 @@ int ParseEnvironmentOptions(const char *env, int force) listenPort = ValidateArg("local", name, value); } + else if (strcasecmp(name, "loopback") == 0) + { + loopbackBind = ValidateArg("local", name, value); + } else if (strcasecmp(name, "accept") == 0) { if (*connectHost != '\0') @@ -13750,7 +13761,14 @@ int ParseListenOption(int &address) } else { - address = htonl(INADDR_ANY); + if ( loopbackBind ) + { + address = htonl(INADDR_LOOPBACK); + } + else + { + address = htonl(INADDR_ANY); + } } } else |