summaryrefslogtreecommitdiff
path: root/win
diff options
context:
space:
mode:
authorbrain <brain@e03df62e-2008-0410-955e-edbf42e46eb7>2007-05-22 20:03:33 +0000
committerbrain <brain@e03df62e-2008-0410-955e-edbf42e46eb7>2007-05-22 20:03:33 +0000
commit428aa503684e0f3d79730a1c7336db734846ffb6 (patch)
treea05d6eefe8069c55500680a8325ac5961282adb8 /win
parent75f0cba571dca97f181835d3645c3d42dd5daf2d (diff)
Code to find nameservers in the windows registry - largely untested
git-svn-id: http://svn.inspircd.org/repository/trunk/inspircd@7113 e03df62e-2008-0410-955e-edbf42e46eb7
Diffstat (limited to 'win')
-rw-r--r--win/inspircd_win32wrapper.cpp68
-rw-r--r--win/inspircd_win32wrapper.h4
2 files changed, 72 insertions, 0 deletions
diff --git a/win/inspircd_win32wrapper.cpp b/win/inspircd_win32wrapper.cpp
index ece823a4d..27cd15d0d 100644
--- a/win/inspircd_win32wrapper.cpp
+++ b/win/inspircd_win32wrapper.cpp
@@ -9,6 +9,7 @@ using namespace std;
#define INADDR_NONE 0xffffffff
#endif
+
HANDLE hIPCPipe;
int inet_aton(const char *cp, struct in_addr *addr)
@@ -366,3 +367,70 @@ void CloseIPC()
CloseHandle(hIPCPipe);
}
+
+bool GetNameServer(HKEY hKey, const char *subkey, char* &obuf)
+{
+ /* Test for the size we need */
+ DWORD size = 0;
+ DWORD result;
+
+ result = RegQueryValueEx(hKey, subkey, 0, NULL, NULL, &size);
+ if (((result != ERROR_SUCCESS) && (result != ERROR_MORE_DATA)) || (!size))
+ return false;
+
+ obuf = new char[size+1];
+
+ if ((RegQueryValueEx(hKey, subkey, 0, NULL, (LPBYTE)obuf, &size) != ERROR_SUCCESS) || (!*obuf))
+ {
+ delete obuf;
+ return false;
+ }
+ return true;
+}
+
+bool GetInterface(HKEY hKey, const char *subkey, char* &obuf)
+{
+ char buf[39];
+ DWORD size = 39;
+ int idx = 0;
+ HKEY hVal;
+
+ while (RegEnumKeyEx(hKey, idx++, buf, &size, 0, NULL, NULL, NULL) != ERROR_NO_MORE_ITEMS)
+ {
+ int rc;
+ size = 39;
+ if (RegOpenKeyEx(hKey, buf, 0, KEY_QUERY_VALUE, &hVal) != ERROR_SUCCESS)
+ continue;
+ rc = GetNameServer(hVal, subkey, obuf);
+ RegCloseKey(hVal);
+ if (rc)
+ return true;
+ }
+ return false;
+}
+
+
+std::string FindNameServerWin()
+{
+ std::string returnval;
+ HKEY mykey;
+ HKEY subkey;
+ char* dns = NULL;
+
+ if (RegOpenKeyEx(HKEY_LOCAL_MACHINE, "System\\CurrentControlSet\\Services\\Tcpip\\Parameters", 0, KEY_READ, &mykey) == ERROR_SUCCESS)
+ {
+ RegOpenKeyEx(mykey, "Interfaces", 0, KEY_QUERY_VALUE|KEY_ENUMERATE_SUB_KEYS, &subkey);
+ if ((GetNameServer(mykey, "NameServer", dns)) || (GetNameServer(mykey, "DhcpNameServer", dns))
+ || (GetInterface(subkey, "NameServer", dns)) || (GetInterface(subkey, "DhcpNameServer", dns)))
+ {
+ if (dns)
+ {
+ returnval = dns;
+ delete dns;
+ }
+ }
+ RegCloseKey(subkey);
+ RegCloseKey(mykey);
+ }
+ return returnval;
+}
diff --git a/win/inspircd_win32wrapper.h b/win/inspircd_win32wrapper.h
index f8506c97b..dc2fbb705 100644
--- a/win/inspircd_win32wrapper.h
+++ b/win/inspircd_win32wrapper.h
@@ -42,6 +42,8 @@
#define _CRT_SECURE_NO_DEPRECATE
#define _SCL_SECURE_NO_DEPRECATE
+#include <string>
+
/* Say we're building on windows 2000. Anyone running something older than this
* reeeeeeeally needs to upgrade! */
@@ -168,5 +170,7 @@ void InitIPC();
void CheckIPC(InspIRCd * Instance);
void CloseIPC();
+std::string FindNameServerWin();
+
#endif