From 3ee9f47ac1a8a7fd998570adae83de146cb0d4e9 Mon Sep 17 00:00:00 2001 From: brain <brain@e03df62e-2008-0410-955e-edbf42e46eb7> Date: Tue, 22 May 2007 20:36:53 +0000 Subject: 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 --- win/inspircd_win32wrapper.cpp | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) (limited to 'win/inspircd_win32wrapper.cpp') 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; } + -- cgit v1.2.3