Windows DNS

This commit is contained in:
Grant Limberg 2020-08-11 18:55:42 -07:00
commit d9c4e644de
5 changed files with 427 additions and 6 deletions

View file

@ -44,6 +44,7 @@
#include "OSUtils.hpp"
#include "..\windows\TapDriver6\tap-windows.h"
#include "WinDNSHelper.hpp"
#include <netcon.h>
@ -473,6 +474,29 @@ WindowsEthernetTap::WindowsEthernetTap(
char data[1024];
char tag[24];
// Initialize COM
HRESULT hres = CoInitializeEx(0, COINIT_MULTITHREADED);
if (FAILED(hres)) {
throw std::runtime_error("WinEthernetTap: COM initialization failed");
}
hres = CoInitializeSecurity(
NULL,
-1,
NULL,
NULL,
RPC_C_AUTHN_LEVEL_DEFAULT,
RPC_C_IMP_LEVEL_IMPERSONATE,
NULL,
EOAC_NONE,
NULL
);
if (FAILED(hres)) {
CoUninitialize();
throw std::runtime_error("WinEthernetTap: Failed to initialize security");
}
// We "tag" registry entries with the network ID to identify persistent devices
OSUtils::ztsnprintf(tag,sizeof(tag),"%.16llx",(unsigned long long)nwid);
@ -646,6 +670,8 @@ WindowsEthernetTap::WindowsEthernetTap(
WindowsEthernetTap::~WindowsEthernetTap()
{
WinDNSHelper::removeDNS(_nwid);
CoUninitialize();
_run = false;
ReleaseSemaphore(_injectSemaphore,1,NULL);
Thread::join(_thread);
@ -1292,7 +1318,7 @@ void WindowsEthernetTap::_syncIps()
void WindowsEthernetTap::setDns(const char* domain, const std::vector<InetAddress>& servers)
{
WinDNSHelper::setDNS(_nwid, domain, servers);
}
} // namespace ZeroTier