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.
Modified: trunk/reactos/lib/cpl/ncpa/ncpa.xml
Modified: trunk/reactos/lib/cpl/ncpa/tcpip_properties.c

Modified: trunk/reactos/lib/cpl/ncpa/ncpa.xml
--- trunk/reactos/lib/cpl/ncpa/ncpa.xml	2005-11-09 23:23:12 UTC (rev 19109)
+++ trunk/reactos/lib/cpl/ncpa/ncpa.xml	2005-11-10 06:12:27 UTC (rev 19110)
@@ -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>

Modified: trunk/reactos/lib/cpl/ncpa/tcpip_properties.c
--- trunk/reactos/lib/cpl/ncpa/tcpip_properties.c	2005-11-09 23:23:12 UTC (rev 19109)
+++ trunk/reactos/lib/cpl/ncpa/tcpip_properties.c	2005-11-10 06:12:27 UTC (rev 19110)
@@ -34,6 +34,7 @@
 #include <iptypes.h>
 #include <iphlpapi.h>
 #include <commctrl.h>
+#include <dhcpcapi.h>
 #include <prsht.h>
 
 
@@ -54,86 +55,196 @@
 
 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;
-	if(pPage)
-		pInfo = (IP_ADAPTER_INFO *)pPage->lParam;
-	switch(uMsg)
-	{
+    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)
+    {
     case WM_INITDIALOG:	
-		{
-			pPage = (PROPSHEETPAGE *)lParam;
-			pInfo = (IP_ADAPTER_INFO *)pPage->lParam;
-			EnableWindow(GetDlgItem(hwndDlg,IDC_ADVANCED),FALSE);
-			SetWindowLongPtr(hwndDlg,GWL_USERDATA,(DWORD_PTR)pPage->lParam);
+    {
+        pPage = (PROPSHEETPAGE *)lParam;
+        pInfo = (IP_ADAPTER_INFO *)pPage->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);
-			} 
-			{
-				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];
-				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];
-				SendDlgItemMessage(hwndDlg,IDC_SUBNETMASK,IPM_SETADDRESS,0,dwIPAddr);
+        EnableDHCP( hwndDlg, pInfo->DhcpEnabled );
 
-				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];
-				SendDlgItemMessage(hwndDlg,IDC_DEFGATEWAY,IPM_SETADDRESS,0,dwIPAddr);
+        {
+            DWORD dwIPAddr;
+            IP_ADDR_STRING *pString;
+            pString = &pInfo->IpAddressList;
+            while(pString->Next)
+                pString = pString->Next;
+            dwIPAddr = inet_addr(pString->IpAddress.String);
+            SendDlgItemMessage(hwndDlg,IDC_IPADDR,IPM_SETADDRESS,0,dwIPAddr);
+            dwIPAddr = inet_addr(pString->IpMask.String);
+            SendDlgItemMessage(hwndDlg,IDC_SUBNETMASK,IPM_SETADDRESS,0,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;
-					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);
-				}
-			}
-		}
-		break;
-	case WM_COMMAND:
-		switch(LOWORD(wParam))
-		{
-		}
-		break;
-	}
-	return FALSE;
+            pString = &pInfo->GatewayList;
+            while(pString->Next)
+                pString = pString->Next;
+            dwIPAddr = inet_addr(pString->IpAddress.String);
+            SendDlgItemMessage(hwndDlg,IDC_DEFGATEWAY,IPM_SETADDRESS,0,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 && 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 );
+            }
+        }
+    }
+    break;
+    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;
+    }
+    return FALSE;
 }
 
 void DisplayTCPIPProperties(HWND hParent,IP_ADAPTER_INFO *pInfo)