to listen on specific interface. git-svn-id: svn://svn.code.sf.net/p/tigervnc/code/trunk@3963 3789f03b-4d11-0410-bbf8-ca57d06f2519tags/v1.0.90
@@ -331,8 +331,8 @@ int TcpSocket::getSockPort(int sock) | |||
} | |||
TcpListener::TcpListener(int port, bool localhostOnly, int sock, bool close_) | |||
: closeFd(close_) | |||
TcpListener::TcpListener(const char *listenaddr, int port, bool localhostOnly, | |||
int sock, bool close_) : closeFd(close_) | |||
{ | |||
if (sock != -1) { | |||
fd = sock; | |||
@@ -360,11 +360,24 @@ TcpListener::TcpListener(int port, bool localhostOnly, int sock, bool close_) | |||
struct sockaddr_in addr; | |||
memset(&addr, 0, sizeof(addr)); | |||
addr.sin_family = AF_INET; | |||
addr.sin_port = htons(port); | |||
if (localhostOnly) | |||
if (localhostOnly) { | |||
addr.sin_addr.s_addr = htonl(INADDR_LOOPBACK); | |||
else | |||
addr.sin_addr.s_addr = htonl(INADDR_ANY); | |||
} else if (listenaddr != NULL) { | |||
#ifndef WIN32 | |||
if (inet_aton(listenaddr, &addr.sin_addr) == 0) | |||
#else | |||
/* Windows doesn't have inet_aton, sigh */ | |||
if ((addr.sin_addr.s_addr = inet_addr(listenaddr)) == INADDR_NONE) | |||
#endif | |||
{ | |||
closesocket(fd); | |||
throw Exception("invalid network interface address: %s", listenaddr); | |||
} | |||
} else | |||
addr.sin_addr.s_addr = htonl(INADDR_ANY); /* Bind to 0.0.0.0 by default. */ | |||
addr.sin_port = htons(port); | |||
if (bind(fd, (struct sockaddr *)&addr, sizeof(addr)) < 0) { | |||
int e = errorNumber; | |||
closesocket(fd); |
@@ -65,8 +65,8 @@ namespace network { | |||
class TcpListener : public SocketListener { | |||
public: | |||
TcpListener(int port, bool localhostOnly=false, int sock=-1, | |||
bool close=true); | |||
TcpListener(const char *listenaddr, int port, bool localhostOnly=false, | |||
int sock=-1, bool close=true); | |||
virtual ~TcpListener(); | |||
virtual void shutdown(); |
@@ -370,7 +370,7 @@ int main(int argc, char** argv) | |||
if (vncServerName && isdigit(vncServerName[0])) | |||
port = atoi(vncServerName); | |||
TcpListener listener(port); | |||
TcpListener listener(NULL, port); | |||
vlog.info("Listening on port %d\n",port); | |||
@@ -447,7 +447,7 @@ int main(int argc, char** argv) | |||
QueryConnHandler qcHandler(dpy, &server); | |||
server.setQueryConnectionHandler(&qcHandler); | |||
TcpListener listener((int)rfbport); | |||
TcpListener listener(NULL, (int)rfbport); | |||
vlog.info("Listening on port %d", (int)rfbport); | |||
const char *hostsData = hostsFile.getData(); |
@@ -47,6 +47,10 @@ depth 8 is BGR233 (meaning the most significant two bits represent blue, the | |||
next three green, and the least significant three represent red), the default | |||
for depth 16 is RGB565 and for depth 24 is RGB888. | |||
.TP | |||
.B \-interface \fIIP address\fP or \-i \fIIP address\fP | |||
Listen on interface. By default Xvnc listens on all available interfaces. | |||
.TP | |||
.B \-cc 3 | |||
As an alternative to the default TrueColor visual, this allows you to run an |
@@ -72,6 +72,7 @@ extern "C" { | |||
pointer args); | |||
extern char *display; | |||
extern char *listenaddr; | |||
} | |||
using namespace rfb; | |||
@@ -223,22 +224,24 @@ void vncExtensionInit() | |||
if (network::TcpSocket::isSocket(vncInetdSock) && | |||
!network::TcpSocket::isConnected(vncInetdSock)) | |||
{ | |||
listener = new network::TcpListener(0, 0, vncInetdSock, true); | |||
listener = new network::TcpListener(NULL, 0, 0, vncInetdSock, true); | |||
vlog.info("inetd wait"); | |||
} | |||
} else { | |||
int port = rfbport; | |||
if (port == 0) port = 5900 + atoi(display); | |||
port += 1000 * scr; | |||
listener = new network::TcpListener(port, localhostOnly); | |||
vlog.info("Listening for VNC connections on port %d",port); | |||
listener = new network::TcpListener(listenaddr, port, localhostOnly); | |||
vlog.info("Listening for VNC connections on %s interface(s), port %d", | |||
listenaddr == NULL ? "all" : listenaddr, port); | |||
CharArray httpDirStr(httpDir.getData()); | |||
if (httpDirStr.buf[0]) { | |||
port = httpPort; | |||
if (port == 0) port = 5800 + atoi(display); | |||
port += 1000 * scr; | |||
httpListener = new network::TcpListener(port, localhostOnly); | |||
vlog.info("Listening for HTTP connections on port %d",port); | |||
httpListener = new network::TcpListener(listenaddr, port, localhostOnly); | |||
vlog.info("Listening for HTTP connections on %s interface(s), port %d", | |||
listenaddr == NULL ? "all" : listenaddr, port); | |||
} | |||
} | |||
@@ -164,6 +164,8 @@ static bool displaySpecified = false; | |||
static bool wellKnownSocketsCreated = false; | |||
static char displayNumStr[16]; | |||
char *listenaddr = NULL; | |||
static void | |||
vfbInitializePixmapDepths(void) | |||
@@ -284,6 +286,7 @@ ddxUseMsg() | |||
ErrorF("-depth D set screen 0's depth\n"); | |||
ErrorF("-pixelformat fmt set pixel format (rgbNNN or bgrNNN)\n"); | |||
ErrorF("-inetd has been launched from inetd\n"); | |||
ErrorF("-interface IP_address listen on specified interface\n"); | |||
ErrorF("\nVNC parameters:\n"); | |||
fprintf(stderr,"\n" | |||
@@ -306,7 +309,7 @@ static | |||
bool displayNumFree(int num) | |||
{ | |||
try { | |||
network::TcpListener l(6000+num); | |||
network::TcpListener l(NULL, 6000+num); | |||
} catch (rdr::Exception& e) { | |||
return false; | |||
} | |||
@@ -544,6 +547,23 @@ ddxProcessArgument(int argc, char *argv[], int i) | |||
return 1; | |||
} | |||
if (strcmp(argv[i], "-interface") == 0 || | |||
strcmp(argv[i], "-i") == 0) { | |||
if (++i >= argc) { | |||
UseMsg(); | |||
return 2; | |||
} | |||
if (listenaddr != NULL) /* Only first -interface is valid */ | |||
return 2; | |||
listenaddr = strdup(argv[i]); | |||
if (listenaddr == NULL) | |||
FatalError("Not enough memory"); | |||
return 2; | |||
} | |||
if (rfb::Configuration::setParam(argv[i])) | |||
return 1; |
@@ -239,7 +239,7 @@ int WINAPI WinMain(HINSTANCE inst, HINSTANCE prevInst, char* cmdLine, int cmdSho | |||
ListenTrayIcon tray; | |||
// Listen for reverse connections | |||
network::TcpListener sock(port); | |||
network::TcpListener sock(NULL, port); | |||
ListenServer listener(&sock); | |||
// Run the view manager |
@@ -77,7 +77,7 @@ void ManagedListener::refresh() { | |||
return; | |||
try { | |||
if (port) | |||
sock = new network::TcpListener(port, localOnly); | |||
sock = new network::TcpListener(NULL, port, localOnly); | |||
} catch (rdr::Exception& e) { | |||
vlog.error(e.str()); | |||
} |