summaryrefslogtreecommitdiff
path: root/win/inspircd_win32wrapper.cpp
diff options
context:
space:
mode:
authorbrain <brain@e03df62e-2008-0410-955e-edbf42e46eb7>2007-05-22 20:36:53 +0000
committerbrain <brain@e03df62e-2008-0410-955e-edbf42e46eb7>2007-05-22 20:36:53 +0000
commit3ee9f47ac1a8a7fd998570adae83de146cb0d4e9 (patch)
treef72863b8b630734982796c097316fd824f8a3e33 /win/inspircd_win32wrapper.cpp
parente8aed79a4b1dc4487fe6f45f6976661218aaef11 (diff)
Comment on how we came up with this code, and comment it
git-svn-id: http://svn.inspircd.org/repository/trunk/inspircd@7116 e03df62e-2008-0410-955e-edbf42e46eb7
Diffstat (limited to 'win/inspircd_win32wrapper.cpp')
-rw-r--r--win/inspircd_win32wrapper.cpp11
1 files changed, 9 insertions, 2 deletions
diff --git a/win/inspircd_win32wrapper.cpp b/win/inspircd_win32wrapper.cpp
index dde2415aa..1cdd46444 100644
--- a/win/inspircd_win32wrapper.cpp
+++ b/win/inspircd_win32wrapper.cpp
@@ -368,12 +368,15 @@ void CloseIPC()
}
+/* These three functions were created from looking at how ares does it
+ * (...and they look far tidier in C++)
+ */
+
+/* Get active nameserver */
bool GetNameServer(HKEY regkey, const char *key, char* &output)
{
- /* Test for the size we need */
DWORD size = 0;
DWORD result = RegQueryValueEx(regkey, key, 0, NULL, NULL, &size);
-
if (((result != ERROR_SUCCESS) && (result != ERROR_MORE_DATA)) || (!size))
return false;
@@ -387,6 +390,7 @@ bool GetNameServer(HKEY regkey, const char *key, char* &output)
return true;
}
+/* Check a network interface for its nameserver */
bool GetInterface(HKEY regkey, const char *key, char* &output)
{
char buf[39];
@@ -414,8 +418,10 @@ std::string FindNameServerWin()
HKEY top, key;
char* dns = NULL;
+ /* Lets see if the correct registry hive and tree exist */
if (RegOpenKeyEx(HKEY_LOCAL_MACHINE, "System\\CurrentControlSet\\Services\\Tcpip\\Parameters", 0, KEY_READ, &top) == ERROR_SUCCESS)
{
+ /* If they do, attempt to get the nameserver name */
RegOpenKeyEx(top, "Interfaces", 0, KEY_QUERY_VALUE|KEY_ENUMERATE_SUB_KEYS, &key);
if ((GetNameServer(top, "NameServer", dns)) || (GetNameServer(top, "DhcpNameServer", dns))
|| (GetInterface(key, "NameServer", dns)) || (GetInterface(key, "DhcpNameServer", dns)))
@@ -431,3 +437,4 @@ std::string FindNameServerWin()
}
return returnval;
}
+