openbsd-ports/emulators/qemu/patches/patch-vl_c

194 lines
5.6 KiB
Plaintext
Raw Normal View History

--- vl.c.orig Mon Dec 18 16:55:53 2006
+++ vl.c Mon Dec 18 17:06:04 2006
@@ -43,7 +43,8 @@
#include <netdb.h>
#ifdef _BSD
#include <sys/stat.h>
-#ifndef __APPLE__
+#include <net/if.h>
+#if !defined(__APPLE__) && !defined(__OpenBSD__)
#include <libutil.h>
#endif
#else
@@ -291,7 +292,7 @@ void isa_unassign_ioport(int start, int
/***********************************************************/
-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;
@@ -309,7 +310,7 @@ void pstrcpy(char *buf, int buf_size, co
}
/* 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);
@@ -2631,7 +2632,7 @@ static int parse_macaddr(uint8_t *macadd
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;
@@ -3029,11 +3030,85 @@ static int tap_open(char *ifname, int if
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);
@@ -3535,7 +3610,8 @@ static int net_socket_mcast_init(VLANSta
}
-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;
@@ -3660,17 +3736,21 @@ int net_client_init(const char *str)
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
@@ -5453,7 +5533,23 @@ void register_machines(void)
#elif defined(TARGET_SH4)
qemu_register_machine(&shix_machine);
#else
-#error unsupported CPU
+# warning non-optimized CPU
+#include <sys/time.h>
+#include <time.h>
+
+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
}
@@ -5671,7 +5767,7 @@ int main(int argc, char **argv)
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;