diff options
Diffstat (limited to 'libvncserver')
-rw-r--r-- | libvncserver/cargs.c | 12 | ||||
-rwxr-xr-x | libvncserver/httpd.c | 3 | ||||
-rw-r--r-- | libvncserver/main.c | 2 | ||||
-rwxr-xr-x | libvncserver/sockets.c | 42 |
4 files changed, 47 insertions, 12 deletions
diff --git a/libvncserver/cargs.c b/libvncserver/cargs.c index 254f2ce..fbd3cc9 100644 --- a/libvncserver/cargs.c +++ b/libvncserver/cargs.c @@ -14,6 +14,8 @@ #include <rfb/rfb.h> +extern rfbStringToAddr(char *str, in_addr_t *iface); + void rfbUsage(void) { @@ -36,6 +38,8 @@ rfbUsage(void) fprintf(stderr, "-httpport portnum use portnum for http connection\n"); fprintf(stderr, "-enablehttpproxy enable http proxy support\n"); fprintf(stderr, "-progressive height enable progressive updating for slow links\n"); + fprintf(stderr, "-listen ipaddr listen for connections only on network interface with\n"); + fprintf(stderr, " addr ipaddr. '-listen localhost' and hostname work too.\n"); } /* purges COUNT arguments from ARGV at POSITION and decrements ARGC. @@ -125,6 +129,14 @@ rfbProcessArguments(rfbScreenInfoPtr rfbScreen,int* argc, char *argv[]) return FALSE; } rfbScreen->progressiveSliceHeight = atoi(argv[++i]); + } else if (strcmp(argv[i], "-listen") == 0) { /* -listen ipaddr */ + if (i + 1 >= *argc) { + rfbUsage(); + return FALSE; + } + if (! rfbStringToAddr(argv[++i], &(rfbScreen->listenInterface))) { + return FALSE; + } } else { i++; i1=i; diff --git a/libvncserver/httpd.c b/libvncserver/httpd.c index e169c30..b973bb6 100755 --- a/libvncserver/httpd.c +++ b/libvncserver/httpd.c @@ -102,7 +102,8 @@ rfbHttpInitSockets(rfbScreenInfoPtr rfbScreen) rfbLog(" URL http://%s:%d\n",rfbScreen->thisHost,rfbScreen->httpPort); - if ((rfbScreen->httpListenSock = rfbListenOnTCPPort(rfbScreen->httpPort)) < 0) { + if ((rfbScreen->httpListenSock = + rfbListenOnTCPPort(rfbScreen->httpPort, rfbScreen->listenInterface)) < 0) { rfbLogPerror("ListenOnTCPPort"); return; } diff --git a/libvncserver/main.c b/libvncserver/main.c index 0f68ee1..9447bf0 100644 --- a/libvncserver/main.c +++ b/libvncserver/main.c @@ -579,6 +579,8 @@ rfbScreenInfoPtr rfbGetScreen(int* argc,char** argv, /* disable progressive updating per default */ screen->progressiveSliceHeight = 0; + screen->listenInterface = htonl(INADDR_ANY); + if(!rfbProcessArguments(screen,argc,argv)) { free(screen); return 0; diff --git a/libvncserver/sockets.c b/libvncserver/sockets.c index 0937097..0aba2dc 100755 --- a/libvncserver/sockets.c +++ b/libvncserver/sockets.c @@ -102,6 +102,8 @@ int rfbMaxClientWait = 20000; /* time (ms) after which we decide client has void rfbInitSockets(rfbScreenInfoPtr rfbScreen) { + in_addr_t iface = rfbScreen->listenInterface; + if (rfbScreen->socketInitDone) return; @@ -132,9 +134,8 @@ rfbInitSockets(rfbScreenInfoPtr rfbScreen) if(rfbScreen->autoPort) { int i; rfbLog("Autoprobing TCP port \n"); - for (i = 5900; i < 6000; i++) { - if ((rfbScreen->listenSock = rfbListenOnTCPPort(i)) >= 0) { + if ((rfbScreen->listenSock = rfbListenOnTCPPort(i, iface)) >= 0) { rfbScreen->port = i; break; } @@ -153,7 +154,7 @@ rfbInitSockets(rfbScreenInfoPtr rfbScreen) else if(rfbScreen->port>0) { rfbLog("Listening for VNC connections on TCP port %d\n", rfbScreen->port); - if ((rfbScreen->listenSock = rfbListenOnTCPPort(rfbScreen->port)) < 0) { + if ((rfbScreen->listenSock = rfbListenOnTCPPort(rfbScreen->port, iface)) < 0) { rfbLogPerror("ListenOnTCPPort"); return; } @@ -166,7 +167,7 @@ rfbInitSockets(rfbScreenInfoPtr rfbScreen) if (rfbScreen->udpPort != 0) { rfbLog("rfbInitSockets: listening for input on UDP port %d\n",rfbScreen->udpPort); - if ((rfbScreen->udpSock = rfbListenOnUDPPort(rfbScreen->udpPort)) < 0) { + if ((rfbScreen->udpSock = rfbListenOnUDPPort(rfbScreen->udpPort, iface)) < 0) { rfbLogPerror("ListenOnUDPPort"); return; } @@ -527,9 +528,29 @@ rfbWriteExact(cl, buf, len) return 1; } +/* currently private, called by rfbProcessArguments() */ +int +rfbStringToAddr(char *str, in_addr_t *addr) { + if (str == NULL || *str == '\0' || strcmp(str, "any") == 0) { + *addr = htonl(INADDR_ANY); + } else if (strcmp(str, "localhost") == 0) { + *addr = htonl(INADDR_LOOPBACK); + } else { + struct hostent *hp; + if ((*addr = inet_addr(str)) == htonl(INADDR_NONE)) { + if (!(hp = gethostbyname(str))) { + return 0; + } + *addr = *(unsigned long *)hp->h_addr; + } + } + return 1; +} + int -rfbListenOnTCPPort(port) +rfbListenOnTCPPort(port, iface) int port; + in_addr_t iface; { struct sockaddr_in addr; int sock; @@ -538,8 +559,7 @@ rfbListenOnTCPPort(port) memset(&addr, 0, sizeof(addr)); addr.sin_family = AF_INET; addr.sin_port = htons(port); - /* addr.sin_addr.s_addr = interface.s_addr; */ - addr.sin_addr.s_addr = INADDR_ANY; + addr.sin_addr.s_addr = iface; if ((sock = socket(AF_INET, SOCK_STREAM, 0)) < 0) { return -1; @@ -574,7 +594,7 @@ rfbConnectToTcpAddr(host, port) addr.sin_family = AF_INET; addr.sin_port = htons(port); - if ((addr.sin_addr.s_addr = inet_addr(host)) == INADDR_NONE) + if ((addr.sin_addr.s_addr = inet_addr(host)) == htonl(INADDR_NONE)) { if (!(hp = gethostbyname(host))) { errno = EINVAL; @@ -596,8 +616,9 @@ rfbConnectToTcpAddr(host, port) } int -rfbListenOnUDPPort(port) +rfbListenOnUDPPort(port, iface) int port; + in_addr_t iface; { struct sockaddr_in addr; int sock; @@ -606,8 +627,7 @@ rfbListenOnUDPPort(port) memset(&addr, 0, sizeof(addr)); addr.sin_family = AF_INET; addr.sin_port = htons(port); - /* addr.sin_addr.s_addr = interface.s_addr; */ - addr.sin_addr.s_addr = INADDR_ANY; + addr.sin_addr.s_addr = iface; if ((sock = socket(AF_INET, SOCK_DGRAM, 0)) < 0) { return -1; |