-/* IPC Messages */
-#define IPC_MESSAGE_REHASH 1
-#define IPC_MESSAGE_DIE 2
-#define IPC_MESSAGE_RESTART 3
-
-IPC::IPC(InspIRCd* Srv) : Instance(Srv)
-{
- static DWORD buflen = 1024;
- static const char * pipename = "\\\\.\\mailslot\\Inspircd";
- hIPCPipe = CreateMailslot(pipename, buflen, 0, 0);
- if (hIPCPipe == INVALID_HANDLE_VALUE)
- printf("IPC Pipe could not be created. Are you sure you didn't start InspIRCd twice?\n");
-}
-
-void IPC::Check()
-{
- if (hIPCPipe == INVALID_HANDLE_VALUE)
- return;
-
- DWORD bytes;
- DWORD action;
-
- BOOL res = ReadFile(hIPCPipe, &action, sizeof(DWORD), &bytes, 0);
- if (!res)
- {
- if (GetLastError() != ERROR_SEM_TIMEOUT)
- Instance->Log(DEFAULT, "IPC Pipe Error %u: %s", GetLastError(), dlerror());
- return;
- }
-
- switch (action)
- {
- case IPC_MESSAGE_REHASH:
- Instance->Rehash();
- break;
-
- case IPC_MESSAGE_DIE:
- Instance->Exit(0);
- break;
-
- case IPC_MESSAGE_RESTART:
- Instance->Restart("IPC_MESSAGE_RESTART received by mailslot.");
- break;
- }
-}
-
-IPC::~IPC()
-{
- CloseHandle(hIPCPipe);
-}
-
-
-/* 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)
-{
- DWORD size = 0;
- DWORD result = RegQueryValueEx(regkey, key, 0, NULL, NULL, &size);
- if (((result != ERROR_SUCCESS) && (result != ERROR_MORE_DATA)) || (!size))
- return false;
-
- output = new char[size+1];
-
- if ((RegQueryValueEx(regkey, key, 0, NULL, (LPBYTE)output, &size) != ERROR_SUCCESS) || (!*output))
- {
- delete output;
- return false;
- }
- return true;
-}
-
-/* Check a network interface for its nameserver */
-bool GetInterface(HKEY regkey, const char *key, char* &output)
-{
- char buf[39];
- DWORD size = 39;
- int idx = 0;
- HKEY top;
-
- while (RegEnumKeyEx(regkey, idx++, buf, &size, 0, NULL, NULL, NULL) != ERROR_NO_MORE_ITEMS)
- {
- size = 39;
- if (RegOpenKeyEx(regkey, buf, 0, KEY_QUERY_VALUE, &top) != ERROR_SUCCESS)
- continue;
- int rc = GetNameServer(top, key, output);
- RegCloseKey(top);
- if (rc)
- return true;
- }
- return false;
-}
-
-
-std::string FindNameServerWin()
-{
- std::string returnval = "127.0.0.1";
- 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)))
- {
- if (dns)
- {
- returnval = dns;
- delete dns;
- }
- }
- RegCloseKey(key);
- RegCloseKey(top);
- }
- return returnval;
-}
-
-
-void ClearConsole()