From: Anthony Liguori <aliguori@cs.utexas.edu>
To: qemu-devel@nongnu.org
Subject: [Qemu-devel] [PATCH] Allow -vnc to restrict what interface to listen on
Date: Tue, 03 Oct 2006 20:16:01 -0500 [thread overview]
Message-ID: <45230B51.1070905@cs.utexas.edu> (raw)
[-- Attachment #1: Type: text/plain, Size: 520 bytes --]
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
[-- Attachment #2: vnc-listen.diff --]
[-- Type: text/x-patch, Size: 4803 bytes --]
# 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
diff -r d12ee567e5b9 -r 3eebcca40df8 qemu_socket.h
--- a/qemu_socket.h Sat Sep 30 01:01:17 2006 +0000
+++ b/qemu_socket.h Tue Oct 03 20:09:43 2006 -0500
@@ -27,4 +27,6 @@
void socket_set_nonblock(int fd);
+int parse_host(struct sockaddr_in *saddr, const char *str);
+
#endif /* QEMU_SOCKET_H */
diff -r d12ee567e5b9 -r 3eebcca40df8 vl.c
--- a/vl.c Sat Sep 30 01:01:17 2006 +0000
+++ b/vl.c Tue Oct 03 20:09:43 2006 -0500
@@ -151,7 +151,7 @@ int usb_enabled = 0;
int usb_enabled = 0;
static VLANState *first_vlan;
int smp_cpus = 1;
-int vnc_display = -1;
+const char *vnc_interface = NULL;
#if defined(TARGET_SPARC)
#define MAX_CPUS 16
#elif defined(TARGET_I386)
@@ -2706,10 +2706,23 @@ fail:
return -1;
}
+int parse_host(struct sockaddr_in *saddr, const char *str)
+{
+ struct hostent *pent;
+
+ pent = gethostbyname(str);
+ if (pent == NULL) {
+ if (!inet_aton(str, &saddr->sin_addr))
+ return -1;
+ } else
+ memcpy(&saddr->sin_addr, pent->h_addr, 4);
+
+ return 0;
+}
+
int parse_host_port(struct sockaddr_in *saddr, const char *str)
{
char buf[512];
- struct hostent *he;
const char *p, *r;
int port;
@@ -2719,16 +2732,9 @@ int parse_host_port(struct sockaddr_in *
saddr->sin_family = AF_INET;
if (buf[0] == '\0') {
saddr->sin_addr.s_addr = 0;
- } else {
- if (isdigit(buf[0])) {
- if (!inet_aton(buf, &saddr->sin_addr))
- return -1;
- } else {
- if ((he = gethostbyname(buf)) == NULL)
- return - 1;
- saddr->sin_addr = *(struct in_addr *)he->h_addr;
- }
- }
+ } else if (parse_host(saddr, buf) == -1)
+ return -1;
+
port = strtol(p, (char **)&r, 0);
if (r == p)
return -1;
@@ -5926,7 +5932,7 @@ void help(void)
"-no-acpi disable ACPI\n"
#endif
"-loadvm file start right away with a saved state (loadvm in monitor)\n"
- "-vnc display start a VNC server on display\n"
+ "-vnc addr start a VNC server on addr ([interface:]display)\n"
"\n"
"During emulation, the following keys are useful:\n"
"ctrl-alt-f toggle full screen\n"
@@ -6716,11 +6722,7 @@ int main(int argc, char **argv)
}
break;
case QEMU_OPTION_vnc:
- vnc_display = atoi(optarg);
- if (vnc_display < 0) {
- fprintf(stderr, "Invalid VNC display\n");
- exit(1);
- }
+ vnc_interface = optarg;
break;
case QEMU_OPTION_no_acpi:
acpi_enabled = 0;
@@ -6841,8 +6843,8 @@ int main(int argc, char **argv)
/* terminal init */
if (nographic) {
dumb_display_init(ds);
- } else if (vnc_display != -1) {
- vnc_display_init(ds, vnc_display);
+ } else if (vnc_interface != NULL) {
+ vnc_display_init(ds, vnc_interface);
} else {
#if defined(CONFIG_SDL)
sdl_display_init(ds, full_screen);
diff -r d12ee567e5b9 -r 3eebcca40df8 vl.h
--- a/vl.h Sat Sep 30 01:01:17 2006 +0000
+++ b/vl.h Tue Oct 03 20:09:43 2006 -0500
@@ -866,7 +866,7 @@ void cocoa_display_init(DisplayState *ds
void 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
diff -r d12ee567e5b9 -r 3eebcca40df8 vnc.c
--- a/vnc.c Sat Sep 30 01:01:17 2006 +0000
+++ b/vnc.c Tue Oct 03 20:09:43 2006 -0500
@@ -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,
reply other threads:[~2006-10-04 1:16 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=45230B51.1070905@cs.utexas.edu \
--to=aliguori@cs.utexas.edu \
--cc=qemu-devel@nongnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).