1 | /* |
1 | /* |
2 | device-linux.C -- Interaction with Linux tun/tap device |
2 | device-linux.C -- Interaction with Linux tun/tap device |
|
|
3 | Copyright (C) 2003-2004 Marc Lehmann <pcg@goof.com> |
3 | |
4 | |
4 | This program is free software; you can redistribute it and/or modify |
5 | This program is free software; you can redistribute it and/or modify |
5 | it under the terms of the GNU General Public License as published by |
6 | it under the terms of the GNU General Public License as published by |
6 | the Free Software Foundation; either version 2 of the License, or |
7 | the Free Software Foundation; either version 2 of the License, or |
7 | (at your option) any later version. |
8 | (at your option) any later version. |
… | |
… | |
42 | #include "gettext.h" |
43 | #include "gettext.h" |
43 | |
44 | |
44 | #include "conf.h" |
45 | #include "conf.h" |
45 | |
46 | |
46 | #if TEST_ETHEREMU |
47 | #if TEST_ETHEREMU |
|
|
48 | # define IF_istun |
47 | # include "ether_emu.C" |
49 | # include "ether_emu.C" |
48 | #endif |
50 | #endif |
49 | |
51 | |
50 | const char * |
52 | const char * |
51 | tap_device::info () |
53 | tap_device::info () |
… | |
… | |
62 | fd = open (device, O_RDWR); |
64 | fd = open (device, O_RDWR); |
63 | |
65 | |
64 | if (fd < 0) |
66 | if (fd < 0) |
65 | { |
67 | { |
66 | slog (L_ERR, _("could not open device %s: %s"), device, strerror (errno)); |
68 | slog (L_ERR, _("could not open device %s: %s"), device, strerror (errno)); |
67 | exit (1); |
69 | exit (EXIT_FAILURE); |
68 | } |
70 | } |
69 | |
71 | |
70 | memset (&ifr, 0, sizeof (ifr)); |
72 | memset (&ifr, 0, sizeof (ifr)); |
71 | #if TEST_ETHEREMU |
73 | #if TEST_ETHEREMU |
72 | ifr.ifr_flags = IFF_TUN | IFF_NO_PI; |
74 | ifr.ifr_flags = IFF_TUN | IFF_NO_PI; |
… | |
… | |
85 | ifrname [IFNAMSIZ] = 0; |
87 | ifrname [IFNAMSIZ] = 0; |
86 | } |
88 | } |
87 | else |
89 | else |
88 | { |
90 | { |
89 | slog (L_CRIT, _("unable to configure tun/tap interface: %s"), strerror (errno)); |
91 | slog (L_CRIT, _("unable to configure tun/tap interface: %s"), strerror (errno)); |
90 | exit (1); |
92 | exit (EXIT_FAILURE); |
91 | } |
93 | } |
92 | |
94 | |
93 | if (ioctl (fd, TUNSETPERSIST, conf.ifpersist ? 1 : 0)) |
95 | if (ioctl (fd, TUNSETPERSIST, conf.ifpersist ? 1 : 0)) |
94 | slog (L_WARN, _("cannot set persistency mode for device %s: %s"), ifrname, strerror (errno)); |
96 | slog (L_WARN, _("cannot set persistency mode for device %s: %s"), ifrname, strerror (errno)); |
95 | |
97 | |