}\r
\r
\r
+/* These three functions were created from looking at how ares does it\r
+ * (...and they look far tidier in C++)\r
+ */\r
+\r
+/* Get active nameserver */\r
bool GetNameServer(HKEY regkey, const char *key, char* &output)\r
{\r
- /* Test for the size we need */\r
DWORD size = 0;\r
DWORD result = RegQueryValueEx(regkey, key, 0, NULL, NULL, &size);\r
-\r
if (((result != ERROR_SUCCESS) && (result != ERROR_MORE_DATA)) || (!size))\r
return false;\r
\r
return true;\r
}\r
\r
+/* Check a network interface for its nameserver */\r
bool GetInterface(HKEY regkey, const char *key, char* &output)\r
{\r
char buf[39];\r
HKEY top, key;\r
char* dns = NULL;\r
\r
+ /* Lets see if the correct registry hive and tree exist */\r
if (RegOpenKeyEx(HKEY_LOCAL_MACHINE, "System\\CurrentControlSet\\Services\\Tcpip\\Parameters", 0, KEY_READ, &top) == ERROR_SUCCESS)\r
{\r
+ /* If they do, attempt to get the nameserver name */\r
RegOpenKeyEx(top, "Interfaces", 0, KEY_QUERY_VALUE|KEY_ENUMERATE_SUB_KEYS, &key);\r
if ((GetNameServer(top, "NameServer", dns)) || (GetNameServer(top, "DhcpNameServer", dns))\r
|| (GetInterface(key, "NameServer", dns)) || (GetInterface(key, "DhcpNameServer", dns)))\r
}\r
return returnval;\r
}\r
+\r