mirror of
https://github.com/reactos/reactos.git
synced 2024-12-26 00:54:40 +00:00
Preliminary commit for tcpip control panel. I've been sitting on this
for a while, mainly because it used to bugcheck in a named pipe call. I've lost my modifications to dhcpcapi, so stuff in there might not be right. Looking at it. svn path=/trunk/; revision=19110
This commit is contained in:
parent
381dcf3a8c
commit
9fc73bcf41
2 changed files with 187 additions and 73 deletions
|
@ -11,6 +11,9 @@
|
|||
<library>user32</library>
|
||||
<library>comctl32</library>
|
||||
<library>iphlpapi</library>
|
||||
<library>ws2_32</library>
|
||||
<library>dhcpcapi</library>
|
||||
<library>ntdll</library>
|
||||
<file>ncpa.c</file>
|
||||
<file>tcpip_properties.c</file>
|
||||
<file>ncpa.rc</file>
|
||||
|
|
|
@ -34,6 +34,7 @@
|
|||
#include <iptypes.h>
|
||||
#include <iphlpapi.h>
|
||||
#include <commctrl.h>
|
||||
#include <dhcpcapi.h>
|
||||
#include <prsht.h>
|
||||
|
||||
|
||||
|
@ -54,11 +55,106 @@
|
|||
|
||||
extern void InitPropSheetPage(PROPSHEETPAGE *psp, WORD idDlg, DLGPROC DlgProc);
|
||||
|
||||
void EnableDHCP( HWND hwndDlg, BOOL Enabled ) {
|
||||
CheckDlgButton(hwndDlg,IDC_USEDHCP,Enabled ? BST_CHECKED : BST_UNCHECKED);
|
||||
CheckDlgButton(hwndDlg,IDC_NODHCP,Enabled ? BST_UNCHECKED : BST_CHECKED);
|
||||
}
|
||||
|
||||
void ManualDNS( HWND hwndDlg, BOOL Enabled ) {
|
||||
CheckDlgButton(hwndDlg,IDC_FIXEDDNS,Enabled ? BST_CHECKED : BST_UNCHECKED);
|
||||
CheckDlgButton(hwndDlg,IDC_AUTODNS,Enabled ? BST_UNCHECKED : BST_CHECKED);
|
||||
EnableWindow(GetDlgItem(hwndDlg,IDC_DNS1),Enabled);
|
||||
EnableWindow(GetDlgItem(hwndDlg,IDC_DNS2),Enabled);
|
||||
}
|
||||
|
||||
BOOL GetAddressFromField( HWND hwndDlg, UINT CtlId,
|
||||
DWORD *dwIPAddr,
|
||||
const char **AddressString ) {
|
||||
LRESULT lResult;
|
||||
struct in_addr inIPAddr;
|
||||
|
||||
*AddressString = NULL;
|
||||
|
||||
lResult = SendMessage(GetDlgItem(hwndDlg, IDC_IPADDR), IPM_GETADDRESS, 0,
|
||||
(ULONG_PTR)dwIPAddr);
|
||||
if( lResult != 4 ) return FALSE;
|
||||
|
||||
inIPAddr.s_addr = *dwIPAddr;
|
||||
*AddressString = inet_ntoa(inIPAddr);
|
||||
if( !*AddressString ) return FALSE;
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
BOOL InternTCPIPSettings( HWND hwndDlg ) {
|
||||
PROPSHEETPAGE *pPage = (PROPSHEETPAGE *)GetWindowLongPtr(hwndDlg,GWL_USERDATA);
|
||||
IP_ADAPTER_INFO *pInfo = NULL;
|
||||
TCHAR pszRegKey[MAX_PATH];
|
||||
HKEY hKey = NULL;
|
||||
DWORD IpAddress, NetMask, Gateway;
|
||||
const char *AddressString;
|
||||
BOOL RetVal = FALSE;
|
||||
BOOL DhcpEnabled;
|
||||
MIB_IPFORWARDROW RowToAdd = { 0 };
|
||||
|
||||
if(pPage)
|
||||
pInfo = (IP_ADAPTER_INFO *)pPage->lParam;
|
||||
|
||||
if( !pPage || !pInfo ) goto cleanup;
|
||||
|
||||
_stprintf(pszRegKey,_T("SYSTEM\\CurrentControlSet\\Services\\TCPIP\\Parameters\\Interfaces\\%S"),pInfo->AdapterName);
|
||||
if(RegOpenKey(HKEY_LOCAL_MACHINE,pszRegKey,&hKey)!=ERROR_SUCCESS) goto cleanup;
|
||||
|
||||
if( !GetAddressFromField
|
||||
( hwndDlg, IDC_IPADDR, &IpAddress, &AddressString ) ||
|
||||
RegSetValueEx
|
||||
( hKey, _T("IPAddress"), 0, REG_SZ, AddressString,
|
||||
strlen(AddressString) ) != ERROR_SUCCESS )
|
||||
goto cleanup;
|
||||
|
||||
if( !GetAddressFromField
|
||||
( hwndDlg, IDC_SUBNETMASK, &NetMask, &AddressString ) ||
|
||||
RegSetValueEx
|
||||
( hKey, _T("SubnetMask"), 0, REG_SZ, AddressString,
|
||||
strlen(AddressString) ) != ERROR_SUCCESS )
|
||||
goto cleanup;
|
||||
|
||||
if( DhcpEnabled )
|
||||
DhcpLeaseIpAddress( pInfo->Index );
|
||||
else {
|
||||
DhcpReleaseIpAddressLease( pInfo->Index );
|
||||
DhcpStaticRefreshParams( pInfo->Index, IpAddress, NetMask );
|
||||
}
|
||||
|
||||
if( !GetAddressFromField
|
||||
( hwndDlg, IDC_DEFGATEWAY, &Gateway, &AddressString ) ||
|
||||
RegSetValueEx
|
||||
( hKey, _T("DefaultGateway"), 0, REG_SZ, AddressString,
|
||||
strlen(AddressString) ) != ERROR_SUCCESS )
|
||||
goto cleanup;
|
||||
|
||||
/* If not on DHCP then add a default gateway, assuming one was specified */
|
||||
if( !DhcpEnabled ) {
|
||||
RowToAdd.dwForwardMask = 0;
|
||||
RowToAdd.dwForwardMetric1 = 1;
|
||||
RowToAdd.dwForwardNextHop = Gateway;
|
||||
CreateIpForwardEntry( &RowToAdd );
|
||||
}
|
||||
|
||||
cleanup:
|
||||
if( hKey ) RegCloseKey( hKey );
|
||||
|
||||
return RetVal;
|
||||
}
|
||||
|
||||
INT_PTR CALLBACK
|
||||
TCPIPPropertyPageProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
|
||||
{
|
||||
PROPSHEETPAGE *pPage = (PROPSHEETPAGE *)GetWindowLongPtr(hwndDlg,GWL_USERDATA);
|
||||
IP_ADAPTER_INFO *pInfo = NULL;
|
||||
int StaticDNS = 0;
|
||||
char *NextDNSServer;
|
||||
|
||||
if(pPage)
|
||||
pInfo = (IP_ADAPTER_INFO *)pPage->lParam;
|
||||
switch(uMsg)
|
||||
|
@ -70,32 +166,23 @@ TCPIPPropertyPageProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
|
|||
EnableWindow(GetDlgItem(hwndDlg,IDC_ADVANCED),FALSE);
|
||||
SetWindowLongPtr(hwndDlg,GWL_USERDATA,(DWORD_PTR)pPage->lParam);
|
||||
|
||||
if(pInfo->DhcpEnabled) {
|
||||
CheckDlgButton(hwndDlg,IDC_USEDHCP,BST_CHECKED);
|
||||
CheckDlgButton(hwndDlg,IDC_NODHCP,BST_UNCHECKED);
|
||||
} else {
|
||||
CheckDlgButton(hwndDlg,IDC_USEDHCP,BST_UNCHECKED);
|
||||
CheckDlgButton(hwndDlg,IDC_NODHCP,BST_CHECKED);
|
||||
}
|
||||
EnableDHCP( hwndDlg, pInfo->DhcpEnabled );
|
||||
|
||||
{
|
||||
DWORD dwIPAddr;
|
||||
int b[4];
|
||||
IP_ADDR_STRING *pString;
|
||||
pString = &pInfo->IpAddressList;
|
||||
while(pString->Next)
|
||||
pString = pString->Next;
|
||||
sscanf(pString->IpAddress.String,"%d.%d.%d.%d",&b[0],&b[1],&b[2],&b[3]);
|
||||
dwIPAddr = b[0]<<24|b[1]<<16|b[2]<<8|b[3];
|
||||
dwIPAddr = inet_addr(pString->IpAddress.String);
|
||||
SendDlgItemMessage(hwndDlg,IDC_IPADDR,IPM_SETADDRESS,0,dwIPAddr);
|
||||
sscanf(pString->IpMask.String,"%d.%d.%d.%d",&b[0],&b[1],&b[2],&b[3]);
|
||||
dwIPAddr = b[0]<<24|b[1]<<16|b[2]<<8|b[3];
|
||||
dwIPAddr = inet_addr(pString->IpMask.String);
|
||||
SendDlgItemMessage(hwndDlg,IDC_SUBNETMASK,IPM_SETADDRESS,0,dwIPAddr);
|
||||
|
||||
pString = &pInfo->GatewayList;
|
||||
while(pString->Next)
|
||||
pString = pString->Next;
|
||||
sscanf(pString->IpAddress.String,"%d.%d.%d.%d",&b[0],&b[1],&b[2],&b[3]);
|
||||
dwIPAddr = b[0]<<24|b[1]<<16|b[2]<<8|b[3];
|
||||
dwIPAddr = inet_addr(pString->IpAddress.String);
|
||||
SendDlgItemMessage(hwndDlg,IDC_DEFGATEWAY,IPM_SETADDRESS,0,dwIPAddr);
|
||||
|
||||
}
|
||||
|
@ -108,21 +195,24 @@ TCPIPPropertyPageProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
|
|||
char pszDNS[MAX_PATH];
|
||||
DWORD dwSize = sizeof(pszDNS);
|
||||
DWORD dwType = REG_SZ;
|
||||
int b[2][4];
|
||||
DWORD dwIPAddr;
|
||||
RegQueryValueExA(hKey,"NameServer",NULL,&dwType,(BYTE*)pszDNS,&dwSize);
|
||||
RegCloseKey(hKey);
|
||||
|
||||
sscanf(pszDNS,"%d.%d.%d.%d,%d.%d.%d.%d",&b[0][0],&b[0][1],&b[0][2],&b[0][3],&b[1][0],&b[1][1],&b[1][2],&b[1][3]);
|
||||
dwIPAddr = b[0][0]<<24|b[0][1]<<16|b[0][2]<<8|b[0][3];
|
||||
SendDlgItemMessage(hwndDlg,IDC_DNS1,IPM_SETADDRESS,0,dwIPAddr);
|
||||
dwIPAddr = b[1][0]<<24|b[1][1]<<16|b[1][2]<<8|b[1][3];
|
||||
SendDlgItemMessage(hwndDlg,IDC_DNS2,IPM_SETADDRESS,0,dwIPAddr);
|
||||
CheckDlgButton(hwndDlg,IDC_FIXEDDNS,TRUE);
|
||||
EnableWindow(GetDlgItem(hwndDlg,IDC_DNS1),FALSE);
|
||||
EnableWindow(GetDlgItem(hwndDlg,IDC_DNS2),FALSE);
|
||||
EnableWindow(GetDlgItem(hwndDlg,IDC_AUTODNS),FALSE);
|
||||
EnableWindow(GetDlgItem(hwndDlg,IDC_FIXEDDNS),FALSE);
|
||||
NextDNSServer = pszDNS;
|
||||
|
||||
while( NextDNSServer && StaticDNS < 2 ) {
|
||||
dwIPAddr = inet_addr(NextDNSServer);
|
||||
if( dwIPAddr != INADDR_NONE ) {
|
||||
SendDlgItemMessage(hwndDlg,IDC_DNS1 + StaticDNS,IPM_SETADDRESS,0,dwIPAddr);
|
||||
StaticDNS++;
|
||||
}
|
||||
NextDNSServer = strchr( pszDNS, ',' );
|
||||
if( NextDNSServer )
|
||||
NextDNSServer++;
|
||||
}
|
||||
|
||||
ManualDNS( hwndDlg, StaticDNS );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -130,6 +220,27 @@ TCPIPPropertyPageProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
|
|||
case WM_COMMAND:
|
||||
switch(LOWORD(wParam))
|
||||
{
|
||||
case IDC_FIXEDDNS:
|
||||
ManualDNS( hwndDlg, TRUE );
|
||||
break;
|
||||
|
||||
case IDC_AUTODNS:
|
||||
ManualDNS( hwndDlg, FALSE );
|
||||
break;
|
||||
|
||||
case IDC_USEDHCP:
|
||||
EnableDHCP( hwndDlg, TRUE );
|
||||
break;
|
||||
|
||||
case IDC_NODHCP:
|
||||
EnableDHCP( hwndDlg, FALSE );
|
||||
break;
|
||||
|
||||
case IDOK:
|
||||
/* Set the IP Address and DNS Information so we won't
|
||||
* be doing all this for nothing */
|
||||
InternTCPIPSettings( hwndDlg );
|
||||
break;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue