diff --git a/common/network/TcpSocket.cxx b/common/network/TcpSocket.cxx index 462b8a7baa..15730cfdce 100644 --- a/common/network/TcpSocket.cxx +++ b/common/network/TcpSocket.cxx @@ -496,10 +496,6 @@ void network::createTcpListeners(std::list *listeners, } } - if (new_listeners.empty ()) - throw SocketException("createTcpListeners: no addresses available", - EADDRNOTAVAIL); - listeners->splice (listeners->end(), new_listeners); } diff --git a/unix/x0vncserver/x0vncserver.cxx b/unix/x0vncserver/x0vncserver.cxx index b9fe058afa..f87eb61e4a 100644 --- a/unix/x0vncserver/x0vncserver.cxx +++ b/unix/x0vncserver/x0vncserver.cxx @@ -306,16 +306,22 @@ int main(int argc, char** argv) } if ((int)rfbport != -1) { + std::list tcp_listeners; const char *addr = interface; + if (strcasecmp(addr, "all") == 0) addr = 0; if (localhostOnly) - createLocalTcpListeners(&listeners, (int)rfbport); + createLocalTcpListeners(&tcp_listeners, (int)rfbport); else - createTcpListeners(&listeners, addr, (int)rfbport); - vlog.info("Listening for VNC connections on %s interface(s), port %d", - localhostOnly ? "local" : (const char*)interface, - (int)rfbport); + createTcpListeners(&tcp_listeners, addr, (int)rfbport); + + if (!tcp_listeners.empty()) { + listeners.splice (listeners.end(), tcp_listeners); + vlog.info("Listening for VNC connections on %s interface(s), port %d", + localhostOnly ? "local" : (const char*)interface, + (int)rfbport); + } FileTcpFilter fileTcpFilter(hostsFile); if (strlen(hostsFile) != 0) @@ -325,6 +331,11 @@ int main(int argc, char** argv) (*i)->setFilter(&fileTcpFilter); } + if (listeners.empty()) { + vlog.error("No path or port configured for incoming connections"); + return -1; + } + PollingScheduler sched((int)pollingCycle, (int)maxProcessorUsage); while (!caughtSignal) { diff --git a/unix/xserver/hw/vnc/vncExtInit.cc b/unix/xserver/hw/vnc/vncExtInit.cc index 0292a6d1b3..1dfe76d741 100644 --- a/unix/xserver/hw/vnc/vncExtInit.cc +++ b/unix/xserver/hw/vnc/vncExtInit.cc @@ -229,6 +229,7 @@ void vncExtensionInit(void) } if (!inetd && rfbport != -1) { + std::list tcp_listeners; const char *addr = interface; int port = rfbport; if (port == 0) port = 5900 + atoi(vncGetDisplay()); @@ -236,15 +237,21 @@ void vncExtensionInit(void) if (strcasecmp(addr, "all") == 0) addr = 0; if (localhostOnly) - network::createLocalTcpListeners(&listeners, port); + network::createLocalTcpListeners(&tcp_listeners, port); else - network::createTcpListeners(&listeners, addr, port); + network::createTcpListeners(&tcp_listeners, addr, port); - vlog.info("Listening for VNC connections on %s interface(s), port %d", - localhostOnly ? "local" : (const char*)interface, - port); + if (!tcp_listeners.empty()) { + listeners.splice (listeners.end(), tcp_listeners); + vlog.info("Listening for VNC connections on %s interface(s), port %d", + localhostOnly ? "local" : (const char*)interface, + port); + } } + if (!inetd && listeners.empty()) + throw rdr::Exception("No path or port configured for incoming connections"); + PixelFormat pf = vncGetPixelFormat(scr); vncSetGlueContext(scr); diff --git a/vncviewer/vncviewer.cxx b/vncviewer/vncviewer.cxx index 544a87bb33..06a8316d4f 100644 --- a/vncviewer/vncviewer.cxx +++ b/vncviewer/vncviewer.cxx @@ -756,6 +756,8 @@ int main(int argc, char** argv) port = atoi(vncServerName); createTcpListeners(&listeners, 0, port); + if (listeners.empty()) + throw Exception(_("Unable to listen for incoming connections")); vlog.info(_("Listening on port %d"), port);