mirror of
https://github.com/reactos/reactos.git
synced 2025-06-09 20:11:14 +00:00
Prepare front-end for saving settings
svn path=/trunk/; revision=20758
This commit is contained in:
parent
29f2266458
commit
d0ab58d96c
5 changed files with 383 additions and 216 deletions
|
@ -60,22 +60,22 @@ CAPTION "General"
|
||||||
FONT 8, "MS Shell Dlg"
|
FONT 8, "MS Shell Dlg"
|
||||||
BEGIN
|
BEGIN
|
||||||
LTEXT "You can get IP settings assigned automatically if your network supports this capability. Otherwise, you need to ask your network administrator for the appropriate IP settings.", -1, 9, 9, 228, 27
|
LTEXT "You can get IP settings assigned automatically if your network supports this capability. Otherwise, you need to ask your network administrator for the appropriate IP settings.", -1, 9, 9, 228, 27
|
||||||
CONTROL "Obtain the IP address automatically", IDC_USEDHCP, "BUTTON", BS_AUTORADIOBUTTON | WS_GROUP, 14, 43, 210, 12
|
CONTROL "Obtain the IP address automatically", IDC_USEDHCP, "BUTTON", BS_AUTORADIOBUTTON | WS_GROUP | WS_TABSTOP, 14, 43, 210, 12
|
||||||
GROUPBOX "", -1, 9, 61, 228, 70, BS_GROUPBOX
|
GROUPBOX "", -1, 9, 61, 228, 70, BS_GROUPBOX
|
||||||
CONTROL "&Use the following IP address:", IDC_NODHCP, "BUTTON", BS_AUTORADIOBUTTON, 14, 59, 105, 12
|
CONTROL "&Use the following IP address:", IDC_NODHCP, "BUTTON", BS_AUTORADIOBUTTON, 14, 59, 105, 12
|
||||||
LTEXT "IP address:", -1, 14, 75, 135, 8
|
LTEXT "IP address:", -1, 14, 75, 135, 8
|
||||||
CONTROL "",IDC_IPADDR,"SysIPAddress32",0,150,75-2,80,12
|
CONTROL "",IDC_IPADDR,"SysIPAddress32",WS_TABSTOP,150,75-2,80,12
|
||||||
LTEXT "Subnet mask:", -1, 14, 90, 135, 8
|
LTEXT "Subnet mask:", -1, 14, 90, 135, 8
|
||||||
CONTROL "",IDC_SUBNETMASK,"SysIPAddress32",0,150,90-2,80,12
|
CONTROL "",IDC_SUBNETMASK,"SysIPAddress32",WS_TABSTOP,150,90-2,80,12
|
||||||
LTEXT "Default gateway:", -1, 14, 105, 135, 8
|
LTEXT "Default gateway:", -1, 14, 105, 135, 8
|
||||||
CONTROL "",IDC_DEFGATEWAY,"SysIPAddress32",0,150,105-2,80,12
|
CONTROL "",IDC_DEFGATEWAY,"SysIPAddress32",WS_TABSTOP,150,105-2,80,12
|
||||||
CONTROL "Obtain the DNS server address automatically", IDC_AUTODNS, "BUTTON", BS_AUTORADIOBUTTON | WS_GROUP, 14, 139, 210, 12
|
CONTROL "Obtain the DNS server address automatically", IDC_AUTODNS, "BUTTON", BS_AUTORADIOBUTTON | WS_GROUP | WS_TABSTOP, 14, 139, 210, 12
|
||||||
GROUPBOX "", -1, 9, 157, 228, 47, BS_GROUPBOX
|
GROUPBOX "", -1, 9, 157, 228, 47, BS_GROUPBOX
|
||||||
CONTROL "&Use the following DNS server addresses", IDC_FIXEDDNS, "BUTTON", BS_AUTORADIOBUTTON, 14, 155, 142, 12
|
CONTROL "&Use the following DNS server addresses", IDC_FIXEDDNS, "BUTTON", BS_AUTORADIOBUTTON, 14, 155, 142, 12
|
||||||
LTEXT "Preferred DNS server:", -1, 14, 171, 135, 8
|
LTEXT "Preferred DNS server:", -1, 14, 171, 135, 8
|
||||||
CONTROL "",IDC_DNS1,"SysIPAddress32",0,150,171-2,80,12
|
CONTROL "",IDC_DNS1,"SysIPAddress32",WS_TABSTOP,150,171-2,80,12
|
||||||
LTEXT "Alternate DNS server:", -1, 14, 186, 135, 8
|
LTEXT "Alternate DNS server:", -1, 14, 186, 135, 8
|
||||||
CONTROL "",IDC_DNS2,"SysIPAddress32",0,150,186-2,80,12
|
CONTROL "",IDC_DNS2,"SysIPAddress32",WS_TABSTOP,150,186-2,80,12
|
||||||
PUSHBUTTON "&Advanced", IDC_ADVANCED, 186, 209, 50, 14, WS_DISABLED | WS_TABSTOP
|
PUSHBUTTON "&Advanced", IDC_ADVANCED, 186, 209, 50, 14, WS_DISABLED | WS_TABSTOP
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -85,3 +85,14 @@ BEGIN
|
||||||
IDS_CPLSYSTEMNAME "Network Properties"
|
IDS_CPLSYSTEMNAME "Network Properties"
|
||||||
IDS_CPLSYSTEMDESCRIPTION "Customizes network settings."
|
IDS_CPLSYSTEMDESCRIPTION "Customizes network settings."
|
||||||
END
|
END
|
||||||
|
|
||||||
|
STRINGTABLE
|
||||||
|
BEGIN
|
||||||
|
IDS_ERROR "Error"
|
||||||
|
IDS_ENTER_VALID_IPADDRESS "You must enter a valid IP address"
|
||||||
|
IDS_ENTER_VALID_SUBNET "You must enter a valid subnet mask"
|
||||||
|
IDS_CANNOT_LOAD_CONFIG "Unable to load current config data"
|
||||||
|
IDS_CANNOT_CREATE_PROPSHEET "Unable to create property sheet"
|
||||||
|
IDS_OUT_OF_MEMORY "Out of memory"
|
||||||
|
IDS_CANNOT_SAVE_CHANGES "Unable to save the changes you made"
|
||||||
|
END
|
||||||
|
|
|
@ -25,6 +25,14 @@
|
||||||
|
|
||||||
#define IDS_CPLSYSTEMNAME 1001
|
#define IDS_CPLSYSTEMNAME 1001
|
||||||
#define IDS_CPLSYSTEMDESCRIPTION 2001
|
#define IDS_CPLSYSTEMDESCRIPTION 2001
|
||||||
|
#define IDS_ERROR 3001
|
||||||
|
#define IDS_ENTER_VALID_IPADDRESS 3002
|
||||||
|
#define IDS_ENTER_VALID_SUBNET 3003
|
||||||
|
#define IDS_CANNOT_LOAD_CONFIG 3004
|
||||||
|
#define IDS_CANNOT_CREATE_PROPSHEET 3005
|
||||||
|
#define IDS_OUT_OF_MEMORY 3006
|
||||||
|
#define IDS_CANNOT_SAVE_CHANGES 3007
|
||||||
|
|
||||||
|
|
||||||
/* controls */
|
/* controls */
|
||||||
#define IDC_NETCARDLIST 100
|
#define IDC_NETCARDLIST 100
|
||||||
|
|
|
@ -4,6 +4,7 @@
|
||||||
* FILE: lib/cpl/system/tcpip_properties.c
|
* FILE: lib/cpl/system/tcpip_properties.c
|
||||||
* PURPOSE: ReactOS Network Control Panel
|
* PURPOSE: ReactOS Network Control Panel
|
||||||
* COPYRIGHT: Copyright 2004 Gero Kuehn (reactos.filter@gkware.com)
|
* COPYRIGHT: Copyright 2004 Gero Kuehn (reactos.filter@gkware.com)
|
||||||
|
* Copyright 2006 Ge van Geldorp <gvg@reactos.org>
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
@ -29,257 +30,368 @@
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
#include "resource.h"
|
#include "resource.h"
|
||||||
#include "ncpa.h"
|
#include "ncpa.h"
|
||||||
|
|
||||||
|
#define NDEBUG
|
||||||
|
#include <debug.h>
|
||||||
|
|
||||||
|
typedef struct _TCPIP_PROPERTIES_DATA {
|
||||||
|
DWORD AdapterIndex;
|
||||||
|
char *AdapterName;
|
||||||
|
BOOL DhcpEnabled;
|
||||||
|
DWORD IpAddress;
|
||||||
|
DWORD SubnetMask;
|
||||||
|
DWORD Gateway;
|
||||||
|
DWORD Dns1;
|
||||||
|
DWORD Dns2;
|
||||||
|
BOOL OldDhcpEnabled;
|
||||||
|
DWORD OldIpAddress;
|
||||||
|
DWORD OldSubnetMask;
|
||||||
|
DWORD OldGateway;
|
||||||
|
DWORD OldDns1;
|
||||||
|
DWORD OldDns2;
|
||||||
|
} TCPIP_PROPERTIES_DATA, *PTCPIP_PROPERTIES_DATA;
|
||||||
|
|
||||||
void InitPropSheetPage(PROPSHEETPAGE *psp, WORD idDlg, DLGPROC DlgProc);
|
void InitPropSheetPage(PROPSHEETPAGE *psp, WORD idDlg, DLGPROC DlgProc);
|
||||||
|
DWORD APIENTRY DhcpNotifyConfigChange(LPWSTR ServerName, LPWSTR AdapterName,
|
||||||
|
BOOL NewIpAddress, DWORD IpIndex,
|
||||||
|
DWORD IpAddress, DWORD SubnetMask,
|
||||||
|
int DhcpAction);
|
||||||
|
|
||||||
|
|
||||||
static void
|
static void
|
||||||
ManualDNS( HWND hwndDlg, BOOL Enabled ) {
|
ManualDNS(HWND Dlg, BOOL Enabled) {
|
||||||
CheckDlgButton(hwndDlg, IDC_FIXEDDNS, Enabled ? BST_CHECKED : BST_UNCHECKED);
|
CheckDlgButton(Dlg, IDC_FIXEDDNS,
|
||||||
CheckDlgButton(hwndDlg, IDC_AUTODNS, Enabled ? BST_UNCHECKED : BST_CHECKED);
|
Enabled ? BST_CHECKED : BST_UNCHECKED);
|
||||||
EnableWindow(GetDlgItem(hwndDlg, IDC_DNS1), Enabled);
|
CheckDlgButton(Dlg, IDC_AUTODNS,
|
||||||
EnableWindow(GetDlgItem(hwndDlg, IDC_DNS2), Enabled);
|
Enabled ? BST_UNCHECKED : BST_CHECKED);
|
||||||
if ( ! Enabled ) {
|
EnableWindow(GetDlgItem(Dlg, IDC_DNS1), Enabled);
|
||||||
SendDlgItemMessage(hwndDlg, IDC_DNS1, IPM_CLEARADDRESS, 0, 0);
|
EnableWindow(GetDlgItem(Dlg, IDC_DNS2), Enabled);
|
||||||
SendDlgItemMessage(hwndDlg, IDC_DNS2, IPM_CLEARADDRESS, 0, 0);
|
if (! Enabled) {
|
||||||
|
SendDlgItemMessage(Dlg, IDC_DNS1, IPM_CLEARADDRESS, 0, 0);
|
||||||
|
SendDlgItemMessage(Dlg, IDC_DNS2, IPM_CLEARADDRESS, 0, 0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
EnableDHCP( HWND hwndDlg, BOOL Enabled ) {
|
EnableDHCP(HWND Dlg, BOOL Enabled) {
|
||||||
CheckDlgButton(hwndDlg, IDC_USEDHCP, Enabled ? BST_CHECKED : BST_UNCHECKED);
|
CheckDlgButton(Dlg, IDC_USEDHCP, Enabled ? BST_CHECKED : BST_UNCHECKED);
|
||||||
CheckDlgButton(hwndDlg, IDC_NODHCP, Enabled ? BST_UNCHECKED : BST_CHECKED);
|
CheckDlgButton(Dlg, IDC_NODHCP, Enabled ? BST_UNCHECKED : BST_CHECKED);
|
||||||
EnableWindow(GetDlgItem(hwndDlg, IDC_IPADDR), ! Enabled);
|
EnableWindow(GetDlgItem(Dlg, IDC_IPADDR), ! Enabled);
|
||||||
EnableWindow(GetDlgItem(hwndDlg, IDC_SUBNETMASK), ! Enabled);
|
EnableWindow(GetDlgItem(Dlg, IDC_SUBNETMASK), ! Enabled);
|
||||||
EnableWindow(GetDlgItem(hwndDlg, IDC_DEFGATEWAY), ! Enabled);
|
EnableWindow(GetDlgItem(Dlg, IDC_DEFGATEWAY), ! Enabled);
|
||||||
EnableWindow(GetDlgItem(hwndDlg, IDC_AUTODNS), Enabled);
|
EnableWindow(GetDlgItem(Dlg, IDC_AUTODNS), Enabled);
|
||||||
if ( Enabled ) {
|
if (Enabled) {
|
||||||
SendDlgItemMessage(hwndDlg, IDC_IPADDR, IPM_CLEARADDRESS, 0, 0);
|
SendDlgItemMessage(Dlg, IDC_IPADDR, IPM_CLEARADDRESS, 0, 0);
|
||||||
SendDlgItemMessage(hwndDlg, IDC_SUBNETMASK, IPM_CLEARADDRESS, 0, 0);
|
SendDlgItemMessage(Dlg, IDC_SUBNETMASK, IPM_CLEARADDRESS, 0, 0);
|
||||||
SendDlgItemMessage(hwndDlg, IDC_DEFGATEWAY, IPM_CLEARADDRESS, 0, 0);
|
SendDlgItemMessage(Dlg, IDC_DEFGATEWAY, IPM_CLEARADDRESS, 0, 0);
|
||||||
} else {
|
} else {
|
||||||
ManualDNS(hwndDlg, TRUE);
|
ManualDNS(Dlg, TRUE);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
ShowError(HWND Parent, UINT MsgId)
|
||||||
|
{
|
||||||
|
WCHAR Error[32], Msg[64];
|
||||||
|
|
||||||
|
if (0 == LoadStringW((HINSTANCE) GetWindowLongPtrW(Parent, GWLP_HINSTANCE),
|
||||||
|
IDS_ERROR, Error, sizeof(Error) / sizeof(Error[0]))) {
|
||||||
|
wcscpy(Error, L"Error");
|
||||||
|
}
|
||||||
|
if (0 == LoadStringW((HINSTANCE) GetWindowLongPtrW(Parent, GWLP_HINSTANCE),
|
||||||
|
MsgId, Msg, sizeof(Msg) / sizeof(Msg[0]))) {
|
||||||
|
wcscpy(Msg, L"Unknown error");
|
||||||
|
}
|
||||||
|
MessageBoxW(Parent, Msg, Error, MB_OK | MB_ICONSTOP);
|
||||||
|
}
|
||||||
|
|
||||||
static BOOL
|
static BOOL
|
||||||
GetAddressFromField( HWND hwndDlg, UINT CtlId,
|
ValidateAndStore(HWND Dlg, PTCPIP_PROPERTIES_DATA DlgData)
|
||||||
DWORD *dwIPAddr,
|
{
|
||||||
const char **AddressString ) {
|
DWORD IpAddress;
|
||||||
LRESULT lResult;
|
|
||||||
struct in_addr inIPAddr;
|
|
||||||
|
|
||||||
*AddressString = NULL;
|
DlgData->DhcpEnabled = (BST_CHECKED ==
|
||||||
|
IsDlgButtonChecked(Dlg, IDC_USEDHCP));
|
||||||
|
if (! DlgData->DhcpEnabled) {
|
||||||
|
if (4 != SendMessageW(GetDlgItem(Dlg, IDC_IPADDR), IPM_GETADDRESS,
|
||||||
|
0, (LPARAM) &IpAddress)) {
|
||||||
|
ShowError(Dlg, IDS_ENTER_VALID_IPADDRESS);
|
||||||
|
SetFocus(GetDlgItem(Dlg, IDC_IPADDR));
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
DlgData->IpAddress = htonl(IpAddress);
|
||||||
|
if (4 != SendMessageW(GetDlgItem(Dlg, IDC_SUBNETMASK), IPM_GETADDRESS,
|
||||||
|
0, (LPARAM) &IpAddress)) {
|
||||||
|
ShowError(Dlg, IDS_ENTER_VALID_SUBNET);
|
||||||
|
SetFocus(GetDlgItem(Dlg, IDC_SUBNETMASK));
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
DlgData->SubnetMask = htonl(IpAddress);
|
||||||
|
if (4 != SendMessageW(GetDlgItem(Dlg, IDC_DEFGATEWAY), IPM_GETADDRESS,
|
||||||
|
0, (LPARAM) &IpAddress)) {
|
||||||
|
DlgData->Gateway = INADDR_NONE;
|
||||||
|
} else {
|
||||||
|
DlgData->Gateway = htonl(IpAddress);
|
||||||
|
}
|
||||||
|
ASSERT(BST_CHECKED == IsDlgButtonChecked(Dlg, IDC_FIXEDDNS));
|
||||||
|
} else {
|
||||||
|
DlgData->IpAddress = INADDR_NONE;
|
||||||
|
DlgData->SubnetMask = INADDR_NONE;
|
||||||
|
DlgData->Gateway = INADDR_NONE;
|
||||||
|
}
|
||||||
|
|
||||||
lResult = SendMessage(GetDlgItem(hwndDlg, IDC_IPADDR), IPM_GETADDRESS, 0,
|
if (BST_CHECKED == IsDlgButtonChecked(Dlg, IDC_FIXEDDNS)) {
|
||||||
(ULONG_PTR)dwIPAddr);
|
if (4 != SendMessageW(GetDlgItem(Dlg, IDC_DNS1), IPM_GETADDRESS,
|
||||||
if( lResult != 4 ) return FALSE;
|
0, (LPARAM) &IpAddress)) {
|
||||||
|
DlgData->Dns1 = INADDR_NONE;
|
||||||
inIPAddr.s_addr = *dwIPAddr;
|
} else {
|
||||||
*AddressString = inet_ntoa(inIPAddr);
|
DlgData->Dns1 = htonl(IpAddress);
|
||||||
if( !*AddressString ) return FALSE;
|
}
|
||||||
|
if (4 != SendMessageW(GetDlgItem(Dlg, IDC_DNS2), IPM_GETADDRESS,
|
||||||
|
0, (LPARAM) &IpAddress)) {
|
||||||
|
DlgData->Dns2 = INADDR_NONE;
|
||||||
|
} else {
|
||||||
|
DlgData->Dns2 = htonl(IpAddress);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
DlgData->Dns1 = INADDR_NONE;
|
||||||
|
DlgData->Dns2 = INADDR_NONE;
|
||||||
|
}
|
||||||
|
|
||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
static BOOL
|
static BOOL
|
||||||
InternTCPIPSettings( HWND hwndDlg ) {
|
InternTCPIPSettings(HWND Dlg, PTCPIP_PROPERTIES_DATA DlgData) {
|
||||||
PROPSHEETPAGE *pPage = (PROPSHEETPAGE *)GetWindowLongPtr(hwndDlg,GWL_USERDATA);
|
BOOL Changed;
|
||||||
IP_ADAPTER_INFO *pInfo = NULL;
|
BOOL IpChanged;
|
||||||
TCHAR pszRegKey[MAX_PATH];
|
int DhcpAction;
|
||||||
HKEY hKey = NULL;
|
LPWSTR AdapterName;
|
||||||
DWORD IpAddress, NetMask, Gateway;
|
|
||||||
const char *AddressString;
|
|
||||||
BOOL RetVal = FALSE;
|
|
||||||
BOOL DhcpEnabled = FALSE;
|
|
||||||
MIB_IPFORWARDROW RowToAdd = { 0 };
|
|
||||||
|
|
||||||
if(pPage)
|
|
||||||
pInfo = (IP_ADAPTER_INFO *)pPage->lParam;
|
|
||||||
|
|
||||||
if( !pPage || !pInfo ) goto cleanup;
|
if (! ValidateAndStore(Dlg, DlgData)) {
|
||||||
|
/* Should never happen, we should have validated at PSN_KILLACTIVE */
|
||||||
_stprintf(pszRegKey,_T("SYSTEM\\CurrentControlSet\\Services\\TCPIP\\Parameters\\Interfaces\\%S"),pInfo->AdapterName);
|
ASSERT(FALSE);
|
||||||
if(RegOpenKey(HKEY_LOCAL_MACHINE,pszRegKey,&hKey)!=ERROR_SUCCESS) goto cleanup;
|
return FALSE;
|
||||||
|
|
||||||
if( !GetAddressFromField
|
|
||||||
( hwndDlg, IDC_IPADDR, &IpAddress, &AddressString ) ||
|
|
||||||
RegSetValueEx
|
|
||||||
( hKey, _T("IPAddress"), 0, REG_SZ, (const BYTE*)AddressString,
|
|
||||||
strlen(AddressString) ) != ERROR_SUCCESS )
|
|
||||||
goto cleanup;
|
|
||||||
|
|
||||||
if( !GetAddressFromField
|
|
||||||
( hwndDlg, IDC_SUBNETMASK, &NetMask, &AddressString ) ||
|
|
||||||
RegSetValueEx
|
|
||||||
( hKey, _T("SubnetMask"), 0, REG_SZ, (const BYTE*)AddressString,
|
|
||||||
strlen(AddressString) ) != ERROR_SUCCESS )
|
|
||||||
goto cleanup;
|
|
||||||
|
|
||||||
if( DhcpEnabled ) /* FIXME - DhcpEnabled is never initialized at this point! */
|
|
||||||
DhcpLeaseIpAddress( pInfo->Index );
|
|
||||||
else {
|
|
||||||
DhcpReleaseIpAddressLease( pInfo->Index );
|
|
||||||
DhcpStaticRefreshParams( pInfo->Index, IpAddress, NetMask );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if( !GetAddressFromField
|
Changed = FALSE;
|
||||||
( hwndDlg, IDC_DEFGATEWAY, &Gateway, &AddressString ) ||
|
if (DlgData->DhcpEnabled) {
|
||||||
RegSetValueEx
|
Changed = ! DlgData->OldDhcpEnabled;
|
||||||
( hKey, _T("DefaultGateway"), 0, REG_SZ, (const BYTE*)AddressString,
|
IpChanged = FALSE;
|
||||||
strlen(AddressString) ) != ERROR_SUCCESS )
|
DhcpAction = 1;
|
||||||
goto cleanup;
|
} else {
|
||||||
|
Changed = DlgData->OldDhcpEnabled ||
|
||||||
/* If not on DHCP then add a default gateway, assuming one was specified */
|
DlgData->IpAddress != DlgData->OldIpAddress ||
|
||||||
if( !DhcpEnabled ) {
|
DlgData->SubnetMask != DlgData->OldSubnetMask;
|
||||||
RowToAdd.dwForwardMask = 0;
|
IpChanged = DlgData->OldDhcpEnabled ||
|
||||||
RowToAdd.dwForwardMetric1 = 1;
|
DlgData->IpAddress != DlgData->OldIpAddress;
|
||||||
RowToAdd.dwForwardNextHop = Gateway;
|
DhcpAction = 2;
|
||||||
CreateIpForwardEntry( &RowToAdd );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
cleanup:
|
if (Changed) {
|
||||||
if( hKey ) RegCloseKey( hKey );
|
AdapterName = HeapAlloc(GetProcessHeap(), 0,
|
||||||
|
(strlen(DlgData->AdapterName) + 1) *
|
||||||
|
sizeof(WCHAR));
|
||||||
|
if (NULL == AdapterName) {
|
||||||
|
ShowError(Dlg, IDS_OUT_OF_MEMORY);
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
MultiByteToWideChar(CP_THREAD_ACP, 0, DlgData->AdapterName, -1,
|
||||||
|
AdapterName, strlen(DlgData->AdapterName) + 1);
|
||||||
|
if (0 == DhcpNotifyConfigChange(NULL, AdapterName, IpChanged,
|
||||||
|
DlgData->AdapterIndex,
|
||||||
|
DlgData->IpAddress,
|
||||||
|
DlgData->SubnetMask, DhcpAction)) {
|
||||||
|
HeapFree(GetProcessHeap(), 0, AdapterName);
|
||||||
|
ShowError(Dlg, IDS_CANNOT_SAVE_CHANGES);
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
HeapFree(GetProcessHeap(), 0, AdapterName);
|
||||||
|
}
|
||||||
|
|
||||||
return RetVal;
|
/* FIXME Save default gateway and DNS entries */
|
||||||
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
static INT_PTR CALLBACK
|
static INT_PTR CALLBACK
|
||||||
TCPIPPropertyPageProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
|
TCPIPPropertyPageProc(HWND Dlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
|
||||||
{
|
{
|
||||||
PROPSHEETPAGE *pPage = (PROPSHEETPAGE *)GetWindowLongPtr(hwndDlg,GWL_USERDATA);
|
LPPROPSHEETPAGEW Page;
|
||||||
IP_ADAPTER_INFO *pInfo = NULL;
|
PTCPIP_PROPERTIES_DATA DlgData;
|
||||||
int StaticDNS = 0;
|
LPNMHDR Nmhdr;
|
||||||
char *NextDNSServer;
|
|
||||||
|
|
||||||
if(pPage)
|
DlgData = (PTCPIP_PROPERTIES_DATA) GetWindowLongPtrW(Dlg, GWL_USERDATA);
|
||||||
pInfo = (IP_ADAPTER_INFO *)pPage->lParam;
|
switch(uMsg) {
|
||||||
switch(uMsg)
|
|
||||||
{
|
|
||||||
case WM_INITDIALOG:
|
case WM_INITDIALOG:
|
||||||
{
|
Page = (LPPROPSHEETPAGEW) lParam;
|
||||||
pPage = (PROPSHEETPAGE *)lParam;
|
DlgData = (PTCPIP_PROPERTIES_DATA) Page->lParam;
|
||||||
pInfo = (IP_ADAPTER_INFO *)pPage->lParam;
|
SetWindowLongPtrW(Dlg, GWL_USERDATA, Page->lParam);
|
||||||
EnableWindow(GetDlgItem(hwndDlg,IDC_ADVANCED),FALSE);
|
|
||||||
SetWindowLongPtr(hwndDlg,GWL_USERDATA,(DWORD_PTR)pPage->lParam);
|
|
||||||
|
|
||||||
EnableDHCP( hwndDlg, pInfo->DhcpEnabled );
|
EnableWindow(GetDlgItem(Dlg, IDC_ADVANCED), FALSE);
|
||||||
|
|
||||||
if ( ! pInfo->DhcpEnabled )
|
EnableDHCP(Dlg, DlgData->OldDhcpEnabled);
|
||||||
|
|
||||||
|
if (! DlgData->OldDhcpEnabled)
|
||||||
{
|
{
|
||||||
DWORD dwIPAddr;
|
if (INADDR_NONE != DlgData->OldIpAddress) {
|
||||||
IP_ADDR_STRING *pString;
|
SendDlgItemMessage(Dlg, IDC_IPADDR, IPM_SETADDRESS, 0,
|
||||||
pString = &pInfo->IpAddressList;
|
ntohl(DlgData->OldIpAddress));
|
||||||
while(pString->Next)
|
}
|
||||||
pString = pString->Next;
|
if (INADDR_NONE != DlgData->OldSubnetMask) {
|
||||||
dwIPAddr = inet_addr(pString->IpAddress.String);
|
SendDlgItemMessage(Dlg, IDC_SUBNETMASK, IPM_SETADDRESS, 0,
|
||||||
SendDlgItemMessage(hwndDlg,IDC_IPADDR,IPM_SETADDRESS,0,
|
ntohl(DlgData->OldSubnetMask));
|
||||||
ntohl(dwIPAddr));
|
}
|
||||||
dwIPAddr = inet_addr(pString->IpMask.String);
|
if (INADDR_NONE != DlgData->OldGateway) {
|
||||||
SendDlgItemMessage(hwndDlg,IDC_SUBNETMASK,IPM_SETADDRESS,0,
|
SendDlgItemMessage(Dlg, IDC_DEFGATEWAY, IPM_SETADDRESS, 0,
|
||||||
ntohl(dwIPAddr));
|
ntohl(DlgData->OldGateway));
|
||||||
|
|
||||||
pString = &pInfo->GatewayList;
|
|
||||||
while(pString->Next)
|
|
||||||
pString = pString->Next;
|
|
||||||
dwIPAddr = inet_addr(pString->IpAddress.String);
|
|
||||||
SendDlgItemMessage(hwndDlg,IDC_DEFGATEWAY,IPM_SETADDRESS,0,
|
|
||||||
ntohl(dwIPAddr));
|
|
||||||
|
|
||||||
}
|
|
||||||
{
|
|
||||||
TCHAR pszRegKey[MAX_PATH];
|
|
||||||
HKEY hKey;
|
|
||||||
_stprintf(pszRegKey,_T("SYSTEM\\CurrentControlSet\\Services\\TCPIP\\Parameters\\Interfaces\\%S"),pInfo->AdapterName);
|
|
||||||
if(RegOpenKey(HKEY_LOCAL_MACHINE,pszRegKey,&hKey)==ERROR_SUCCESS)
|
|
||||||
{
|
|
||||||
char pszDNS[MAX_PATH];
|
|
||||||
DWORD dwSize = sizeof(pszDNS);
|
|
||||||
DWORD dwType = REG_SZ;
|
|
||||||
DWORD dwIPAddr;
|
|
||||||
RegQueryValueExA(hKey,"NameServer",NULL,&dwType,(BYTE*)pszDNS,&dwSize);
|
|
||||||
RegCloseKey(hKey);
|
|
||||||
|
|
||||||
NextDNSServer = pszDNS;
|
|
||||||
|
|
||||||
while( NextDNSServer && *NextDNSServer && StaticDNS < 2 ) {
|
|
||||||
dwIPAddr = inet_addr(NextDNSServer);
|
|
||||||
if( dwIPAddr != INADDR_NONE ) {
|
|
||||||
SendDlgItemMessage(hwndDlg,IDC_DNS1 + StaticDNS,
|
|
||||||
IPM_SETADDRESS,0,ntohl(dwIPAddr));
|
|
||||||
StaticDNS++;
|
|
||||||
}
|
|
||||||
NextDNSServer = strchr( pszDNS, ',' );
|
|
||||||
if( NextDNSServer )
|
|
||||||
NextDNSServer++;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
ManualDNS( hwndDlg, StaticDNS );
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
break;
|
if (INADDR_NONE != DlgData->OldDns1) {
|
||||||
|
SendDlgItemMessage(Dlg, IDC_DNS1, IPM_SETADDRESS, 0,
|
||||||
|
ntohl(DlgData->OldDns1));
|
||||||
|
if (INADDR_NONE != DlgData->OldDns2) {
|
||||||
|
SendDlgItemMessage(Dlg, IDC_DNS2, IPM_SETADDRESS, 0,
|
||||||
|
ntohl(DlgData->OldDns2));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
ManualDNS(Dlg, INADDR_NONE != DlgData->OldDns1);
|
||||||
|
break;
|
||||||
|
|
||||||
case WM_COMMAND:
|
case WM_COMMAND:
|
||||||
switch(LOWORD(wParam))
|
switch(LOWORD(wParam)) {
|
||||||
{
|
|
||||||
case IDC_FIXEDDNS:
|
case IDC_FIXEDDNS:
|
||||||
ManualDNS( hwndDlg, TRUE );
|
ManualDNS(Dlg, TRUE);
|
||||||
break;
|
return TRUE;
|
||||||
|
|
||||||
case IDC_AUTODNS:
|
case IDC_AUTODNS:
|
||||||
ManualDNS( hwndDlg, FALSE );
|
ManualDNS(Dlg, FALSE);
|
||||||
break;
|
return TRUE;
|
||||||
|
|
||||||
case IDC_USEDHCP:
|
case IDC_USEDHCP:
|
||||||
EnableDHCP( hwndDlg, TRUE );
|
EnableDHCP(Dlg, TRUE);
|
||||||
break;
|
return TRUE;
|
||||||
|
|
||||||
case IDC_NODHCP:
|
case IDC_NODHCP:
|
||||||
EnableDHCP( hwndDlg, FALSE );
|
EnableDHCP(Dlg, FALSE);
|
||||||
break;
|
return TRUE;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
case IDOK:
|
case WM_NOTIFY:
|
||||||
|
Nmhdr = (LPNMHDR) lParam;
|
||||||
|
|
||||||
|
switch(Nmhdr->code) {
|
||||||
|
case PSN_KILLACTIVE:
|
||||||
|
/* Do validation here, must set FALSE to continue */
|
||||||
|
SetWindowLongPtrW(Dlg, DWL_MSGRESULT,
|
||||||
|
(LONG_PTR) ! ValidateAndStore(Dlg, DlgData));
|
||||||
|
return TRUE;
|
||||||
|
|
||||||
|
case PSN_APPLY:
|
||||||
/* Set the IP Address and DNS Information so we won't
|
/* Set the IP Address and DNS Information so we won't
|
||||||
* be doing all this for nothing */
|
* be doing all this for nothing */
|
||||||
InternTCPIPSettings( hwndDlg );
|
SetWindowLongPtrW(Dlg, DWL_MSGRESULT,
|
||||||
break;
|
InternTCPIPSettings(Dlg, DlgData) ?
|
||||||
|
PSNRET_NOERROR : PSNRET_INVALID);
|
||||||
|
return TRUE;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
void DisplayTCPIPProperties(HWND hParent,IP_ADAPTER_INFO *pInfo)
|
static BOOL
|
||||||
|
LoadDataFromInfo(PTCPIP_PROPERTIES_DATA DlgData, IP_ADAPTER_INFO *Info)
|
||||||
{
|
{
|
||||||
PROPSHEETPAGE psp[1];
|
IP_ADDR_STRING *pString;
|
||||||
PROPSHEETHEADER psh;
|
WCHAR RegKey[MAX_PATH];
|
||||||
INITCOMMONCONTROLSEX cce;
|
HKEY hKey;
|
||||||
|
char Dns[MAX_PATH];
|
||||||
|
DWORD Size;
|
||||||
|
DWORD Type;
|
||||||
|
char *NextDnsServer;
|
||||||
|
|
||||||
cce.dwSize = sizeof(INITCOMMONCONTROLSEX);
|
DlgData->AdapterName = Info->AdapterName;
|
||||||
cce.dwICC = ICC_INTERNET_CLASSES;
|
DlgData->AdapterIndex = Info->Index;
|
||||||
InitCommonControlsEx(&cce);
|
|
||||||
|
|
||||||
ZeroMemory(&psh, sizeof(PROPSHEETHEADER));
|
DlgData->OldDhcpEnabled = Info->DhcpEnabled;
|
||||||
psh.dwSize = sizeof(PROPSHEETHEADER);
|
|
||||||
psh.dwFlags = PSH_PROPSHEETPAGE | PSH_NOAPPLYNOW;
|
|
||||||
psh.hwndParent = hParent;
|
|
||||||
psh.hInstance = hApplet;
|
|
||||||
psh.hIcon = LoadIcon(hApplet, MAKEINTRESOURCE(IDI_CPLSYSTEM));
|
|
||||||
psh.pszCaption = NULL;//Caption;
|
|
||||||
psh.nPages = sizeof(psp) / sizeof(PROPSHEETPAGE);
|
|
||||||
psh.nStartPage = 0;
|
|
||||||
psh.ppsp = psp;
|
|
||||||
psh.pfnCallback = NULL;
|
|
||||||
|
|
||||||
|
|
||||||
InitPropSheetPage(&psp[0], IDD_TCPIPPROPERTIES, TCPIPPropertyPageProc);
|
pString = &Info->IpAddressList;
|
||||||
psp[0].lParam = (LPARAM)pInfo;
|
while (NULL != pString->Next) {
|
||||||
|
pString = pString->Next;
|
||||||
|
}
|
||||||
|
DlgData->OldIpAddress = inet_addr(pString->IpAddress.String);
|
||||||
|
DlgData->OldSubnetMask = inet_addr(pString->IpMask.String);
|
||||||
|
pString = &Info->GatewayList;
|
||||||
|
while (NULL != pString->Next) {
|
||||||
|
pString = pString->Next;
|
||||||
|
}
|
||||||
|
DlgData->OldGateway = inet_addr(pString->IpAddress.String);
|
||||||
|
|
||||||
if (PropertySheet(&psh) == -1)
|
DlgData->OldDns1 = INADDR_NONE;
|
||||||
{
|
DlgData->OldDns2 = INADDR_NONE;
|
||||||
MessageBox(hParent,_T("Unable to create property sheet"),_T("Error"),MB_ICONSTOP);
|
swprintf(RegKey,
|
||||||
}
|
L"SYSTEM\\CurrentControlSet\\Services\\TCPIP\\Parameters\\Interfaces\\%S",
|
||||||
|
Info->AdapterName);
|
||||||
|
if (ERROR_SUCCESS == RegOpenKeyW(HKEY_LOCAL_MACHINE, RegKey, &hKey)) {
|
||||||
|
Size = sizeof(Dns);
|
||||||
|
RegQueryValueExA(hKey, "NameServer", NULL, &Type, (BYTE *)Dns,
|
||||||
|
&Size);
|
||||||
|
RegCloseKey(hKey);
|
||||||
|
|
||||||
return;
|
if ('\0' != Dns[0]) {
|
||||||
|
DlgData->OldDns1 = inet_addr(Dns);
|
||||||
|
NextDnsServer = strchr(Dns, ',');
|
||||||
|
if (NULL != NextDnsServer && '\0' != *NextDnsServer) {
|
||||||
|
DlgData->OldDns2 = inet_addr(NextDnsServer);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return TRUE;
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
DisplayTCPIPProperties(HWND hParent, IP_ADAPTER_INFO *pInfo)
|
||||||
|
{
|
||||||
|
PROPSHEETPAGEW psp[1];
|
||||||
|
PROPSHEETHEADERW psh;
|
||||||
|
INITCOMMONCONTROLSEX cce;
|
||||||
|
TCPIP_PROPERTIES_DATA DlgData;
|
||||||
|
|
||||||
|
if (! LoadDataFromInfo(&DlgData, pInfo))
|
||||||
|
{
|
||||||
|
ShowError(hParent, IDS_CANNOT_LOAD_CONFIG);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
cce.dwSize = sizeof(INITCOMMONCONTROLSEX);
|
||||||
|
cce.dwICC = ICC_INTERNET_CLASSES;
|
||||||
|
InitCommonControlsEx(&cce);
|
||||||
|
|
||||||
|
ZeroMemory(&psh, sizeof(PROPSHEETHEADER));
|
||||||
|
psh.dwSize = sizeof(PROPSHEETHEADER);
|
||||||
|
psh.dwFlags = PSH_PROPSHEETPAGE | PSH_NOAPPLYNOW;
|
||||||
|
psh.hwndParent = hParent;
|
||||||
|
psh.hInstance = hApplet;
|
||||||
|
psh.hIcon = LoadIcon(hApplet, MAKEINTRESOURCE(IDI_CPLSYSTEM));
|
||||||
|
psh.pszCaption = NULL;//Caption;
|
||||||
|
psh.nPages = sizeof(psp) / sizeof(PROPSHEETPAGE);
|
||||||
|
psh.nStartPage = 0;
|
||||||
|
psh.ppsp = psp;
|
||||||
|
psh.pfnCallback = NULL;
|
||||||
|
|
||||||
|
InitPropSheetPage(&psp[0], IDD_TCPIPPROPERTIES, TCPIPPropertyPageProc);
|
||||||
|
psp[0].lParam = (LPARAM) &DlgData;
|
||||||
|
|
||||||
|
if (PropertySheetW(&psh) == -1)
|
||||||
|
{
|
||||||
|
ShowError(hParent, IDS_CANNOT_CREATE_PROPSHEET);
|
||||||
|
}
|
||||||
|
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,12 +1,9 @@
|
||||||
/* $Id: dllmain.c 12852 2005-01-06 13:58:04Z mf $
|
/*
|
||||||
*
|
|
||||||
* COPYRIGHT: See COPYING in the top level directory
|
* COPYRIGHT: See COPYING in the top level directory
|
||||||
* PROJECT: ReactOS system libraries
|
* PROJECT: ReactOS system libraries
|
||||||
* FILE: lib/dhcpcapi/dhcpcapi.c
|
* FILE: lib/dhcpcapi/dhcpcapi.c
|
||||||
* PURPOSE: Client API for DHCP
|
* PURPOSE: Client API for DHCP
|
||||||
* PROGRAMMER: arty (ayerkes@speakeasy.net)
|
* COPYRIGHT: Copyright 2005 Art Yerkes <ayerkes@speakeasy.net>
|
||||||
* UPDATE HISTORY:
|
|
||||||
* Created 12/04/2005
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <roscfg.h>
|
#include <roscfg.h>
|
||||||
|
@ -15,6 +12,9 @@
|
||||||
#include <time.h>
|
#include <time.h>
|
||||||
#include <dhcp/rosdhcp_public.h>
|
#include <dhcp/rosdhcp_public.h>
|
||||||
|
|
||||||
|
#define NDEBUG
|
||||||
|
#include <debug.h>
|
||||||
|
|
||||||
#define DHCP_TIMEOUT 1000
|
#define DHCP_TIMEOUT 1000
|
||||||
|
|
||||||
DWORD APIENTRY DhcpCApiInitialize(LPDWORD Version) {
|
DWORD APIENTRY DhcpCApiInitialize(LPDWORD Version) {
|
||||||
|
@ -118,34 +118,70 @@ DWORD APIENTRY DhcpStaticRefreshParams( DWORD AdapterIndex,
|
||||||
return Reply.Reply;
|
return Reply.Reply;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*++
|
/*!
|
||||||
* @name DhcpRosGetAdapterInfo
|
* Set new TCP/IP parameters and notify DHCP client service of this
|
||||||
* @implemented ReactOS only
|
|
||||||
*
|
*
|
||||||
|
* \param[in] ServerName
|
||||||
|
* NULL for local machine
|
||||||
|
*
|
||||||
|
* \param[in] AdapterName
|
||||||
|
* IPHLPAPI name of adapter to change
|
||||||
|
*
|
||||||
|
* \param[in] NewIpAddress
|
||||||
|
* TRUE if IP address changes
|
||||||
|
*
|
||||||
|
* \param[in] IpAddress
|
||||||
|
* New IP address (network byte order)
|
||||||
|
*
|
||||||
|
* \param[in] SubnetMask
|
||||||
|
* New subnet mask (network byte order)
|
||||||
|
*
|
||||||
|
* \param[in] DhcpAction
|
||||||
|
* 0 - don't modify
|
||||||
|
* 1 - enable DHCP
|
||||||
|
* 2 - disable DHCP
|
||||||
|
*
|
||||||
|
* \return non-zero on success
|
||||||
|
*
|
||||||
|
* \remarks Undocumented by Microsoft
|
||||||
|
*/
|
||||||
|
DWORD APIENTRY
|
||||||
|
DhcpNotifyConfigChange(LPWSTR ServerName,
|
||||||
|
LPWSTR AdapterName,
|
||||||
|
BOOL NewIpAddress,
|
||||||
|
DWORD IpIndex,
|
||||||
|
DWORD IpAddress,
|
||||||
|
DWORD SubnetMask,
|
||||||
|
int DhcpAction)
|
||||||
|
{
|
||||||
|
DPRINT1("DhcpNotifyConfigChange not implemented yet\n");
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*!
|
||||||
* Get DHCP info for an adapter
|
* Get DHCP info for an adapter
|
||||||
*
|
*
|
||||||
* @param AdapterIndex
|
* \param[in] AdapterIndex
|
||||||
* Index of the adapter (iphlpapi-style) for which info is
|
* Index of the adapter (iphlpapi-style) for which info is
|
||||||
* requested
|
* requested
|
||||||
*
|
*
|
||||||
* @param DhcpEnabled
|
* \param[out] DhcpEnabled
|
||||||
* Returns whether DHCP is enabled for the adapter
|
* Returns whether DHCP is enabled for the adapter
|
||||||
*
|
*
|
||||||
* @param DhcpServer
|
* \param[out] DhcpServer
|
||||||
* Returns DHCP server IP address (255.255.255.255 if no
|
* Returns DHCP server IP address (255.255.255.255 if no
|
||||||
* server reached yet), in network byte order
|
* server reached yet), in network byte order
|
||||||
*
|
*
|
||||||
* @param LeaseObtained
|
* \param[out] LeaseObtained
|
||||||
* Returns time at which the lease was obtained
|
* Returns time at which the lease was obtained
|
||||||
*
|
*
|
||||||
* @param LeaseExpires
|
* \param[out] LeaseExpires
|
||||||
* Returns time at which the lease will expire
|
* Returns time at which the lease will expire
|
||||||
*
|
*
|
||||||
* @return non-zero on success
|
* \return non-zero on success
|
||||||
*
|
*
|
||||||
* @remarks This is a ReactOS-only routine
|
* \remarks This is a ReactOS-only routine
|
||||||
*
|
*/
|
||||||
*--*/
|
|
||||||
DWORD APIENTRY DhcpRosGetAdapterInfo( DWORD AdapterIndex,
|
DWORD APIENTRY DhcpRosGetAdapterInfo( DWORD AdapterIndex,
|
||||||
PBOOL DhcpEnabled,
|
PBOOL DhcpEnabled,
|
||||||
PDWORD DhcpServer,
|
PDWORD DhcpServer,
|
||||||
|
|
|
@ -17,7 +17,7 @@
|
||||||
@ stub DhcpHandlePnPEvent
|
@ stub DhcpHandlePnPEvent
|
||||||
@ stdcall DhcpLeaseIpAddress(long)
|
@ stdcall DhcpLeaseIpAddress(long)
|
||||||
@ stub DhcpLeaseIpAddressEx
|
@ stub DhcpLeaseIpAddressEx
|
||||||
@ stub DhcpNotifyConfigChange
|
@ stdcall DhcpNotifyConfigChange(ptr ptr long long long long long)
|
||||||
@ stub DhcpNotifyConfigChangeEx
|
@ stub DhcpNotifyConfigChangeEx
|
||||||
@ stub DhcpNotifyMediaReconnected
|
@ stub DhcpNotifyMediaReconnected
|
||||||
@ stub DhcpOpenGlobalEvent
|
@ stub DhcpOpenGlobalEvent
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue