diff --git a/dll/win32/netcfgx/CMakeLists.txt b/dll/win32/netcfgx/CMakeLists.txt index 835c3c36734..2811d36dda6 100644 --- a/dll/win32/netcfgx/CMakeLists.txt +++ b/dll/win32/netcfgx/CMakeLists.txt @@ -22,6 +22,6 @@ target_link_libraries(netcfgx 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) diff --git a/dll/win32/netcfgx/netcfgx.rbuild b/dll/win32/netcfgx/netcfgx.rbuild index 2d220ae2e62..3198641b0d0 100644 --- a/dll/win32/netcfgx/netcfgx.rbuild +++ b/dll/win32/netcfgx/netcfgx.rbuild @@ -8,7 +8,7 @@ advapi32 uuid iphlpapi - iphlpapi + dhcpcsvc wine ole32 user32 diff --git a/dll/win32/netcfgx/precomp.h b/dll/win32/netcfgx/precomp.h index a6a6021b0a6..f64647be1e6 100644 --- a/dll/win32/netcfgx/precomp.h +++ b/dll/win32/netcfgx/precomp.h @@ -14,6 +14,8 @@ #include #include #include +#include +#include #include #include #include "resource.h" diff --git a/dll/win32/netcfgx/tcpipconf_notify.c b/dll/win32/netcfgx/tcpipconf_notify.c index cb521e8607e..cf4966d1b00 100644 --- a/dll/win32/netcfgx/tcpipconf_notify.c +++ b/dll/win32/netcfgx/tcpipconf_notify.c @@ -3117,6 +3117,7 @@ INetCfgComponentControl_fnApplyRegistryChanges( WCHAR szBuffer[200]; TcpipSettings * pCurrentConfig, *pOldConfig; ULONG NTEInstance; + DWORD DhcpApiVersion; TcpipConfNotifyImpl * This = impl_from_INetCfgComponentControl(iface); @@ -3197,39 +3198,74 @@ INetCfgComponentControl_fnApplyRegistryChanges( 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) + /* 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) { - 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); - } + 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) {