1 | /* |
1 | /* |
2 | device-cygwin.C -- Stub for Cygwin environment |
2 | device-cygwin.C -- Stub for Cygwin environment |
3 | Copyright (C) 2003-2004 Marc Lehmann <ocg@goof.com> |
3 | Copyright (C) 2003-2008 Marc Lehmann <ocg@goof.com> |
4 | Copyright (C) 2002-2003 Ivo Timmermans <ivo@o2w.nl>, |
4 | Copyright (C) 2002-2003 Ivo Timmermans <ivo@o2w.nl>, |
5 | 2002-2003 Guus Sliepen <guus@sliepen.eu.org> |
5 | 2002-2003 Guus Sliepen <guus@sliepen.eu.org> |
6 | |
6 | |
|
|
7 | This file is part of GVPE. |
|
|
8 | |
7 | This program is free software; you can redistribute it and/or modify |
9 | GVPE is free software; you can redistribute it and/or modify it |
8 | it under the terms of the GNU General Public License as published by |
10 | under the terms of the GNU General Public License as published by the |
9 | the Free Software Foundation; either version 2 of the License, or |
11 | Free Software Foundation; either version 3 of the License, or (at your |
10 | (at your option) any later version. |
12 | option) any later version. |
11 | |
13 | |
12 | This program is distributed in the hope that it will be useful, |
14 | This program is distributed in the hope that it will be useful, but |
13 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
15 | WITHOUT ANY WARRANTY; without even the implied warranty of |
14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
16 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General |
15 | GNU General Public License for more details. |
17 | Public License for more details. |
16 | |
18 | |
17 | You should have received a copy of the GNU General Public License |
19 | You should have received a copy of the GNU General Public License along |
18 | along with this program; if not, write to the Free Software |
20 | with this program; if not, see <http://www.gnu.org/licenses/>. |
19 | Foundation, Inc. 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
21 | |
|
|
22 | Additional permission under GNU GPL version 3 section 7 |
|
|
23 | |
|
|
24 | If you modify this Program, or any covered work, by linking or |
|
|
25 | combining it with the OpenSSL project's OpenSSL library (or a modified |
|
|
26 | version of that library), containing parts covered by the terms of the |
|
|
27 | OpenSSL or SSLeay licenses, the licensors of this Program grant you |
|
|
28 | additional permission to convey the resulting work. Corresponding |
|
|
29 | Source for a non-source form of such a combination shall include the |
|
|
30 | source code for the parts of OpenSSL used as well as that of the |
|
|
31 | covered work. |
20 | */ |
32 | */ |
21 | |
33 | |
22 | // unfortunately, there is be no way to set MAC addresses under windows, |
34 | // unfortunately, there is be no way to set MAC addresses under windows, |
23 | // and the default cipedrvr uses a different MAC address than we do, |
35 | // and the default cipedrvr uses a different MAC address than we do, |
24 | // so this module tries to fix mac addresses in packets and arp packets. |
36 | // so this module tries to fix mac addresses in packets and arp packets. |
… | |
… | |
28 | // a newer driver is available as part of the openvpn package: |
40 | // a newer driver is available as part of the openvpn package: |
29 | // http://openvpn.sf.net/ |
41 | // http://openvpn.sf.net/ |
30 | |
42 | |
31 | #include "config.h" |
43 | #include "config.h" |
32 | |
44 | |
33 | #include <stdio.h> |
45 | #include <cstdio> |
|
|
46 | #include <cstring> |
|
|
47 | #include <cstdlib> |
34 | #include <errno.h> |
48 | #include <errno.h> |
35 | #include <sys/types.h> |
49 | #include <sys/types.h> |
36 | #include <sys/stat.h> |
50 | #include <sys/stat.h> |
37 | #include <fcntl.h> |
51 | #include <fcntl.h> |
38 | #include <unistd.h> |
52 | #include <unistd.h> |
39 | #include <cstring> |
|
|
40 | |
53 | |
41 | #include "conf.h" |
54 | #include "conf.h" |
42 | #include "util.h" |
55 | #include "util.h" |
43 | |
56 | |
44 | #include <io.h> |
57 | #include <io.h> |
… | |
… | |
100 | if (GetLastError () == ERROR_IO_PENDING) |
113 | if (GetLastError () == ERROR_IO_PENDING) |
101 | GetOverlappedResult (device_handle, &overlapped, &dlen, TRUE); |
114 | GetOverlappedResult (device_handle, &overlapped, &dlen, TRUE); |
102 | else |
115 | else |
103 | { |
116 | { |
104 | slog (L_ERR, "WIN32 TAP: ReadFile returned error: %s", wstrerror (GetLastError ())); |
117 | slog (L_ERR, "WIN32 TAP: ReadFile returned error: %s", wstrerror (GetLastError ())); |
105 | exit (1); |
118 | exit (EXIT_FAILURE); |
106 | } |
119 | } |
107 | } |
120 | } |
108 | |
121 | |
109 | if (dlen > 0) |
122 | if (dlen > 0) |
110 | { |
123 | { |
… | |
… | |
119 | tap_device::info () |
132 | tap_device::info () |
120 | { |
133 | { |
121 | return _("cygwin cipe/openvpn tap device"); |
134 | return _("cygwin cipe/openvpn tap device"); |
122 | } |
135 | } |
123 | |
136 | |
|
|
137 | const char * |
|
|
138 | tap_device::if_up () |
|
|
139 | { |
|
|
140 | return ""; |
|
|
141 | } |
|
|
142 | |
124 | tap_device::tap_device () |
143 | tap_device::tap_device () |
125 | { |
144 | { |
126 | HKEY key, key2; |
145 | HKEY key, key2; |
127 | int i; |
146 | int i; |
128 | |
147 | |
… | |
… | |
140 | |
159 | |
141 | if (RegOpenKeyEx (HKEY_LOCAL_MACHINE, REG_CONTROL_NET, 0, KEY_READ, &key)) |
160 | if (RegOpenKeyEx (HKEY_LOCAL_MACHINE, REG_CONTROL_NET, 0, KEY_READ, &key)) |
142 | { |
161 | { |
143 | slog (L_ERR, _("WIN32 TAP: unable to read registry: %s"), |
162 | slog (L_ERR, _("WIN32 TAP: unable to read registry: %s"), |
144 | wstrerror (GetLastError ())); |
163 | wstrerror (GetLastError ())); |
145 | exit (1); |
164 | exit (EXIT_FAILURE); |
146 | } |
165 | } |
147 | |
166 | |
148 | for (i = 0;; i++) |
167 | for (i = 0;; i++) |
149 | { |
168 | { |
150 | len = sizeof (adapterid); |
169 | len = sizeof (adapterid); |
… | |
… | |
191 | RegCloseKey (key); |
210 | RegCloseKey (key); |
192 | |
211 | |
193 | if (!found) |
212 | if (!found) |
194 | { |
213 | { |
195 | slog (L_ERR, _("WIN32 TAP: no windows tap device found!")); |
214 | slog (L_ERR, _("WIN32 TAP: no windows tap device found!")); |
196 | exit (1); |
215 | exit (EXIT_FAILURE); |
197 | } |
216 | } |
198 | |
217 | |
199 | /* Try to open the corresponding tap device */ |
218 | /* Try to open the corresponding tap device */ |
200 | |
219 | |
201 | if (device_handle == INVALID_HANDLE_VALUE) |
220 | if (device_handle == INVALID_HANDLE_VALUE) |
… | |
… | |
209 | |
228 | |
210 | if (device_handle == INVALID_HANDLE_VALUE) |
229 | if (device_handle == INVALID_HANDLE_VALUE) |
211 | { |
230 | { |
212 | slog (L_ERR, _("WIN32 TAP: %s is not a usable windows tap device %s: %s"), |
231 | slog (L_ERR, _("WIN32 TAP: %s is not a usable windows tap device %s: %s"), |
213 | adaptername, tapname, wstrerror (GetLastError ())); |
232 | adaptername, tapname, wstrerror (GetLastError ())); |
214 | exit (1); |
233 | exit (EXIT_FAILURE); |
215 | } |
234 | } |
216 | |
235 | |
217 | strcpy (ifrname, (char *)tapname); |
236 | strcpy (ifrname, (char *)tapname); |
218 | |
237 | |
219 | /* Get MAC address from tap device */ |
238 | /* Get MAC address from tap device */ |
… | |
… | |
223 | &len, 0)) |
242 | &len, 0)) |
224 | { |
243 | { |
225 | slog (L_ERR, |
244 | slog (L_ERR, |
226 | _("WIN32 TAP: could not get MAC address from windows tap device %s: %s"), |
245 | _("WIN32 TAP: could not get MAC address from windows tap device %s: %s"), |
227 | adaptername, wstrerror (GetLastError ())); |
246 | adaptername, wstrerror (GetLastError ())); |
228 | exit (1); |
247 | exit (EXIT_FAILURE); |
229 | } |
248 | } |
230 | |
249 | |
231 | pipe (iopipe); |
250 | pipe (iopipe); |
232 | fd = iopipe[0]; |
251 | fd = iopipe[0]; |
233 | pipe_handle = (HANDLE) get_osfhandle (iopipe[1]); |
252 | pipe_handle = (HANDLE) get_osfhandle (iopipe[1]); |