summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorDavid Lönnhager <david.l@mullvad.net>2019-11-29 13:38:05 +0100
committerDavid Lönnhager <david.l@mullvad.net>2019-12-03 09:17:30 +0100
commit726aec61b039aefa129dcc0c2c261c299f20bdc6 (patch)
tree3b57cc5143bfdb6fc563e08a73d51b852db21c76
parentba20a7fa733fa02010b62582b220f716444abb50 (diff)
downloadmullvadvpn-726aec61b039aefa129dcc0c2c261c299f20bdc6.tar.xz
mullvadvpn-726aec61b039aefa129dcc0c2c261c299f20bdc6.zip
Workaround for net adapter alias issue on Windows 8
-rw-r--r--windows/windns/src/windns/windns.cpp23
-rw-r--r--windows/windns/src/windns/windns.vcxproj2
-rw-r--r--windows/windns/src/windns/windns.vcxproj.filters2
-rw-r--r--windows/winnet/src/winnet/interfaceutils.cpp24
-rw-r--r--windows/winnet/src/winnet/winnet.vcxproj2
5 files changed, 51 insertions, 2 deletions
diff --git a/windows/windns/src/windns/windns.cpp b/windows/windns/src/windns/windns.cpp
index eae828973c..1687586c7b 100644
--- a/windows/windns/src/windns/windns.cpp
+++ b/windows/windns/src/windns/windns.cpp
@@ -4,6 +4,7 @@
#include "windns.h"
#include "confineoperation.h"
#include "netsh.h"
+#include "ncicontext.h"
#include "logsink.h"
#include <memory>
#include <vector>
@@ -96,8 +97,30 @@ AdapterDnsAddresses GetAdapterDnsAddresses(const std::wstring &adapterAlias)
const IP_ADAPTER_ADDRESSES *adapter;
+ NciContext nci;
+
while (nullptr != (adapter = adapters.next()))
{
+ std::wstring name;
+ IID guidObj = { 0 };
+
+ auto guid = std::string(adapter->AdapterName);
+ auto wguid = std::wstring(guid.begin(), guid.end());
+
+ if (S_OK != IIDFromString(&wguid[0], &guidObj))
+ {
+ throw std::runtime_error("IIDFromString() failed");
+ }
+
+ try
+ {
+ name = nci.getConnectionName(guidObj);
+ }
+ catch (...)
+ {
+ continue;
+ }
+
if (0 != _wcsicmp(adapter->FriendlyName, adapterAlias.c_str()))
{
continue;
diff --git a/windows/windns/src/windns/windns.vcxproj b/windows/windns/src/windns/windns.vcxproj
index b2b68a999f..308cfb1aea 100644
--- a/windows/windns/src/windns/windns.vcxproj
+++ b/windows/windns/src/windns/windns.vcxproj
@@ -178,6 +178,7 @@
<ClInclude Include="confineoperation.h" />
<ClInclude Include="logsink.h" />
<ClInclude Include="ilogsink.h" />
+ <ClInclude Include="ncicontext.h" />
<ClInclude Include="netsh.h" />
<ClInclude Include="stdafx.h" />
<ClInclude Include="targetver.h" />
@@ -187,6 +188,7 @@
<ClCompile Include="confineoperation.cpp" />
<ClCompile Include="dllmain.cpp" />
<ClCompile Include="logsink.cpp" />
+ <ClCompile Include="ncicontext.cpp" />
<ClCompile Include="netsh.cpp" />
<ClCompile Include="stdafx.cpp">
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">Create</PrecompiledHeader>
diff --git a/windows/windns/src/windns/windns.vcxproj.filters b/windows/windns/src/windns/windns.vcxproj.filters
index e71bf3e814..d551081fe0 100644
--- a/windows/windns/src/windns/windns.vcxproj.filters
+++ b/windows/windns/src/windns/windns.vcxproj.filters
@@ -8,6 +8,7 @@
<ClInclude Include="confineoperation.h" />
<ClInclude Include="ilogsink.h" />
<ClInclude Include="logsink.h" />
+ <ClInclude Include="ncicontext.h" />
</ItemGroup>
<ItemGroup>
<ClCompile Include="dllmain.cpp" />
@@ -16,6 +17,7 @@
<ClCompile Include="netsh.cpp" />
<ClCompile Include="confineoperation.cpp" />
<ClCompile Include="logsink.cpp" />
+ <ClCompile Include="ncicontext.cpp" />
</ItemGroup>
<ItemGroup>
<ResourceCompile Include="windns.rc" />
diff --git a/windows/winnet/src/winnet/interfaceutils.cpp b/windows/winnet/src/winnet/interfaceutils.cpp
index 202d9d0724..e64fbb376e 100644
--- a/windows/winnet/src/winnet/interfaceutils.cpp
+++ b/windows/winnet/src/winnet/interfaceutils.cpp
@@ -1,5 +1,6 @@
#include "stdafx.h"
#include "interfaceutils.h"
+#include "ncicontext.h"
#include "libcommon/error.h"
#include "libcommon/string.h"
#include <cstdint>
@@ -28,10 +29,29 @@ std::set<InterfaceUtils::NetworkAdapter> InterfaceUtils::GetAllAdapters()
std::set<NetworkAdapter> adapters;
+ NciContext nci;
+
for (auto it = (PIP_ADAPTER_ADDRESSES)&buffer[0]; nullptr != it; it = it->Next)
{
- adapters.emplace(NetworkAdapter(common::string::ToWide(it->AdapterName),
- it->Description, it->FriendlyName));
+ auto guid = std::string(it->AdapterName);
+ auto wguid = std::wstring(guid.begin(), guid.end());
+
+ IID guidObj = { 0 };
+ if (S_OK != IIDFromString(&wguid[0], &guidObj))
+ {
+ throw std::runtime_error("IIDFromString() failed");
+ }
+
+ try
+ {
+ std::wstring name = nci.getConnectionName(guidObj);
+
+ adapters.emplace(NetworkAdapter(common::string::ToWide(it->AdapterName),
+ it->Description, /*it->FriendlyName*/ name));
+ }
+ catch (...)
+ {
+ }
}
return adapters;
diff --git a/windows/winnet/src/winnet/winnet.vcxproj b/windows/winnet/src/winnet/winnet.vcxproj
index def37bc67d..5943ca53c8 100644
--- a/windows/winnet/src/winnet/winnet.vcxproj
+++ b/windows/winnet/src/winnet/winnet.vcxproj
@@ -27,6 +27,7 @@
</ProjectConfiguration>
</ItemGroup>
<ItemGroup>
+ <ClCompile Include="ncicontext.cpp" />
<ClCompile Include="networkadaptermonitor.cpp" />
<ClCompile Include="dllmain.cpp" />
<ClCompile Include="InterfacePair.cpp" />
@@ -41,6 +42,7 @@
<ClCompile Include="winnet.cpp" />
</ItemGroup>
<ItemGroup>
+ <ClInclude Include="ncicontext.h" />
<ClInclude Include="networkadaptermonitor.h" />
<ClInclude Include="InterfacePair.h" />
<ClInclude Include="interfaceutils.h" />