From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1LOXn5-00066T-TF for qemu-devel@nongnu.org; Sun, 18 Jan 2009 08:34:15 -0500 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1LOXn4-00061y-41 for qemu-devel@nongnu.org; Sun, 18 Jan 2009 08:34:15 -0500 Received: from [199.232.76.173] (port=53726 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1LOXn3-00061o-VI for qemu-devel@nongnu.org; Sun, 18 Jan 2009 08:34:14 -0500 Received: from mx2.redhat.com ([66.187.237.31]:52075) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1LOXn3-0004Tq-Gd for qemu-devel@nongnu.org; Sun, 18 Jan 2009 08:34:13 -0500 Received: from int-mx2.corp.redhat.com (int-mx2.corp.redhat.com [172.16.27.26]) by mx2.redhat.com (8.13.8/8.13.8) with ESMTP id n0IDYCso000934 for ; Sun, 18 Jan 2009 08:34:12 -0500 Received: from ns3.rdu.redhat.com (ns3.rdu.redhat.com [10.11.255.199]) by int-mx2.corp.redhat.com (8.13.1/8.13.1) with ESMTP id n0IDYCqY008337 for ; Sun, 18 Jan 2009 08:34:13 -0500 Received: from dhcp-1-237.tlv.redhat.com (dhcp-1-237.tlv.redhat.com [10.35.1.237]) by ns3.rdu.redhat.com (8.13.8/8.13.8) with ESMTP id n0IDYCie019518 for ; Sun, 18 Jan 2009 08:34:12 -0500 Date: Sun, 18 Jan 2009 15:32:31 +0200 From: Gleb Natapov Message-ID: <20090118133231.GA19268@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Subject: [Qemu-devel] [PATCH] specify vmchannel as a net option Reply-To: qemu-devel@nongnu.org List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Another version. Try to maintain balance between command line ugliness and parsing ugliness. To configure vmchannel use: -net channel,666:unix:/tmp/666,server,nowait Signed-off-by: Gleb Natapov diff --git a/net.c b/net.c index 86ee7d5..35728dd 100644 --- a/net.c +++ b/net.c @@ -644,6 +644,23 @@ void do_info_slirp(void) slirp_stats(); } +struct VMChannel { + CharDriverState *hd; + int port; +} *vmchannels; + +static int vmchannel_can_read(void *opaque) +{ + struct VMChannel *vmc = (struct VMChannel*)opaque; + return slirp_socket_can_recv(4, vmc->port); +} + +static void vmchannel_read(void *opaque, const uint8_t *buf, int size) +{ + struct VMChannel *vmc = (struct VMChannel*)opaque; + slirp_socket_recv(4, vmc->port, buf, size); +} + #endif /* CONFIG_SLIRP */ #if !defined(_WIN32) @@ -1604,6 +1621,30 @@ int net_client_init(const char *device, const char *p) } vlan->nb_host_devs++; ret = net_slirp_init(vlan, device, name); + } else if (!strcmp(device, "channel")) { + long port; + char name[20], *devname; + struct VMChannel *vmc; + + port = strtol(p, &devname, 10); + devname++; + if (port < 1 || port > 65535) { + fprintf(stderr, "vmchannel wrong port number\n"); + return -1; + } + vmc = malloc(sizeof(struct VMChannel)); + snprintf(name, 20, "vmchannel%ld", port); + vmc->hd = qemu_chr_open(name, devname); + if (!vmc->hd) { + fprintf(stderr, "qemu: could not open vmchannel device" + "'%s'\n", devname); + return -1; + } + vmc->port = port; + slirp_add_exec(3, vmc->hd, 4, port); + qemu_chr_add_handlers(vmc->hd, vmchannel_can_read, vmchannel_read, + NULL, vmc); + ret = 0; } else #endif #ifdef _WIN32 -- Gleb.