mirror of
https://github.com/zerotier/ZeroTierOne.git
synced 2025-01-18 18:56:24 +00:00
Check if DNS servers need to be Applied on macOS
This commit is contained in:
parent
e8f7d5ef9e
commit
31ffe4403c
@ -39,18 +39,22 @@ void MacDNSHelper::setDNS(uint64_t nwid, const char *domain, const std::vector<I
|
||||
sprintf(buf, "State:/Network/Service/%.16llx/DNS", nwid);
|
||||
CFStringRef key = CFStringCreateWithCString(NULL, buf, kCFStringEncodingUTF8);
|
||||
CFArrayRef list = SCDynamicStoreCopyKeyList(ds, key);
|
||||
|
||||
CFIndex i = 0, j = CFArrayGetCount(list);
|
||||
bool ret = TRUE;
|
||||
if (j <= 0) {
|
||||
ret &= SCDynamicStoreAddValue(ds, key, dict);
|
||||
} else {
|
||||
ret &= SCDynamicStoreSetValue(ds, (CFStringRef)CFArrayGetValueAtIndex(list, i), dict);
|
||||
}
|
||||
if (!ret) {
|
||||
fprintf(stderr, "Error writing DNS configuration\n");
|
||||
|
||||
CFPropertyListRef oldDNSServers = SCDynamicStoreCopyValue(ds, (CFStringRef)CFArrayGetValueAtIndex(list, i));
|
||||
if (!CFEqual(oldDNSServers,dict)) {
|
||||
bool ret = TRUE;
|
||||
if (j <= 0) {
|
||||
ret &= SCDynamicStoreAddValue(ds, key, dict);
|
||||
} else {
|
||||
ret &= SCDynamicStoreSetValue(ds, (CFStringRef)CFArrayGetValueAtIndex(list, i), dict);
|
||||
}
|
||||
if (!ret) {
|
||||
fprintf(stderr, "Error writing DNS configuration\n");
|
||||
}
|
||||
}
|
||||
|
||||
CFRelease(oldDNSServers);
|
||||
CFRelease(list);
|
||||
CFRelease(key);
|
||||
CFRelease(dict);
|
||||
|
Loading…
Reference in New Issue
Block a user