ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/gvpe/src/device-cygwin.C
(Generate patch)

Comparing gvpe/src/device-cygwin.C (file contents):
Revision 1.6 by pcg, Wed Oct 15 06:06:41 2003 UTC vs.
Revision 1.11 by pcg, Tue Apr 26 00:55:56 2005 UTC

1/* 1/*
2 device-cygwin.C -- Stub for Cygwin environment 2 device-cygwin.C -- Stub for Cygwin environment
3 Copyright (C) 2003 Marc Lehmann <ocg@goof.com> 3 Copyright (C) 2003-2005 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
8 it under the terms of the GNU General Public License as published by 10 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or 11 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version. 12 (at your 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,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of 15 but 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
15 GNU General Public License for more details. 17 GNU General 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
18 along with this program; if not, write to the Free Software 20 along with gvpe; if not, write to the Free Software
19 Foundation, Inc. 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 21 Foundation, Inc. 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20*/ 22*/
21 23
22// unfortunately, there is be no way to set MAC addresses under windows, 24// 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, 25// 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. 26// 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: 30// a newer driver is available as part of the openvpn package:
29// http://openvpn.sf.net/ 31// http://openvpn.sf.net/
30 32
31#include "config.h" 33#include "config.h"
32 34
33#include <stdio.h> 35#include <cstdio>
36#include <cstring>
37#include <cstdlib>
34#include <errno.h> 38#include <errno.h>
35#include <sys/types.h> 39#include <sys/types.h>
36#include <sys/stat.h> 40#include <sys/stat.h>
37#include <fcntl.h> 41#include <fcntl.h>
38#include <unistd.h> 42#include <unistd.h>
39#include <cstring>
40 43
41#include "conf.h" 44#include "conf.h"
42#include "util.h" 45#include "util.h"
43 46
44#include <io.h> 47#include <io.h>
100 if (GetLastError () == ERROR_IO_PENDING) 103 if (GetLastError () == ERROR_IO_PENDING)
101 GetOverlappedResult (device_handle, &overlapped, &dlen, TRUE); 104 GetOverlappedResult (device_handle, &overlapped, &dlen, TRUE);
102 else 105 else
103 { 106 {
104 slog (L_ERR, "WIN32 TAP: ReadFile returned error: %s", wstrerror (GetLastError ())); 107 slog (L_ERR, "WIN32 TAP: ReadFile returned error: %s", wstrerror (GetLastError ()));
105 exit (1); 108 exit (EXIT_FAILURE);
106 } 109 }
107 } 110 }
108 111
109 if (dlen > 0) 112 if (dlen > 0)
110 { 113 {
119tap_device::info () 122tap_device::info ()
120{ 123{
121 return _("cygwin cipe/openvpn tap device"); 124 return _("cygwin cipe/openvpn tap device");
122} 125}
123 126
127const char *
128tap_device::if_up ()
129{
130 return "";
131}
132
124tap_device::tap_device () 133tap_device::tap_device ()
125{ 134{
126 HKEY key, key2; 135 HKEY key, key2;
127 int i; 136 int i;
128 137
140 149
141 if (RegOpenKeyEx (HKEY_LOCAL_MACHINE, REG_CONTROL_NET, 0, KEY_READ, &key)) 150 if (RegOpenKeyEx (HKEY_LOCAL_MACHINE, REG_CONTROL_NET, 0, KEY_READ, &key))
142 { 151 {
143 slog (L_ERR, _("WIN32 TAP: unable to read registry: %s"), 152 slog (L_ERR, _("WIN32 TAP: unable to read registry: %s"),
144 wstrerror (GetLastError ())); 153 wstrerror (GetLastError ()));
145 exit (1); 154 exit (EXIT_FAILURE);
146 } 155 }
147 156
148 for (i = 0;; i++) 157 for (i = 0;; i++)
149 { 158 {
150 len = sizeof (adapterid); 159 len = sizeof (adapterid);
191 RegCloseKey (key); 200 RegCloseKey (key);
192 201
193 if (!found) 202 if (!found)
194 { 203 {
195 slog (L_ERR, _("WIN32 TAP: no windows tap device found!")); 204 slog (L_ERR, _("WIN32 TAP: no windows tap device found!"));
196 exit (1); 205 exit (EXIT_FAILURE);
197 } 206 }
198 207
199 /* Try to open the corresponding tap device */ 208 /* Try to open the corresponding tap device */
200 209
201 if (device_handle == INVALID_HANDLE_VALUE) 210 if (device_handle == INVALID_HANDLE_VALUE)
209 218
210 if (device_handle == INVALID_HANDLE_VALUE) 219 if (device_handle == INVALID_HANDLE_VALUE)
211 { 220 {
212 slog (L_ERR, _("WIN32 TAP: %s is not a usable windows tap device %s: %s"), 221 slog (L_ERR, _("WIN32 TAP: %s is not a usable windows tap device %s: %s"),
213 adaptername, tapname, wstrerror (GetLastError ())); 222 adaptername, tapname, wstrerror (GetLastError ()));
214 exit (1); 223 exit (EXIT_FAILURE);
215 } 224 }
216 225
217 strcpy (ifrname, (char *)tapname); 226 strcpy (ifrname, (char *)tapname);
218 227
219 /* Get MAC address from tap device */ 228 /* Get MAC address from tap device */
223 &len, 0)) 232 &len, 0))
224 { 233 {
225 slog (L_ERR, 234 slog (L_ERR,
226 _("WIN32 TAP: could not get MAC address from windows tap device %s: %s"), 235 _("WIN32 TAP: could not get MAC address from windows tap device %s: %s"),
227 adaptername, wstrerror (GetLastError ())); 236 adaptername, wstrerror (GetLastError ()));
228 exit (1); 237 exit (EXIT_FAILURE);
229 } 238 }
230 239
231 pipe (iopipe); 240 pipe (iopipe);
232 fd = iopipe[0]; 241 fd = iopipe[0];
233 pipe_handle = (HANDLE) get_osfhandle (iopipe[1]); 242 pipe_handle = (HANDLE) get_osfhandle (iopipe[1]);

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines