X-Git-Url: https://www.tinc-vpn.org/git/browse?p=tinc;a=blobdiff_plain;f=src%2Fcygwin%2Fdevice.c;h=cbfebc23866a85ff22078374b063b29041e7fa07;hp=131a786b1826aecce709ff47ac759cd62dd6869c;hb=2ed154e73192d5e162544bc570abbb3a1df3ec83;hpb=c15e8a96bf7e45adf750b7a36b0e8446ea049468 diff --git a/src/cygwin/device.c b/src/cygwin/device.c index 131a786b..cbfebc23 100644 --- a/src/cygwin/device.c +++ b/src/cygwin/device.c @@ -1,5 +1,5 @@ /* - device.c -- Interaction with CIPE driver in a Cygwin environment + device.c -- Interaction with Windows tap driver in a Cygwin environment Copyright (C) 2002-2003 Ivo Timmermans , 2002-2003 Guus Sliepen @@ -17,7 +17,7 @@ along with this program; if not, write to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. - $Id: device.c,v 1.1.2.11 2003/07/28 21:54:03 guus Exp $ + $Id: device.c,v 1.1.2.14 2003/07/29 23:21:01 guus Exp $ */ #include "system.h" @@ -95,26 +95,26 @@ bool setup_device(void) if(RegEnumKeyEx(key, i, adapterid, &len, 0, 0, 0, NULL)) break; - if(device) { - if(!strcmp(device, adapterid)) { - found = true; - break; - } else - continue; - } - /* Find out more about this adapter */ snprintf(regpath, sizeof(regpath), "%s\\%s\\Connection", REG_CONTROL_NET, adapterid); - if(RegOpenKeyEx(HKEY_LOCAL_MACHINE, regpath, 0, KEY_READ, &key2)) { - logger(LOG_ERR, _("Unable to read registry")); - return false; - } + if(RegOpenKeyEx(HKEY_LOCAL_MACHINE, regpath, 0, KEY_READ, &key2)) + continue; len = sizeof(adaptername); RegQueryValueEx(key2, "Name", 0, 0, adaptername, &len); + RegCloseKey(key2); + + if(device) { + if(!strcmp(device, adapterid)) { + found = true; + break; + } else + continue; + } + if(iface) { if(!strcmp(iface, adaptername)) { found = true; @@ -132,13 +132,18 @@ bool setup_device(void) } } + RegCloseKey(key); + if(!found) { logger(LOG_ERR, _("No Windows tap device found!")); return false; } - device = adapterid; - iface = adaptername; + if(!device) + device = xstrdup(adapterid); + + if(!iface) + iface = xstrdup(adaptername); snprintf(tapname, sizeof(tapname), USERMODEDEVICEDIR "%s" TAPSUFFIX, device); @@ -156,7 +161,7 @@ bool setup_device(void) handle = CreateFile(tapname, GENERIC_WRITE, FILE_SHARE_READ, 0, OPEN_EXISTING, FILE_ATTRIBUTE_SYSTEM , 0); if(handle == INVALID_HANDLE_VALUE) { - logger(LOG_ERR, _("Could not open CIPE tap device for writing!")); + logger(LOG_ERR, _("Could not open Windows tap device for writing!")); return false; } @@ -164,7 +169,7 @@ bool setup_device(void) /* Get MAC address from tap device */ - if(DeviceIoControl(device_fd, TAP_IOCTL_GET_MAC, mymac.x, sizeof(mymac.x), mymac.x, sizeof(mymac.x), &len, 0)) { + if(!DeviceIoControl(handle, TAP_IOCTL_GET_MAC, mymac.x, sizeof(mymac.x), mymac.x, sizeof(mymac.x), &len, 0)) { logger(LOG_ERR, _("Could not get MAC address from Windows tap device!")); return false; } @@ -187,12 +192,14 @@ bool setup_device(void) It passes everything it reads to the socket. */ char buf[MTU]; - int lenin; + long lenin; + + CloseHandle(handle); - handle = CreateFile(tapname, GENERIC_READ, FILE_SHARE_WRITE, 0, OPEN_EXISTING, FILE_ATTRIBUTE_SYSTEM , 0); + handle = CreateFile(tapname, GENERIC_READ, FILE_SHARE_WRITE, 0, OPEN_EXISTING, FILE_ATTRIBUTE_SYSTEM, 0); if(handle == INVALID_HANDLE_VALUE) { - logger(LOG_ERR, _("Could not open CIPE tap device for reading!")); + logger(LOG_ERR, _("Could not open Windows tap device for reading!")); buf[0] = 0; write(sp[1], buf, 1); exit(1); @@ -208,25 +215,22 @@ bool setup_device(void) /* Pass packets */ for(;;) { - ReadFile (handle, buf, MTU, &lenin, NULL); + ReadFile(handle, buf, MTU, &lenin, NULL); write(sp[1], buf, lenin); } } read(device_fd, &gelukt, 1); if(gelukt != 1) { - logger(LOG_DEBUG, "Tap reader failed!"); + logger(LOG_DEBUG, _("Tap reader failed!")); return false; } - if(!get_config_string(lookup_config(config_tree, "Interface"), &iface)) - iface = device; - device_info = _("Windows tap device"); logger(LOG_INFO, _("%s (%s) is a %s"), device, iface, device_info); - return false; + return true; } void close_device(void) @@ -264,7 +268,7 @@ bool read_packet(vpn_packet_t *packet) bool write_packet(vpn_packet_t *packet) { - int lenout; + long lenout; cp(); @@ -272,7 +276,7 @@ bool write_packet(vpn_packet_t *packet) packet->len, device_info); if(!WriteFile (handle, packet->data, packet->len, &lenout, NULL)) { - logger(LOG_ERR, "Error while writing to %s %s", device_info, device); + logger(LOG_ERR, _("Error while writing to %s %s"), device_info, device); return false; }