summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAdam Ierymenko <adam.ierymenko@zerotier.com>2013-08-21 10:18:05 -0400
committerAdam Ierymenko <adam.ierymenko@zerotier.com>2013-08-21 10:18:05 -0400
commitedad580c32abd4d25751460b61dcc8c12a2caf1f (patch)
treead42d0ba9b68fcb95364dc78a081d625527de212
parent2536352e5d166719acc87535ed17a805e7bd3c26 (diff)
downloadinfinitytier-edad580c32abd4d25751460b61dcc8c12a2caf1f.tar.gz
infinitytier-edad580c32abd4d25751460b61dcc8c12a2caf1f.zip
Some work on Windows tap.
-rw-r--r--node/EthernetTap.cpp30
-rw-r--r--vsprojects/SelfTest/SelfTest.vcxproj2
2 files changed, 31 insertions, 1 deletions
diff --git a/node/EthernetTap.cpp b/node/EthernetTap.cpp
index 1cc15c14..dd555576 100644
--- a/node/EthernetTap.cpp
+++ b/node/EthernetTap.cpp
@@ -679,12 +679,17 @@ void EthernetTap::threadMain()
#include <WinSock2.h>
#include <Windows.h>
+#include <iphlpapi.h>
#include <ws2ipdef.h>
+#include <WS2tcpip.h>
+#include <tchar.h>
+#include <winreg.h>
namespace ZeroTier {
EthernetTap::EthernetTap(
const RuntimeEnvironment *renv,
+ const char *tag,
const MAC &mac,
unsigned int mtu,
void (*handler)(void *,const MAC &,const MAC &,unsigned int,const Buffer<4096> &),
@@ -696,6 +701,31 @@ EthernetTap::EthernetTap(
_handler(handler),
_arg(arg)
{
+ HKEY nwAdapters;
+ if (RegOpenKeyExA(HKEY_LOCAL_MACHINE,"SYSTEM\CurrentControlSet\Control\Class\{4D36E972-E325-11CE-BFC1-08002BE10318}",0,KEY_ALL_ACCESS,&nwAdapters) != ERROR_SUCCESS)
+ throw std::runtime_error("unable to open registry key for network adapter enumeration");
+
+ for(DWORD subkeyIndex=0;subkeyIndex!=-1;) {
+ char subkeyName[1024];
+ char subkeyClass[1024];
+ DWORD subkeyNameLen = sizeof(subkeyName);
+ DWORD subkeyClassLen = sizeof(subkeyClass);
+ FILETIME lastWriteTime;
+ switch (RegEnumKeyExA(nwAdapters,subkeyIndex++,subkeyName,&subkeyNameLen,(DWORD *)0,subkeyClass,&subkeyClassLen,&lastWriteTime)) {
+ case ERROR_NO_MORE_ITEMS: subkeyIndex = -1; break;
+ case ERROR_SUCCESS: {
+ DWORD type = 0;
+ char data[1024];
+ DWORD dataLen = sizeof(data);
+ if (RegGetValueA(nwAdapters,subkeyName,"DeviceInstanceID",RRF_RT_ANY,&type,(PVOID)data,&dataLen) == ERROR_SUCCESS) {
+ data[dataLen] = '\0';
+ printf("%s: %s\r\n",subkeyName,data);
+ }
+ } break;
+ }
+ }
+
+ RegCloseKey(nwAdapters);
}
EthernetTap::~EthernetTap()
diff --git a/vsprojects/SelfTest/SelfTest.vcxproj b/vsprojects/SelfTest/SelfTest.vcxproj
index 52935a95..f974b926 100644
--- a/vsprojects/SelfTest/SelfTest.vcxproj
+++ b/vsprojects/SelfTest/SelfTest.vcxproj
@@ -76,7 +76,7 @@
<GenerateDebugInformation>true</GenerateDebugInformation>
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<OptimizeReferences>true</OptimizeReferences>
- <AdditionalDependencies>wsock32.lib;ws2_32.lib;$(SolutionDir)\ext\bin\libcrypto\win32-vs2012\libeay32.lib;%(AdditionalDependencies)</AdditionalDependencies>
+ <AdditionalDependencies>wsock32.lib;ws2_32.lib;iphlpapi.lib;$(SolutionDir)\ext\bin\libcrypto\win32-vs2012\libeay32.lib;%(AdditionalDependencies)</AdditionalDependencies>
<ImageHasSafeExceptionHandlers>false</ImageHasSafeExceptionHandlers>
</Link>
</ItemDefinitionGroup>