migrate substitution keywords to SVN
[reactos.git] / reactos / lib / cpl / ncpa / tcpip_properties.c
1 /*
2 * ReactOS
3 * Copyright (C) 2004 ReactOS Team
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18 */
19 /* $Id$
20 *
21 * PROJECT: ReactOS Network Control Panel
22 * FILE: lib/cpl/system/tcpip_properties.c
23 * PURPOSE: ReactOS Network Control Panel
24 * PROGRAMMER: Gero Kuehn (reactos.filter@gkware.com)
25 * UPDATE HISTORY:
26 * 08-15-2004 Created
27 */
28
29 #include <stdlib.h>
30 #include <stdio.h>
31 #include <stdarg.h>
32 #include <tchar.h>
33 #include <windows.h>
34 #include <iptypes.h>
35 #include <iphlpapi.h>
36 #include <commctrl.h>
37 #include <prsht.h>
38
39
40 #ifdef _MSC_VER
41 #include <cpl.h>
42 #else
43
44 // this is missing on reactos...
45 #ifndef IPM_SETADDRESS
46 #define IPM_SETADDRESS (WM_USER+101)
47 #endif
48
49 #endif
50
51
52 #include "resource.h"
53 #include "ncpa.h"
54
55 extern void InitPropSheetPage(PROPSHEETPAGE *psp, WORD idDlg, DLGPROC DlgProc);
56
57 INT_PTR CALLBACK
58 TCPIPPropertyPageProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
59 {
60 PROPSHEETPAGE *pPage = (PROPSHEETPAGE *)GetWindowLongPtr(hwndDlg,GWL_USERDATA);
61 IP_ADAPTER_INFO *pInfo = NULL;
62 if(pPage)
63 pInfo = (IP_ADAPTER_INFO *)pPage->lParam;
64 switch(uMsg)
65 {
66 case WM_INITDIALOG:
67 {
68 pPage = (PROPSHEETPAGE *)lParam;
69 pInfo = (IP_ADAPTER_INFO *)pPage->lParam;
70 EnableWindow(GetDlgItem(hwndDlg,IDC_ADVANCED),FALSE);
71 SetWindowLongPtr(hwndDlg,GWL_USERDATA,(DWORD_PTR)pPage->lParam);
72
73 if(pInfo->DhcpEnabled) {
74 CheckDlgButton(hwndDlg,IDC_USEDHCP,BST_CHECKED);
75 CheckDlgButton(hwndDlg,IDC_NODHCP,BST_UNCHECKED);
76 } else {
77 CheckDlgButton(hwndDlg,IDC_USEDHCP,BST_UNCHECKED);
78 CheckDlgButton(hwndDlg,IDC_NODHCP,BST_CHECKED);
79 }
80 {
81 DWORD dwIPAddr;
82 int b[4];
83 IP_ADDR_STRING *pString;
84 pString = &pInfo->IpAddressList;
85 while(pString->Next)
86 pString = pString->Next;
87 sscanf(pString->IpAddress.String,"%d.%d.%d.%d",&b[0],&b[1],&b[2],&b[3]);
88 dwIPAddr = b[0]<<24|b[1]<<16|b[2]<<8|b[3];
89 SendDlgItemMessage(hwndDlg,IDC_IPADDR,IPM_SETADDRESS,0,dwIPAddr);
90 sscanf(pString->IpMask.String,"%d.%d.%d.%d",&b[0],&b[1],&b[2],&b[3]);
91 dwIPAddr = b[0]<<24|b[1]<<16|b[2]<<8|b[3];
92 SendDlgItemMessage(hwndDlg,IDC_SUBNETMASK,IPM_SETADDRESS,0,dwIPAddr);
93
94 pString = &pInfo->GatewayList;
95 while(pString->Next)
96 pString = pString->Next;
97 sscanf(pString->IpAddress.String,"%d.%d.%d.%d",&b[0],&b[1],&b[2],&b[3]);
98 dwIPAddr = b[0]<<24|b[1]<<16|b[2]<<8|b[3];
99 SendDlgItemMessage(hwndDlg,IDC_DEFGATEWAY,IPM_SETADDRESS,0,dwIPAddr);
100
101 }
102 {
103 TCHAR pszRegKey[MAX_PATH];
104 HKEY hKey;
105 _stprintf(pszRegKey,_T("SYSTEM\\CurrentControlSet\\Services\\TCPIP\\Parameters\\Interfaces\\%S"),pInfo->AdapterName);
106 if(RegOpenKey(HKEY_LOCAL_MACHINE,pszRegKey,&hKey)==ERROR_SUCCESS)
107 {
108 char pszDNS[MAX_PATH];
109 DWORD dwSize = sizeof(pszDNS);
110 DWORD dwType = REG_SZ;
111 int b[2][4];
112 DWORD dwIPAddr;
113 RegQueryValueExA(hKey,"NameServer",NULL,&dwType,(BYTE*)pszDNS,&dwSize);
114 RegCloseKey(hKey);
115
116 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]);
117 dwIPAddr = b[0][0]<<24|b[0][1]<<16|b[0][2]<<8|b[0][3];
118 SendDlgItemMessage(hwndDlg,IDC_DNS1,IPM_SETADDRESS,0,dwIPAddr);
119 dwIPAddr = b[1][0]<<24|b[1][1]<<16|b[1][2]<<8|b[1][3];
120 SendDlgItemMessage(hwndDlg,IDC_DNS2,IPM_SETADDRESS,0,dwIPAddr);
121 CheckDlgButton(hwndDlg,IDC_FIXEDDNS,TRUE);
122 EnableWindow(GetDlgItem(hwndDlg,IDC_DNS1),FALSE);
123 EnableWindow(GetDlgItem(hwndDlg,IDC_DNS2),FALSE);
124 EnableWindow(GetDlgItem(hwndDlg,IDC_AUTODNS),FALSE);
125 EnableWindow(GetDlgItem(hwndDlg,IDC_FIXEDDNS),FALSE);
126 }
127 }
128 }
129 break;
130 case WM_COMMAND:
131 switch(LOWORD(wParam))
132 {
133 }
134 break;
135 }
136 return FALSE;
137 }
138
139 void DisplayTCPIPProperties(HWND hParent,IP_ADAPTER_INFO *pInfo)
140 {
141 PROPSHEETPAGE psp[1];
142 PROPSHEETHEADER psh;
143 INITCOMMONCONTROLSEX cce;
144
145 cce.dwSize = sizeof(INITCOMMONCONTROLSEX);
146 cce.dwICC = ICC_INTERNET_CLASSES;
147 InitCommonControlsEx(&cce);
148
149 ZeroMemory(&psh, sizeof(PROPSHEETHEADER));
150 psh.dwSize = sizeof(PROPSHEETHEADER);
151 psh.dwFlags = PSH_PROPSHEETPAGE | PSH_NOAPPLYNOW;
152 psh.hwndParent = hParent;
153 psh.hInstance = hApplet;
154 psh.hIcon = LoadIcon(hApplet, MAKEINTRESOURCE(IDI_CPLSYSTEM));
155 psh.pszCaption = NULL;//Caption;
156 psh.nPages = sizeof(psp) / sizeof(PROPSHEETPAGE);
157 psh.nStartPage = 0;
158 psh.ppsp = psp;
159 psh.pfnCallback = NULL;
160
161
162 InitPropSheetPage(&psp[0], IDD_TCPIPPROPERTIES, TCPIPPropertyPageProc);
163 psp[0].lParam = (LPARAM)pInfo;
164
165 if (PropertySheet(&psh) == -1)
166 {
167 MessageBox(hParent,_T("Unable to create property sheet"),_T("Error"),MB_ICONSTOP);
168 }
169
170 return;
171 }