--------------------- PatchSet 10262 Date: 2007/12/16 17:39:22 Author: serassio Branch: nt Tag: (none) Log: Handle notification of IP address changes for dial-up connections Members: src/win32.c:1.7.8.19->1.7.8.20 Index: squid/src/win32.c =================================================================== RCS file: /cvsroot/squid-sf//squid/src/win32.c,v retrieving revision 1.7.8.19 retrieving revision 1.7.8.20 diff -u -r1.7.8.19 -r1.7.8.20 --- squid/src/win32.c 13 Aug 2007 08:03:08 -0000 1.7.8.19 +++ squid/src/win32.c 16 Dec 2007 17:39:22 -0000 1.7.8.20 @@ -91,6 +91,9 @@ #else #define CHANGESERVICECONFIG2 "ChangeServiceConfig2A" #endif +#undef NotifyAddrChange +typedef DWORD(WINAPI * PFNotifyAddrChange)(OUT PHANDLE, IN LPOVERLAPPED); +#define NOTIFYADDRCHANGE "NotifyAddrChange" #if USE_WIN32_SERVICE static SC_ACTION Squid_SCAction[] = { @@ -380,6 +383,42 @@ _exit(0); } +void WIN32_IpAddrChangeMonitor() +{ + DWORD Result; + HMODULE IPHLPAPIHandle; + PFNotifyAddrChange NotifyAddrChange; + + IPHLPAPIHandle = GetModuleHandle("IPHLPAPI"); + NotifyAddrChange = (PFNotifyAddrChange) GetProcAddress(IPHLPAPIHandle, NOTIFYADDRCHANGE); + + while ( TRUE ) { + Result = NotifyAddrChange(NULL,NULL); + if (Result != NO_ERROR) + { + debug(1, 1) ("NotifyAddrChange error %ld\n", Result); + break; + } + debug(1, 1) ("Notification of IP address change received, reconfiguring Squid ...\n"); + reconfigure(SIGHUP); + } +} + +DWORD WIN32_IpAddrChangeMonitorInit() +{ + DWORD status = ERROR_SUCCESS; + HANDLE thread; + ULONG threadID = 0; + + thread = CreateThread(NULL, 0, (PTHREAD_START_ROUTINE)WIN32_IpAddrChangeMonitor, + NULL, 0, &threadID); + if (thread == NULL) { + status = GetLastError(); + } + CloseHandle(thread); + return status; +} + int WIN32_Subsystem_Init(int *argc, char ***argv) { @@ -456,6 +495,10 @@ #ifdef _SQUID_MSWIN_ if (Win32SockInit() < 0) return 1; + if (WIN32_OS_version > _WIN_OS_WINNT) { + if (WIN32_IpAddrChangeMonitorInit() != ERROR_SUCCESS) + return 1; + } #endif return 0; }