Author: cgutman Date: Sun Jan 15 19:46:14 2012 New Revision: 54980
URL: http://svn.reactos.org/svn/reactos?rev=54980&view=rev Log: [NETCFGX] - Notify the DHCP service when a static IP address is assigned to an adapter
Modified: branches/wlan-bringup/dll/win32/netcfgx/CMakeLists.txt branches/wlan-bringup/dll/win32/netcfgx/netcfgx.rbuild branches/wlan-bringup/dll/win32/netcfgx/precomp.h branches/wlan-bringup/dll/win32/netcfgx/tcpipconf_notify.c
Modified: branches/wlan-bringup/dll/win32/netcfgx/CMakeLists.txt URL: http://svn.reactos.org/svn/reactos/branches/wlan-bringup/dll/win32/netcfgx/C... ============================================================================== --- branches/wlan-bringup/dll/win32/netcfgx/CMakeLists.txt [iso-8859-1] (original) +++ branches/wlan-bringup/dll/win32/netcfgx/CMakeLists.txt [iso-8859-1] Sun Jan 15 19:46:14 2012 @@ -22,6 +22,6 @@ uuid wine)
-add_importlibs(netcfgx rpcrt4 setupapi advapi32 iphlpapi ole32 user32 comctl32 ws2_32 msvcrt kernel32 ntdll) +add_importlibs(netcfgx rpcrt4 setupapi advapi32 iphlpapi dhcpcsvc ole32 user32 comctl32 ws2_32 msvcrt kernel32 ntdll) add_pch(netcfgx precomp.h) add_cd_file(TARGET netcfgx DESTINATION reactos/system32 FOR all)
Modified: branches/wlan-bringup/dll/win32/netcfgx/netcfgx.rbuild URL: http://svn.reactos.org/svn/reactos/branches/wlan-bringup/dll/win32/netcfgx/n... ============================================================================== --- branches/wlan-bringup/dll/win32/netcfgx/netcfgx.rbuild [iso-8859-1] (original) +++ branches/wlan-bringup/dll/win32/netcfgx/netcfgx.rbuild [iso-8859-1] Sun Jan 15 19:46:14 2012 @@ -8,7 +8,7 @@ <library>advapi32</library> <library>uuid</library> <library>iphlpapi</library> - <library>iphlpapi</library> + <library>dhcpcsvc</library> <library>wine</library> <library>ole32</library> <library>user32</library>
Modified: branches/wlan-bringup/dll/win32/netcfgx/precomp.h URL: http://svn.reactos.org/svn/reactos/branches/wlan-bringup/dll/win32/netcfgx/p... ============================================================================== --- branches/wlan-bringup/dll/win32/netcfgx/precomp.h [iso-8859-1] (original) +++ branches/wlan-bringup/dll/win32/netcfgx/precomp.h [iso-8859-1] Sun Jan 15 19:46:14 2012 @@ -14,6 +14,8 @@ #include <setupapi.h> #include <stdio.h> #include <iphlpapi.h> +#include <dhcpcsdk.h> +#include <dhcpcapi.h> #include <olectl.h> #include <netcfgn.h> #include "resource.h"
Modified: branches/wlan-bringup/dll/win32/netcfgx/tcpipconf_notify.c URL: http://svn.reactos.org/svn/reactos/branches/wlan-bringup/dll/win32/netcfgx/t... ============================================================================== --- branches/wlan-bringup/dll/win32/netcfgx/tcpipconf_notify.c [iso-8859-1] (original) +++ branches/wlan-bringup/dll/win32/netcfgx/tcpipconf_notify.c [iso-8859-1] Sun Jan 15 19:46:14 2012 @@ -3117,6 +3117,7 @@ WCHAR szBuffer[200]; TcpipSettings * pCurrentConfig, *pOldConfig; ULONG NTEInstance; + DWORD DhcpApiVersion;
TcpipConfNotifyImpl * This = impl_from_INetCfgComponentControl(iface);
@@ -3197,39 +3198,74 @@ RegSetValueExW(hKey, L"DefaultGatewayMetric", 0, REG_MULTI_SZ, (LPBYTE)L"\0", 2 * sizeof(WCHAR)); if (!pOldConfig->DhcpEnabled) { + /* Delete this adapter's current IP address */ DeleteIPAddress(pOldConfig->Ip->NTEContext); - //FIXME - // start dhcp client service for the adapter + + /* Delete all default routes for this adapter */ + dwSize = 0; + if (GetIpForwardTable(NULL, &dwSize, FALSE) == ERROR_INSUFFICIENT_BUFFER) + { + DWORD Index; + PMIB_IPFORWARDTABLE pIpForwardTable = (PMIB_IPFORWARDTABLE)CoTaskMemAlloc(dwSize); + if (pIpForwardTable) + { + if (GetIpForwardTable(pIpForwardTable, &dwSize, FALSE) == NO_ERROR) + { + for (Index = 0; Index < pIpForwardTable->dwNumEntries; Index++) + { + if (pIpForwardTable->table[Index].dwForwardIfIndex == pOldConfig->Index && + pIpForwardTable->table[Index].dwForwardDest == 0) + { + DeleteIpForwardEntry(&pIpForwardTable->table[Index]); + } + } + } + CoTaskMemFree(pIpForwardTable); + } + } } } else { - if (!pOldConfig->DhcpEnabled) - { + /* Open the DHCP API if DHCP is enabled */ + if (pOldConfig->DhcpEnabled && DhcpCApiInitialize(&DhcpApiVersion) == NO_ERROR) + { + /* We have to tell DHCP about this */ + DhcpStaticRefreshParams(pCurrentConfig->Index, + htonl(pCurrentConfig->Ip->IpAddress), + htonl(pCurrentConfig->Ip->u.Subnetmask)); + + /* Close the API */ + DhcpCApiCleanup(); + } + else + { + /* Delete this adapter's current static IP address */ DeleteIPAddress(pOldConfig->Ip->NTEContext); - //TODO - //delete multiple ip addresses when required - } - - //TODO - // add multiple ip addresses when required - if (AddIPAddress(htonl(pCurrentConfig->Ip->IpAddress), htonl(pCurrentConfig->Ip->u.Subnetmask), pCurrentConfig->Index, &pCurrentConfig->Ip->NTEContext, &NTEInstance) == NO_ERROR) - { - pStr = CreateMultiSzString(pCurrentConfig->Ip, IPADDR, &dwSize, FALSE); - if(pStr) - { - RegSetValueExW(hKey, L"IPAddress", 0, REG_MULTI_SZ, (LPBYTE)pStr, dwSize); - CoTaskMemFree(pStr); - } - - pStr = CreateMultiSzString(pCurrentConfig->Ip, SUBMASK, &dwSize, FALSE); - if(pStr) - { - RegSetValueExW(hKey, L"SubnetMask", 0, REG_MULTI_SZ, (LPBYTE)pStr, dwSize); - CoTaskMemFree(pStr); - } - } - + + /* Add the static IP address via the standard IPHLPAPI function */ + AddIPAddress(htonl(pCurrentConfig->Ip->IpAddress), + htonl(pCurrentConfig->Ip->u.Subnetmask), + pCurrentConfig->Index, + &pCurrentConfig->Ip->NTEContext, + &NTEInstance); + } + + pStr = CreateMultiSzString(pCurrentConfig->Ip, IPADDR, &dwSize, FALSE); + if(pStr) + { + RegSetValueExW(hKey, L"IPAddress", 0, REG_MULTI_SZ, (LPBYTE)pStr, dwSize); + CoTaskMemFree(pStr); + } + + pStr = CreateMultiSzString(pCurrentConfig->Ip, SUBMASK, &dwSize, FALSE); + if(pStr) + { + RegSetValueExW(hKey, L"SubnetMask", 0, REG_MULTI_SZ, (LPBYTE)pStr, dwSize); + CoTaskMemFree(pStr); + } + + /* Delete all default routes for this adapter */ dwSize = 0; if (GetIpForwardTable(NULL, &dwSize, FALSE) == ERROR_INSUFFICIENT_BUFFER) {