root / net / tap-bsd.c @ 15ac913b
History | View | Annotate | Download (2 kB)
1 | e7e92325 | Mark McLoughlin | /*
|
---|---|---|---|
2 | e7e92325 | Mark McLoughlin | * QEMU System Emulator
|
3 | e7e92325 | Mark McLoughlin | *
|
4 | e7e92325 | Mark McLoughlin | * Copyright (c) 2003-2008 Fabrice Bellard
|
5 | e7e92325 | Mark McLoughlin | *
|
6 | e7e92325 | Mark McLoughlin | * Permission is hereby granted, free of charge, to any person obtaining a copy
|
7 | e7e92325 | Mark McLoughlin | * of this software and associated documentation files (the "Software"), to deal
|
8 | e7e92325 | Mark McLoughlin | * in the Software without restriction, including without limitation the rights
|
9 | e7e92325 | Mark McLoughlin | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
10 | e7e92325 | Mark McLoughlin | * copies of the Software, and to permit persons to whom the Software is
|
11 | e7e92325 | Mark McLoughlin | * furnished to do so, subject to the following conditions:
|
12 | e7e92325 | Mark McLoughlin | *
|
13 | e7e92325 | Mark McLoughlin | * The above copyright notice and this permission notice shall be included in
|
14 | e7e92325 | Mark McLoughlin | * all copies or substantial portions of the Software.
|
15 | e7e92325 | Mark McLoughlin | *
|
16 | e7e92325 | Mark McLoughlin | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
17 | e7e92325 | Mark McLoughlin | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
18 | e7e92325 | Mark McLoughlin | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
19 | e7e92325 | Mark McLoughlin | * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
20 | e7e92325 | Mark McLoughlin | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
21 | e7e92325 | Mark McLoughlin | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
22 | e7e92325 | Mark McLoughlin | * THE SOFTWARE.
|
23 | e7e92325 | Mark McLoughlin | */
|
24 | e7e92325 | Mark McLoughlin | |
25 | e7e92325 | Mark McLoughlin | #include "net/tap.h" |
26 | e7e92325 | Mark McLoughlin | #incude "qemu-common.h" |
27 | e7e92325 | Mark McLoughlin | |
28 | e7e92325 | Mark McLoughlin | #ifdef __NetBSD__
|
29 | e7e92325 | Mark McLoughlin | #include <net/if_tap.h> |
30 | e7e92325 | Mark McLoughlin | #endif
|
31 | e7e92325 | Mark McLoughlin | |
32 | e7e92325 | Mark McLoughlin | #if defined(__FreeBSD__) || defined(__DragonFly__)
|
33 | e7e92325 | Mark McLoughlin | #include <libutil.h> |
34 | e7e92325 | Mark McLoughlin | #else
|
35 | e7e92325 | Mark McLoughlin | #include <util.h> |
36 | e7e92325 | Mark McLoughlin | #endif
|
37 | e7e92325 | Mark McLoughlin | #elif defined (__GLIBC__) && defined (__FreeBSD_kernel__)
|
38 | e7e92325 | Mark McLoughlin | #include <freebsd/stdlib.h> |
39 | e7e92325 | Mark McLoughlin | |
40 | e7e92325 | Mark McLoughlin | #if defined(__OpenBSD__)
|
41 | e7e92325 | Mark McLoughlin | #include <util.h> |
42 | e7e92325 | Mark McLoughlin | #endif
|
43 | e7e92325 | Mark McLoughlin | |
44 | e7e92325 | Mark McLoughlin | int tap_open(char *ifname, int ifname_size, int *vnet_hdr, int vnet_hdr_required) |
45 | e7e92325 | Mark McLoughlin | { |
46 | e7e92325 | Mark McLoughlin | int fd;
|
47 | e7e92325 | Mark McLoughlin | char *dev;
|
48 | e7e92325 | Mark McLoughlin | struct stat s;
|
49 | e7e92325 | Mark McLoughlin | |
50 | e7e92325 | Mark McLoughlin | TFR(fd = open("/dev/tap", O_RDWR));
|
51 | e7e92325 | Mark McLoughlin | if (fd < 0) { |
52 | e7e92325 | Mark McLoughlin | fprintf(stderr, "warning: could not open /dev/tap: no virtual network emulation\n");
|
53 | e7e92325 | Mark McLoughlin | return -1; |
54 | e7e92325 | Mark McLoughlin | } |
55 | e7e92325 | Mark McLoughlin | |
56 | e7e92325 | Mark McLoughlin | fstat(fd, &s); |
57 | e7e92325 | Mark McLoughlin | dev = devname(s.st_rdev, S_IFCHR); |
58 | e7e92325 | Mark McLoughlin | pstrcpy(ifname, ifname_size, dev); |
59 | e7e92325 | Mark McLoughlin | |
60 | e7e92325 | Mark McLoughlin | fcntl(fd, F_SETFL, O_NONBLOCK); |
61 | e7e92325 | Mark McLoughlin | return fd;
|
62 | e7e92325 | Mark McLoughlin | } |
63 | 15ac913b | Mark McLoughlin | |
64 | 15ac913b | Mark McLoughlin | int tap_set_sndbuf(int fd, QemuOpts *opts) |
65 | 15ac913b | Mark McLoughlin | { |
66 | 15ac913b | Mark McLoughlin | return 0; |
67 | 15ac913b | Mark McLoughlin | } |