From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1FgWZz-0003QA-Jf for qemu-devel@nongnu.org; Wed, 17 May 2006 20:41:27 -0400 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1FgWZz-0003Py-0X for qemu-devel@nongnu.org; Wed, 17 May 2006 20:41:27 -0400 Received: from [199.232.76.173] (helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1FgWZy-0003Pv-Tg for qemu-devel@nongnu.org; Wed, 17 May 2006 20:41:26 -0400 Received: from [66.210.104.251] (helo=FreeDaemonHosting.com) by monty-python.gnu.org with esmtps (TLS-1.0:DHE_RSA_AES_256_CBC_SHA:32) (Exim 4.52) id 1FgWcx-0000ar-5z for qemu-devel@nongnu.org; Wed, 17 May 2006 20:44:31 -0400 Received: from blue.fries.net (blue.hse.fries.net [IPv6:2001:240:58a::1c]) by FreeDaemonHosting.com (8.13.4/8.13.3) with ESMTP id k4I0f98O020958 for ; Wed, 17 May 2006 19:41:09 -0500 (CDT) Received: from blue.fries.net (localhost.fries.net [IPv6:::1]) by blue.fries.net (8.13.6/8.13.6) with ESMTP id k4I0eaH3025304 for ; Wed, 17 May 2006 19:40:36 -0500 (CDT) Received: (from todd@localhost) by blue.fries.net (8.13.6/8.13.6/Submit) id k4I0easv018007 for qemu-devel@nongnu.org; Wed, 17 May 2006 19:40:36 -0500 (CDT) From: "Todd T. Fries" Date: Wed, 17 May 2006 19:40:34 -0500 MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Content-Disposition: inline Message-Id: <200605171940.35480.qemu-devel@email.fries.net> Subject: [Qemu-devel] [PATCH] fix vl.c for OpenBSD & part 2 of prototype fixes Reply-To: todd@fries.net, 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 --- vl.c.orig Wed May 3 15:32:58 2006 +++ vl.c Wed May 17 19:38:07 2006 @@ -43,7 +43,8 @@ #include #ifdef _BSD #include -#ifndef __APPLE__ +#include +#if !defined(__APPLE__) && !defined(__OpenBSD__) #include #endif #else @@ -292,7 +293,7 @@ /***********************************************************/ -void pstrcpy(char *buf, int buf_size, const char *str) +void pstrcpy(char *buf, size_t buf_size, const char *str) { int c; char *q = buf; @@ -310,7 +311,7 @@ } /* strcat and truncate. */ -char *pstrcat(char *buf, int buf_size, const char *s) +char *pstrcat(char *buf, size_t buf_size, const char *s) { int len; len = strlen(buf); @@ -561,7 +562,23 @@ } #else -#error unsupported CPU +# warning non-optimized CPU +#include +#include + +int64_t cpu_get_real_ticks(void) +{ + struct timeval tv; + static int64_t i = 0; + int64_t j; + + gettimeofday(&tv, NULL); + do { + j = (tv.tv_sec * (uint64_t) 1000000) + tv.tv_usec; + } while (i == j); + i = j; + return j; +} #endif static int64_t cpu_ticks_prev; @@ -2201,7 +2218,7 @@ return 0; } -static int get_str_sep(char *buf, int buf_size, const char **pp, int sep) +static int get_str_sep(char *buf, size_t buf_size, const char **pp, int sep) { const char *p, *p1; int len; @@ -2560,11 +2577,85 @@ char *dev; struct stat s; + /* If the device was specified on the command line, use it */ + if (ifname[0]) { + fd = open(ifname, O_RDWR); + if (fd < 0) { + fprintf(stderr, "warning: could not open %s: no virtual network emulation\n", ifname); + return -1; + } + } else { +#ifdef __OpenBSD__ + struct ifreq ifr; + int i = 0, enoentcount = 0, err = 0, sock; + char dname[100], iname[100]; + + bzero(&ifr, sizeof(ifr)); + if (ifname != NULL && ifname[0] != '\0') { + snprintf(dname, sizeof(dname), "/dev/%s", ifname); + strlcpy(ifr.ifr_name, ifname, sizeof(ifr.ifr_name)); + fd = open(dname, O_RDWR); + } else { + for (; i != -1; i++) { + snprintf(dname, sizeof dname, "/dev/tun%d", i); + bzero(&ifr.ifr_name, sizeof(ifr.ifr_name)); + snprintf(ifr.ifr_name, sizeof(ifr.ifr_name), "tun%d", i); + fd = open(dname, O_RDWR); + if (fd >= 0) + break; + else if (errno != ENOENT || ++enoentcount > 3) { + if (errno != EBUSY) { + err = errno; + break; + } + } else + err = errno; + } + } + if (fd < 0) { + fprintf(stderr, "warning: could not open %s (%s): no virtual " + "network emulation\n", dname, strerror(err)); + return -1; + } + + /* Set the tunnel device operation mode */ + if ((sock = socket(PF_UNIX, SOCK_STREAM, 0)) == -1) { + close(fd); + return -1; + } + + /* Get interface flags */ + if (ioctl(sock, SIOCGIFFLAGS, &ifr) == -1) { + close(fd); + close(sock); + return -1; + } + + /* Set interface mode */ + ifr.ifr_flags &= ~IFF_UP; + ifr.ifr_flags |= IFF_LINK0; + if (ioctl(sock, SIOCSIFFLAGS, &ifr) == -1) { + close(fd); + close(sock); + return -1; + } + + /* Bring interface up */ + ifr.ifr_flags |= IFF_UP; + if (ioctl(sock, SIOCSIFFLAGS, &ifr) == -1) { + close(fd); + close(sock); + return -1; + } + +#else fd = open("/dev/tap", O_RDWR); if (fd < 0) { fprintf(stderr, "warning: could not open /dev/tap: no virtual network emulation\n"); return -1; } +#endif + } fstat(fd, &s); dev = devname(s.st_rdev, S_IFCHR); @@ -3065,7 +3156,8 @@ } -static int get_param_value(char *buf, int buf_size, +static int get_param_value(char *, size_t, const char *, const char *); +static int get_param_value(char *buf, size_t buf_size, const char *tag, const char *str) { const char *p; @@ -3190,17 +3282,21 @@ char ifname[64]; char setup_script[1024]; int fd; + bzero(&ifname,sizeof(ifname)); + bzero(&setup_script,sizeof(setup_script)); if (get_param_value(buf, sizeof(buf), "fd", p) > 0) { fd = strtol(buf, NULL, 0); ret = -1; if (net_tap_fd_init(vlan, fd)) ret = 0; } else { - get_param_value(ifname, sizeof(ifname), "ifname", p); if (get_param_value(setup_script, sizeof(setup_script), "script", p) == 0) { pstrcpy(setup_script, sizeof(setup_script), DEFAULT_NETWORK_SCRIPT); } - ret = net_tap_init(vlan, ifname, setup_script); + if (get_param_value(ifname, sizeof(ifname), "ifname", p) == 0) + ret = net_tap_init(vlan, NULL, setup_script); + else + ret = net_tap_init(vlan, ifname, setup_script); } } else #endif @@ -5101,7 +5197,7 @@ serial_devices[i][0] = '\0'; serial_device_index = 0; - pstrcpy(parallel_devices[0], sizeof(parallel_devices[0]), "vc"); + pstrcpy(parallel_devices[0], sizeof(parallel_devices[0]), "null"); for(i = 1; i < MAX_PARALLEL_PORTS; i++) parallel_devices[i][0] = '\0'; parallel_device_index = 0; -- Todd Fries .. todd@fries.net _____________________________________________ | \ 1.636.410.0632 (voice) | Free Daemon Consulting, LLC \ 1.405.227.9094 (voice) | http://FreeDaemonConsulting.com \ 1.866.792.3418 (FAX) | "..in support of free software solutions." \ 250797 (FWD) | \ \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\ 37E7 D3EB 74D0 8D66 A68D B866 0326 204E 3F42 004A http://todd.fries.net/pgp.txt