mirror of
https://github.com/reactos/reactos.git
synced 2024-12-26 17:14:41 +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>user32</library>
|
||||||
<library>comctl32</library>
|
<library>comctl32</library>
|
||||||
<library>iphlpapi</library>
|
<library>iphlpapi</library>
|
||||||
|
<library>ws2_32</library>
|
||||||
|
<library>dhcpcapi</library>
|
||||||
|
<library>ntdll</library>
|
||||||
<file>ncpa.c</file>
|
<file>ncpa.c</file>
|
||||||
<file>tcpip_properties.c</file>
|
<file>tcpip_properties.c</file>
|
||||||
<file>ncpa.rc</file>
|
<file>ncpa.rc</file>
|
||||||
|
|
|
@ -34,6 +34,7 @@
|
||||||
#include <iptypes.h>
|
#include <iptypes.h>
|
||||||
#include <iphlpapi.h>
|
#include <iphlpapi.h>
|
||||||
#include <commctrl.h>
|
#include <commctrl.h>
|
||||||
|
#include <dhcpcapi.h>
|
||||||
#include <prsht.h>
|
#include <prsht.h>
|
||||||
|
|
||||||
|
|
||||||
|
@ -54,11 +55,106 @@
|
||||||
|
|
||||||
extern void InitPropSheetPage(PROPSHEETPAGE *psp, WORD idDlg, DLGPROC DlgProc);
|
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
|
INT_PTR CALLBACK
|
||||||
TCPIPPropertyPageProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
|
TCPIPPropertyPageProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
|
||||||
{
|
{
|
||||||
PROPSHEETPAGE *pPage = (PROPSHEETPAGE *)GetWindowLongPtr(hwndDlg,GWL_USERDATA);
|
PROPSHEETPAGE *pPage = (PROPSHEETPAGE *)GetWindowLongPtr(hwndDlg,GWL_USERDATA);
|
||||||
IP_ADAPTER_INFO *pInfo = NULL;
|
IP_ADAPTER_INFO *pInfo = NULL;
|
||||||
|
int StaticDNS = 0;
|
||||||
|
char *NextDNSServer;
|
||||||
|
|
||||||
if(pPage)
|
if(pPage)
|
||||||
pInfo = (IP_ADAPTER_INFO *)pPage->lParam;
|
pInfo = (IP_ADAPTER_INFO *)pPage->lParam;
|
||||||
switch(uMsg)
|
switch(uMsg)
|
||||||
|
@ -70,32 +166,23 @@ TCPIPPropertyPageProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
|
||||||
EnableWindow(GetDlgItem(hwndDlg,IDC_ADVANCED),FALSE);
|
EnableWindow(GetDlgItem(hwndDlg,IDC_ADVANCED),FALSE);
|
||||||
SetWindowLongPtr(hwndDlg,GWL_USERDATA,(DWORD_PTR)pPage->lParam);
|
SetWindowLongPtr(hwndDlg,GWL_USERDATA,(DWORD_PTR)pPage->lParam);
|
||||||
|
|
||||||
if(pInfo->DhcpEnabled) {
|
EnableDHCP( hwndDlg, 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);
|
|
||||||
}
|
|
||||||
{
|
{
|
||||||
DWORD dwIPAddr;
|
DWORD dwIPAddr;
|
||||||
int b[4];
|
|
||||||
IP_ADDR_STRING *pString;
|
IP_ADDR_STRING *pString;
|
||||||
pString = &pInfo->IpAddressList;
|
pString = &pInfo->IpAddressList;
|
||||||
while(pString->Next)
|
while(pString->Next)
|
||||||
pString = pString->Next;
|
pString = pString->Next;
|
||||||
sscanf(pString->IpAddress.String,"%d.%d.%d.%d",&b[0],&b[1],&b[2],&b[3]);
|
dwIPAddr = inet_addr(pString->IpAddress.String);
|
||||||
dwIPAddr = b[0]<<24|b[1]<<16|b[2]<<8|b[3];
|
|
||||||
SendDlgItemMessage(hwndDlg,IDC_IPADDR,IPM_SETADDRESS,0,dwIPAddr);
|
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 = inet_addr(pString->IpMask.String);
|
||||||
dwIPAddr = b[0]<<24|b[1]<<16|b[2]<<8|b[3];
|
|
||||||
SendDlgItemMessage(hwndDlg,IDC_SUBNETMASK,IPM_SETADDRESS,0,dwIPAddr);
|
SendDlgItemMessage(hwndDlg,IDC_SUBNETMASK,IPM_SETADDRESS,0,dwIPAddr);
|
||||||
|
|
||||||
pString = &pInfo->GatewayList;
|
pString = &pInfo->GatewayList;
|
||||||
while(pString->Next)
|
while(pString->Next)
|
||||||
pString = pString->Next;
|
pString = pString->Next;
|
||||||
sscanf(pString->IpAddress.String,"%d.%d.%d.%d",&b[0],&b[1],&b[2],&b[3]);
|
dwIPAddr = inet_addr(pString->IpAddress.String);
|
||||||
dwIPAddr = b[0]<<24|b[1]<<16|b[2]<<8|b[3];
|
|
||||||
SendDlgItemMessage(hwndDlg,IDC_DEFGATEWAY,IPM_SETADDRESS,0,dwIPAddr);
|
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];
|
char pszDNS[MAX_PATH];
|
||||||
DWORD dwSize = sizeof(pszDNS);
|
DWORD dwSize = sizeof(pszDNS);
|
||||||
DWORD dwType = REG_SZ;
|
DWORD dwType = REG_SZ;
|
||||||
int b[2][4];
|
|
||||||
DWORD dwIPAddr;
|
DWORD dwIPAddr;
|
||||||
RegQueryValueExA(hKey,"NameServer",NULL,&dwType,(BYTE*)pszDNS,&dwSize);
|
RegQueryValueExA(hKey,"NameServer",NULL,&dwType,(BYTE*)pszDNS,&dwSize);
|
||||||
RegCloseKey(hKey);
|
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]);
|
NextDNSServer = pszDNS;
|
||||||
dwIPAddr = b[0][0]<<24|b[0][1]<<16|b[0][2]<<8|b[0][3];
|
|
||||||
SendDlgItemMessage(hwndDlg,IDC_DNS1,IPM_SETADDRESS,0,dwIPAddr);
|
while( NextDNSServer && StaticDNS < 2 ) {
|
||||||
dwIPAddr = b[1][0]<<24|b[1][1]<<16|b[1][2]<<8|b[1][3];
|
dwIPAddr = inet_addr(NextDNSServer);
|
||||||
SendDlgItemMessage(hwndDlg,IDC_DNS2,IPM_SETADDRESS,0,dwIPAddr);
|
if( dwIPAddr != INADDR_NONE ) {
|
||||||
CheckDlgButton(hwndDlg,IDC_FIXEDDNS,TRUE);
|
SendDlgItemMessage(hwndDlg,IDC_DNS1 + StaticDNS,IPM_SETADDRESS,0,dwIPAddr);
|
||||||
EnableWindow(GetDlgItem(hwndDlg,IDC_DNS1),FALSE);
|
StaticDNS++;
|
||||||
EnableWindow(GetDlgItem(hwndDlg,IDC_DNS2),FALSE);
|
}
|
||||||
EnableWindow(GetDlgItem(hwndDlg,IDC_AUTODNS),FALSE);
|
NextDNSServer = strchr( pszDNS, ',' );
|
||||||
EnableWindow(GetDlgItem(hwndDlg,IDC_FIXEDDNS),FALSE);
|
if( NextDNSServer )
|
||||||
|
NextDNSServer++;
|
||||||
|
}
|
||||||
|
|
||||||
|
ManualDNS( hwndDlg, StaticDNS );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -130,6 +220,27 @@ TCPIPPropertyPageProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
|
||||||
case WM_COMMAND:
|
case WM_COMMAND:
|
||||||
switch(LOWORD(wParam))
|
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;
|
break;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue