aboutsummaryrefslogtreecommitdiff
path: root/net
diff options
context:
space:
mode:
authorJuergen Lock <nox@jelal.kn-bremen.de>2009-11-20 23:31:55 +0100
committerBlue Swirl <blauwirbel@gmail.com>2009-11-21 09:32:08 +0000
commit2f859a3c10c8a038661592fcdfe003ec97cca938 (patch)
tree3503aa689f0820aa9abaa4b3a5c0b44aa1340837 /net
parentFix tap breakage on BSD hosts (no IFF_VNET_HDR) (diff)
downloadqemu-kvm-2f859a3c10c8a038661592fcdfe003ec97cca938.tar.gz
qemu-kvm-2f859a3c10c8a038661592fcdfe003ec97cca938.tar.bz2
qemu-kvm-2f859a3c10c8a038661592fcdfe003ec97cca938.zip
tap-bsd: handle ifname on FreeBSD hosts
Handle ifname on FreeBSD hosts; if no ifname is given, always start the search from tap0. (Simplified/cleaned up version of what has been in the FreeBSD ports for a long time.) Signed-off-by: Juergen Lock <nox@jelal.kn-bremen.de> Signed-off-by: Blue Swirl <blauwirbel@gmail.com>
Diffstat (limited to 'net')
-rw-r--r--net/tap-bsd.c28
1 files changed, 28 insertions, 0 deletions
diff --git a/net/tap-bsd.c b/net/tap-bsd.c
index bde2083e5..0f8ad4ad7 100644
--- a/net/tap-bsd.c
+++ b/net/tap-bsd.c
@@ -49,11 +49,39 @@ int tap_open(char *ifname, int ifname_size, int *vnet_hdr, int vnet_hdr_required
char *dev;
struct stat s;
+#ifdef __FreeBSD__
+ /* if no ifname is given, always start the search from tap0. */
+ int i;
+ char dname[100];
+
+ for (i = 0; i < 10; i++) {
+ if (*ifname) {
+ snprintf(dname, sizeof dname, "/dev/%s", ifname);
+ } else {
+ snprintf(dname, sizeof dname, "/dev/tap%d", i);
+ }
+ TFR(fd = open(dname, O_RDWR));
+ if (fd >= 0) {
+ break;
+ }
+ else if (errno == ENXIO || errno == ENOENT) {
+ break;
+ }
+ if (*ifname) {
+ break;
+ }
+ }
+ if (fd < 0) {
+ qemu_error("warning: could not open %s (%s): no virtual network emulation\n", dname, strerror(errno));
+ return -1;
+ }
+#else
TFR(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);