Allow -vnc to restrict what interface to listen on
PATCH 1/1 Allow -vnc to restrict what interface to listen on
Howdy,
The attached patch changes the -vnc syntax from:
-vnc display
To:
-vnc [interface:]display
This allows a user to restrict the interface the VNC server listens on (for instance, to localhost). I factored out some of the code from the tcp: char device and fixed a minor bug that would mistakenly reject valid hostnames (for instance, 42.slashdot.org). If the interface portion of the option is not specified, the interface defaults to 0.0.0.0 (which is the old behavior).
Regards,
Anthony Liguori
# HG changeset patch
# User anthony@rhesus
# Date 1159924183 18000
# Node ID 3eebcca40df8431aab7411ab585a7302eaebc9c8
# Parent d12ee567e5b9f83821b3c28548a089af2aba2de7
Let the vnc option bind to a particular interface. Also cleanup the telnet options host parsing
qemu_socket.h +2 -0
@@ -27,4 +27,6 @@void socket_set_nonblock (int fd); +int parse_host (struct sockaddr_in *saddr,const char *str); +#endif /* QEMU_SOCKET_H */
vl.c +22 -20
81 lines not on this page · raw message
vl.h +1 -1
@@ -866,7 +866,7 @@ void cocoa_display_init(DisplayState *dsvoid cocoa_display_init (DisplayState *ds,int full_screen);/* vnc.c */ -void vnc_display_init (DisplayState *ds,int display); +void vnc_display_init (DisplayState *ds,const char *interface);/* ide.c */ #define MAX_DISKS 4
vnc.c +20 -2
@@ -1099,11 +1099,26 @@ static void vnc_listen_read(void *opaque } } -void vnc_display_init (DisplayState *ds,int display) +void vnc_display_init (DisplayState *ds,const char *vnc_interface) {struct sockaddr_in addr;int reuse_addr, ret;VncState *vs; +char host[512 ]; +char *ptr; +const char *bind_to ="0.0.0.0" ; +int display; + +snprintf (host,sizeof (host),"%s" , vnc_interface); + + ptr =strchr (host,':' ); +if (ptr) { + *ptr =0 ; + display =atoi (ptr +1 ); + bind_to = host; + }else + display =atoi (host); + vs =qemu_mallocz (sizeof (VncState));if (!vs)
@@ -1132,7 +1147,10 @@ void vnc_display_init(DisplayState *ds, addr.sin_family =AF_INET ; addr.sin_port =htons (5900 + display); -memset (&addr.sin_addr,0 ,sizeof (addr.sin_addr)); +if (parse_host (&addr, bind_to) ==-1 ) { +fprintf (stderr,"Invalid host `%s'\n" , bind_to); +exit (1 ); + } reuse_addr =1 ; ret = setsockopt(vs->lsock, SOL_SOCKET, SO_REUSEADDR,