Subject: pkg/37003: pkg emulators/qemu seg faults when using tap interface
To: None <pkg-manager@netbsd.org, gnats-admin@netbsd.org,>
From: Cliff Wright <cliff@wright-c.itdl.ds.boeing.com>
List: pkgsrc-bugs
Date: 09/19/2007 01:05:00
	Note: There was a bad value `' for the field `Priority'.
	It was set to the default value of `medium'.

>Number:         37003
>Category:       pkg
>Synopsis:       pkg emulators/qemu seg faults when using tap interface
>Confidential:   no
>Severity:       non-critical
>Priority:       medium
>Responsible:    pkg-manager
>State:          open
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Wed Sep 19 01:05:00 +0000 2007
>Originator:     Cliff Wright
>Release:        NetBSD 3.0.1
>Organization:
	
>Environment:
	
	
System: NetBSD blitzen.snipe444.org 3.0.1 NetBSD 3.0.1 (XEN0) #4: Tue Feb 6 13:03:05 PST 2007 cliff@blitzen.snipe444.org:/usr/src/sys/arch/i386/compile/XEN0 i386
Architecture: i386
Machine: i386
>Description:
	
	When starting qemu with the tap option ( e.g.
	qemu -m 150 -net nic -net tap,script=netset freedos.img )
	a seg fault will occur.
	This is due to NetBSD handling tap device name differently,
	it does not allow an fstat, but uses an ioctl instead.
	Below is a patch I used to fix this.
>How-To-Repeat:
	
	See above example.
>Fix:
	
--- vl.c.sav	2007-09-14 17:28:52.000000000 -0700
+++ vl.c	2007-09-18 14:30:18.000000000 -0700
@@ -46,7 +46,12 @@
 #include <dirent.h>
 #include <netdb.h>
 #ifdef _BSD
+#ifdef __NetBSD__
+#include <net/if.h>
+#include <net/if_tap.h>
+#else
 #include <sys/stat.h>
+#endif
 #ifndef _BSD
 #include <libutil.h>
 #endif
@@ -2570,7 +2575,11 @@
 {
     int fd;
     char *dev;
+#ifdef __NetBSD__
+    struct ifreq tapif;
+#else
     struct stat s;
+#endif
 
     fd = open("/dev/tap", O_RDWR);
     if (fd < 0) {
@@ -2578,8 +2587,13 @@
         return -1;
     }
 
+#ifdef __NetBSD__
+    ioctl(fd, TAPGIFNAME, &tapif);
+    dev = tapif.ifr_name;
+#else
     fstat(fd, &s);
     dev = devname(s.st_rdev, S_IFCHR);
+#endif
     pstrcpy(ifname, ifname_size, dev);
 
     fcntl(fd, F_SETFL, O_NONBLOCK);

>Unformatted: