diff options
author | Adam Ierymenko <adam.ierymenko@zerotier.com> | 2013-08-27 11:15:14 -0400 |
---|---|---|
committer | Adam Ierymenko <adam.ierymenko@zerotier.com> | 2013-08-27 11:15:14 -0400 |
commit | b4be07149fe5b526d8fb97f17aafee1e931d9ddf (patch) | |
tree | 64b9c8b9c478838b6e14ca5342be5a6d5b418587 | |
parent | 335733f110e326ef9a501ad5227a5063436b8817 (diff) | |
download | infinitytier-b4be07149fe5b526d8fb97f17aafee1e931d9ddf.tar.gz infinitytier-b4be07149fe5b526d8fb97f17aafee1e931d9ddf.zip |
Tap now basically sorta works on Windows. Now have to figure out how to control DHCP behavior since we normally don't want that.
-rw-r--r-- | node/EthernetTap.cpp | 32 | ||||
-rw-r--r-- | node/UdpSocket.cpp | 3 |
2 files changed, 28 insertions, 7 deletions
diff --git a/node/EthernetTap.cpp b/node/EthernetTap.cpp index 8b171b4c..8c6e15e1 100644 --- a/node/EthernetTap.cpp +++ b/node/EthernetTap.cpp @@ -714,7 +714,7 @@ static inline std::pair<NET_LUID,NET_IFINDEX> _findAdapterByGuid(const GUID &gui for(ULONG i=0;i<ift->NumEntries;++i) { if (ift->Table[i].InterfaceGuid == guid) { std::pair<NET_LUID,NET_IFINDEX> tmp(ift->Table[i].InterfaceLuid,ift->Table[i].InterfaceIndex); - FreeMibTable(&ift); + FreeMibTable(ift); return tmp; } } @@ -751,10 +751,10 @@ EthernetTap::EthernetTap( throw std::runtime_error("MTU too large for Windows tap"); #ifdef _WIN64 - const char *devcon = "\\devcon64.exe"; + const char *devcon = "\\devcon64.exe"; #else - BOOL f64 = FALSE; - const char *devcon = ((IsWow64Process(GetCurrentProcess(),&f64) == TRUE) ? "\\devcon64.exe" : "\\devcon32.exe"); + BOOL f64 = FALSE; + const char *devcon = ((IsWow64Process(GetCurrentProcess(),&f64) == TRUE) ? "\\devcon64.exe" : "\\devcon32.exe"); #endif Mutex::Lock _l(_systemTapInitLock); // only init one tap at a time, process-wide @@ -961,6 +961,26 @@ EthernetTap::~EthernetTap() CloseHandle(_tapOvlRead.hEvent); CloseHandle(_tapOvlWrite.hEvent); CloseHandle(_injectSemaphore); + + // Disable network device on shutdown +#ifdef _WIN64 + const char *devcon = "\\devcon64.exe"; +#else + BOOL f64 = FALSE; + const char *devcon = ((IsWow64Process(GetCurrentProcess(),&f64) == TRUE) ? "\\devcon64.exe" : "\\devcon32.exe"); +#endif + { + STARTUPINFOA startupInfo; + startupInfo.cb = sizeof(startupInfo); + PROCESS_INFORMATION processInfo; + memset(&startupInfo,0,sizeof(STARTUPINFOA)); + memset(&processInfo,0,sizeof(PROCESS_INFORMATION)); + if (CreateProcessA(NULL,(LPSTR)(std::string("\"") + _r->homePath + devcon + "\" disable @" + _myDeviceInstanceIdPath).c_str(),NULL,NULL,FALSE,0,NULL,NULL,&startupInfo,&processInfo)) { + WaitForSingleObject(processInfo.hProcess,INFINITE); + CloseHandle(processInfo.hProcess); + CloseHandle(processInfo.hThread); + } + } } void EthernetTap::whack() @@ -1026,7 +1046,7 @@ bool EthernetTap::removeIP(const InetAddress &ip) } if (addr == ip) { DeleteUnicastIpAddressEntry(&(ipt->Table[i])); - FreeMibTable(&ipt); + FreeMibTable(ipt); Mutex::Lock _l(_ips_m); _ips.erase(ip); return true; @@ -1060,7 +1080,7 @@ std::set<InetAddress> EthernetTap::allIps() const } } } - FreeMibTable(&ipt); + FreeMibTable(ipt); } } catch ( ... ) {} diff --git a/node/UdpSocket.cpp b/node/UdpSocket.cpp index 24c130ca..848414f8 100644 --- a/node/UdpSocket.cpp +++ b/node/UdpSocket.cpp @@ -167,14 +167,15 @@ UdpSocket::UdpSocket( UdpSocket::~UdpSocket() { - int s = _sock; #ifdef __WINDOWS__ + SOCKET s = _sock; _sock = INVALID_SOCKET; if (s != INVALID_SOCKET) { ::shutdown(s,SD_BOTH); ::closesocket(s); } #else + int s = _sock; _sock = 0; if (s > 0) { ::shutdown(s,SHUT_RDWR); |