2006-12-22 12:31:45 -05:00
|
|
|
--- vl.c.orig Mon Dec 18 16:55:53 2006
|
|
|
|
+++ vl.c Mon Dec 18 17:06:04 2006
|
2006-02-16 11:27:44 -05:00
|
|
|
@@ -43,7 +43,8 @@
|
2005-12-27 02:56:14 -05:00
|
|
|
#include <netdb.h>
|
2005-03-07 11:41:28 -05:00
|
|
|
#ifdef _BSD
|
|
|
|
#include <sys/stat.h>
|
|
|
|
-#ifndef __APPLE__
|
2006-02-16 11:27:44 -05:00
|
|
|
+#include <net/if.h>
|
2005-03-07 11:41:28 -05:00
|
|
|
+#if !defined(__APPLE__) && !defined(__OpenBSD__)
|
|
|
|
#include <libutil.h>
|
|
|
|
#endif
|
|
|
|
#else
|
2006-12-22 12:31:45 -05:00
|
|
|
@@ -291,7 +292,7 @@ void isa_unassign_ioport(int start, int
|
2006-04-10 17:10:05 -04:00
|
|
|
|
|
|
|
/***********************************************************/
|
|
|
|
|
|
|
|
-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;
|
2006-12-22 12:31:45 -05:00
|
|
|
@@ -309,7 +310,7 @@ void pstrcpy(char *buf, int buf_size, co
|
2006-04-10 17:10:05 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
/* 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);
|
2006-12-22 12:31:45 -05:00
|
|
|
@@ -2631,7 +2632,7 @@ static int parse_macaddr(uint8_t *macadd
|
2006-04-10 17:10:05 -04:00
|
|
|
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;
|
2006-12-22 12:31:45 -05:00
|
|
|
@@ -3029,11 +3030,85 @@ static int tap_open(char *ifname, int if
|
2005-03-07 11:41:28 -05:00
|
|
|
char *dev;
|
|
|
|
struct stat s;
|
|
|
|
|
2006-02-16 11:27:44 -05:00
|
|
|
+ /* If the device was specified on the command line, use it */
|
|
|
|
+ if (ifname[0]) {
|
2006-12-22 12:31:45 -05:00
|
|
|
+ fd = open(ifname, O_RDWR);
|
|
|
|
+ if (fd < 0) {
|
|
|
|
+ fprintf(stderr, "warning: could not open %s: no virtual network emulation\n", ifname);
|
|
|
|
+ return -1;
|
|
|
|
+ }
|
2006-02-16 11:27:44 -05:00
|
|
|
+ } else {
|
2005-03-07 11:41:28 -05:00
|
|
|
+#ifdef __OpenBSD__
|
2006-02-16 11:27:44 -05:00
|
|
|
+ struct ifreq ifr;
|
|
|
|
+ int i = 0, enoentcount = 0, err = 0, sock;
|
|
|
|
+ char dname[100], iname[100];
|
2005-03-07 11:41:28 -05:00
|
|
|
+
|
2006-02-16 11:27:44 -05:00
|
|
|
+ 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 {
|
2006-04-10 17:10:05 -04:00
|
|
|
+ for (; i != -1; i++) {
|
2006-12-22 12:31:45 -05:00
|
|
|
+ snprintf(dname, sizeof dname, "/dev/tun%d", i);
|
2006-02-16 11:27:44 -05:00
|
|
|
+ bzero(&ifr.ifr_name, sizeof(ifr.ifr_name));
|
2006-12-22 12:31:45 -05:00
|
|
|
+ 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) {
|
2006-02-16 11:27:44 -05:00
|
|
|
+ if (errno != EBUSY) {
|
|
|
|
+ err = errno;
|
|
|
|
+ break;
|
|
|
|
+ }
|
|
|
|
+ } else
|
|
|
|
+ err = errno;
|
|
|
|
+ }
|
2005-03-07 11:41:28 -05:00
|
|
|
+ }
|
|
|
|
+ if (fd < 0) {
|
2006-12-22 12:31:45 -05:00
|
|
|
+ fprintf(stderr, "warning: could not open %s (%s): no virtual "
|
|
|
|
+ "network emulation\n", dname, strerror(err));
|
|
|
|
+ return -1;
|
2005-03-07 11:41:28 -05:00
|
|
|
+ }
|
2006-02-16 11:27:44 -05:00
|
|
|
+
|
|
|
|
+ /* 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;
|
|
|
|
+ }
|
|
|
|
+
|
2005-03-07 11:41:28 -05:00
|
|
|
+#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
|
2006-02-16 11:27:44 -05:00
|
|
|
+ }
|
2005-03-07 11:41:28 -05:00
|
|
|
|
|
|
|
fstat(fd, &s);
|
|
|
|
dev = devname(s.st_rdev, S_IFCHR);
|
2006-12-22 12:31:45 -05:00
|
|
|
@@ -3535,7 +3610,8 @@ static int net_socket_mcast_init(VLANSta
|
2006-02-08 08:44:17 -05:00
|
|
|
|
2006-06-08 10:33:38 -04:00
|
|
|
}
|
2006-04-10 17:10:05 -04:00
|
|
|
|
|
|
|
-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;
|
2006-12-22 12:31:45 -05:00
|
|
|
@@ -3660,17 +3736,21 @@ int net_client_init(const char *str)
|
2006-04-10 17:10:05 -04:00
|
|
|
char ifname[64];
|
|
|
|
char setup_script[1024];
|
|
|
|
int fd;
|
2006-12-22 12:31:45 -05:00
|
|
|
+ bzero(&ifname,sizeof(ifname));
|
|
|
|
+ bzero(&setup_script,sizeof(setup_script));
|
2006-04-10 17:10:05 -04:00
|
|
|
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)
|
2006-12-22 12:31:45 -05:00
|
|
|
+ ret = net_tap_init(vlan, NULL, setup_script);
|
|
|
|
+ else
|
|
|
|
+ ret = net_tap_init(vlan, ifname, setup_script);
|
2006-04-10 17:10:05 -04:00
|
|
|
}
|
|
|
|
} else
|
2006-06-08 10:33:38 -04:00
|
|
|
#endif
|
2006-12-22 12:31:45 -05:00
|
|
|
@@ -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;
|
|
|
|
+}
|
2005-12-27 02:56:14 -05:00
|
|
|
#endif
|
2006-12-22 12:31:45 -05:00
|
|
|
}
|
2005-12-27 02:56:14 -05:00
|
|
|
|
2006-12-22 12:31:45 -05:00
|
|
|
@@ -5671,7 +5767,7 @@ int main(int argc, char **argv)
|
2005-11-05 07:11:05 -05:00
|
|
|
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;
|