ReactOS 0.4.15-dev-6694-g4ba8af9
tcpipconf_notify.c
Go to the documentation of this file.
1#include "precomp.h"
2
3#include <winnls.h>
4#include <winsock.h>
5#include <iphlpapi.h>
6#include <dhcpcsdk.h>
7#include <dhcpcapi.h>
8
9typedef struct
10{
12 LPWSTR szTCPAllowedPorts; // KEY: Tcpip\Parameter\{InstanceGuid}\TCPAllowedPorts
13 LPWSTR szUDPAllowedPorts; // KEY: Tcpip\Parameter\{InstanceGuid}\UDPAllowedPorts
14 LPWSTR szRawIPAllowedProtocols; // KEY: Tcpip\Parameter\{InstanceGuid}\RawIPAllowedProtocols
19
20// KEY: Tcpip\Parameter\{InstanceGuid}\IpAddress | DhcpIpAddress
21// KEY: Tcpip\Parameter\{InstanceGuid}\SubnetMask | DhcpSubnetMask
22// KEY: Tcpip\Parameter\{InstanceGuid}\DefaultGateway | DhcpDefaultGateway
23// KEY: Tcpip\Parameter\{InstanceGuid}\NameServer | DhcpNameServer
24// KEY: Services\NetBT\Parameters\Interfaces\Tcpip_{INSTANCE_GUID}
25
26typedef struct
27{
31 WCHAR szDomain[100];
34
35typedef struct tagIP_ADDR
36{
38 union
39 {
42 }u;
44 struct tagIP_ADDR * Next;
46
47typedef enum
48{
49 METRIC = 1,
51 IPADDR = 3
53
54typedef struct
55{
59
66
67typedef struct
68{
69 const INetCfgComponentPropertyUi * lpVtbl;
70 const INetCfgComponentControl * lpVtblCompControl;
73 INetCfg * pNCfg;
74 INetCfgComponent * pNComp;
78
79typedef struct
80{
83 WCHAR szIP[16];
86
87typedef struct
88{
91 WCHAR szIP[16];
92 WCHAR szMask[16];
94
95typedef struct
96{
99 WCHAR szIP[16];
101
102typedef struct
103{
108
109typedef struct
110{
115
116static __inline LPTcpipConfNotifyImpl impl_from_INetCfgComponentControl(INetCfgComponentControl *iface)
117{
118 return (TcpipConfNotifyImpl*)((char *)iface - FIELD_OFFSET(TcpipConfNotifyImpl, lpVtblCompControl));
119}
120
121INT GetSelectedItem(HWND hDlgCtrl);
123VOID InsertColumnToListView(HWND hDlgCtrl, UINT ResId, UINT SubItem, UINT Size);
127
128VOID
129DisplayError(UINT ResTxt, UINT ResTitle, UINT Type)
130{
131 WCHAR szBuffer[300];
132 WCHAR szTitle[100];
133
134 if (LoadStringW(netcfgx_hInstance, ResTxt, szBuffer, sizeof(szBuffer)/sizeof(WCHAR)))
135 szBuffer[(sizeof(szBuffer)/sizeof(WCHAR))-1] = L'\0';
136 else
137 szBuffer[0] = L'\0';
138
139 if (LoadStringW(netcfgx_hInstance, ResTitle, szTitle, sizeof(szTitle)/sizeof(WCHAR)))
140 szTitle[(sizeof(szTitle)/sizeof(WCHAR))-1] = L'\0';
141 else
142 szTitle[0] = L'\0';
143
144 MessageBoxW(NULL, szBuffer, szTitle, Type);
145}
146
147
148/***************************************************************
149 * TCP/IP Filter Dialog
150 *
151 */
152
156 HWND hwndDlg,
157 UINT uMsg,
160)
161{
162 TcpipPortSettings * pPort;
163 UINT Num;
165 LVITEMW li;
166 WCHAR szBuffer[100];
167
168 switch(uMsg)
169 {
170 case WM_INITDIALOG:
171 pPort = (TcpipPortSettings*)lParam;
172 SetWindowLongPtr(hwndDlg, DWLP_USER, (LONG_PTR)pPort);
173 if (LoadStringW(netcfgx_hInstance, pPort->ResId, szBuffer, sizeof(szBuffer)/sizeof(WCHAR)))
174 {
175 szBuffer[(sizeof(szBuffer)/sizeof(WCHAR))-1] = L'\0';
176 SendDlgItemMessageW(hwndDlg, IDC_PORT_DESC, WM_SETTEXT, 0, (LPARAM)szBuffer);
177 }
178
179 if (pPort->MaxNum == 65536)
181 else
183
184 return TRUE;
185 case WM_COMMAND:
186 if (LOWORD(wParam) == IDCANCEL)
187 {
188 EndDialog(hwndDlg, FALSE);
189 break;
190 }
191 else if (LOWORD(wParam) == IDC_OK)
192 {
193 pPort = (TcpipPortSettings*)GetWindowLongPtr(hwndDlg, DWLP_USER);
194 Num = GetDlgItemInt(hwndDlg, IDC_PORT_VAL, NULL, TRUE);
195 if (Num > pPort->MaxNum || Num == 0)
196 {
197 if (pPort->MaxNum == 65536)
199 else
201
203 break;
204 }
205 if (GetWindowTextW(GetDlgItem(hwndDlg, IDC_PORT_VAL), szBuffer, sizeof(szBuffer)/sizeof(WCHAR)))
206 {
207 szBuffer[(sizeof(szBuffer)/sizeof(WCHAR))-1] = L'\0';
208 ZeroMemory(&find, sizeof(LVFINDINFOW));
209 find.flags = LVFI_STRING;
210 find.psz = szBuffer;
211 if (SendMessageW(pPort->hDlgCtrl, LVM_FINDITEMW, (WPARAM)-1, (LPARAM)&find) == -1)
212 {
213 ZeroMemory(&li, sizeof(LVITEMW));
214 li.mask = LVIF_TEXT;
215 li.iItem = ListView_GetItemCount(pPort->hDlgCtrl);
216 li.pszText = szBuffer;
217 SendMessageW(pPort->hDlgCtrl, LVM_INSERTITEMW, 0, (LPARAM)&li);
218 EndDialog(hwndDlg, TRUE);
219 break;
220 }
223 break;
224 }
225 }
226 }
227 return FALSE;
228}
229
230VOID
231InitFilterListBox(LPWSTR pData, HWND hwndDlg, HWND hDlgCtrl, UINT AllowButton, UINT RestrictButton, UINT AddButton, UINT DelButton)
232{
233 LVITEMW li;
234 LPWSTR pCur;
235 INT iItem;
236
237 if (!pData || !_wtoi(pData))
238 {
239 SendDlgItemMessageW(hwndDlg, AllowButton, BM_SETCHECK, BST_CHECKED, 0);
241 EnableWindow(GetDlgItem(hwndDlg, DelButton), FALSE);
242 return;
243 }
244
245 pCur = pData;
246 memset(&li, 0x0, sizeof(LVITEMW));
247 li.mask = LVIF_TEXT;
248 iItem = 0;
249
250 while(pCur[0])
251 {
252 li.pszText = pCur;
253 li.iItem = iItem;
254 SendMessageW(hDlgCtrl, LVM_INSERTITEMW, 0, (LPARAM)&li);
255 iItem++;
256 pCur += wcslen(pCur) + 1;
257 }
258
259 if (!iItem)
260 SendDlgItemMessageW(hwndDlg, AllowButton, BM_SETCHECK, BST_CHECKED, 0);
261 else
262 SendDlgItemMessageW(hwndDlg, RestrictButton, BM_SETCHECK, BST_CHECKED, 0);
263}
264
265LPWSTR
267 HWND hDlgCtrl,
269{
270 INT iCount, iIndex;
271 LVITEMW li;
274 WCHAR szBuffer[10];
275
276 iCount = ListView_GetItemCount(hDlgCtrl);
277 if (!iCount)
278 {
279 pData = (LPWSTR)CoTaskMemAlloc(3 * sizeof(WCHAR));
280 if (!pData)
281 return NULL;
282 pData[0] = L'0';
283 pData[1] = L'\0';
284 pData[2] = L'\0';
285 *Size = 3 * sizeof(WCHAR);
286 return pData;
287 }
288
289 pData = CoTaskMemAlloc((6 * iCount + 1) * sizeof(WCHAR));
290 if (!pData)
291 return NULL;
292
293 pCur = pData;
294 dwSize = 0;
295 for(iIndex = 0; iIndex < iCount; iIndex++)
296 {
297 ZeroMemory(&li, sizeof(LVITEMW));
298 li.mask = LVIF_TEXT;
299 li.iItem = iIndex;
300 li.pszText = szBuffer;
301 li.cchTextMax = sizeof(szBuffer) /sizeof(WCHAR);
302 if (SendMessageW(hDlgCtrl, LVM_GETITEMW, 0, (LPARAM)&li))
303 {
304 wcscpy(pCur, szBuffer);
305 dwSize += wcslen(szBuffer) + 1;
306 pCur += wcslen(szBuffer) + 1;
307 }
308 }
309 pCur[0] = L'\0';
310 *Size = (dwSize+1) * sizeof(WCHAR);
311 return pData;
312}
313
316 HWND hwndDlg)
317{
318 TcpFilterSettings * pFilter;
319
320 pFilter = CoTaskMemAlloc(sizeof(TcpFilterSettings));
321 if (!pFilter)
322 return NULL;
323
325 pFilter->EnableSecurityFilters = TRUE;
326 else
327 pFilter->EnableSecurityFilters = FALSE;
328
329 pFilter->szTCPAllowedPorts = CreateFilterList(GetDlgItem(hwndDlg, IDC_TCP_LIST), &pFilter->TCPSize);
330 pFilter->szUDPAllowedPorts = CreateFilterList(GetDlgItem(hwndDlg, IDC_UDP_LIST), &pFilter->UDPSize);
332
333 return pFilter;
334}
335
336static
337VOID
339 HWND hwndDlg,
340 HWND hDlgCtrl,
341 UINT MaxItem,
342 UINT ResId)
343{
345
346 Port.MaxNum = MaxItem;
347 Port.hDlgCtrl = hDlgCtrl;
348 Port.ResId = ResId;
349
351}
352
353static
354VOID
356 HWND hDlgCtrl)
357{
358 INT iIndex = GetSelectedItem(hDlgCtrl);
359
360 if (iIndex != -1)
361 {
362 (void)ListView_DeleteItem(hDlgCtrl, iIndex);
363 return;
364 }
366}
367
371 HWND hwndDlg,
372 UINT uMsg,
375)
376{
377 TcpipConfNotifyImpl *pContext;
378 TcpFilterSettings *pFilter;
379
380 switch(uMsg)
381 {
382 case WM_INITDIALOG:
383 pContext = (TcpipConfNotifyImpl*)lParam;
387 if (pContext->pCurrentConfig->pFilter)
388 {
394 }
395 SetWindowLongPtr(hwndDlg, DWLP_USER, (LONG_PTR)pContext);
396 return TRUE;
397 case WM_COMMAND:
398 if (HIWORD(wParam) == BN_CLICKED)
399 {
400 switch (LOWORD(wParam))
401 {
404 {
409 }
410 break;
411 case IDC_TCP_RESTRICT:
413 {
418 }
419 break;
422 {
427 }
428 break;
429 case IDC_UDP_RESTRICT:
431 {
436 }
437 break;
438 case IDC_IP_ALLOW_ALL:
440 {
445 }
446 break;
447 case IDC_IP_RESTRICT:
449 {
454 }
455 break;
456 case IDC_USE_FILTER:
459
460 break;
461 }
462 }
463 switch(LOWORD(wParam))
464 {
465 case IDC_OK:
466 pContext = (TcpipConfNotifyImpl*)GetWindowLongPtr(hwndDlg, DWLP_USER);
467 pFilter = StoreTcpipFilterSettings(hwndDlg);
468 if (pFilter)
469 {
470 if (pContext->pCurrentConfig->pFilter)
471 {
472 CoTaskMemFree(pContext->pCurrentConfig->pFilter->szTCPAllowedPorts);
473 CoTaskMemFree(pContext->pCurrentConfig->pFilter->szUDPAllowedPorts);
474 CoTaskMemFree(pContext->pCurrentConfig->pFilter->szRawIPAllowedProtocols);
475 CoTaskMemFree(pContext->pCurrentConfig->pFilter);
476 }
477 pContext->pCurrentConfig->pFilter = pFilter;
478 }
479 EndDialog(hwndDlg, (INT_PTR)TRUE);
480 break;
481 case IDCANCEL:
482 EndDialog(hwndDlg, FALSE);
483 break;
484 case IDC_TCP_ADD:
485 AddItem(hwndDlg, GetDlgItem(hwndDlg, IDC_TCP_LIST), 65536, IDS_TCP_PORTS);
486 break;
487 case IDC_TCP_DEL:
489 break;
490 case IDC_UDP_ADD:
491 AddItem(hwndDlg, GetDlgItem(hwndDlg, IDC_UDP_LIST), 65536, IDS_UDP_PORTS);
492 break;
493 case IDC_UDP_DEL:
495 break;
496 case IDC_IP_ADD:
497 AddItem(hwndDlg, GetDlgItem(hwndDlg, IDC_IP_LIST), 256, IDS_IP_PROTO);
498 break;
499 case IDC_IP_DEL:
500 DelItem(GetDlgItem(hwndDlg, IDC_IP_LIST));
501 break;
502 default:
503 break;
504 }
505 default:
506 break;
507 }
508
509 return FALSE;
510}
511
512
515{
516 PROPSHEETPAGEW ppage;
517
518 memset(&ppage, 0x0, sizeof(PROPSHEETPAGEW));
519 ppage.dwSize = sizeof(PROPSHEETPAGEW);
520 ppage.dwFlags = PSP_DEFAULT;
521 ppage.u.pszTemplate = resname;
522 ppage.pfnDlgProc = dlgproc;
523 ppage.lParam = lParam;
525 if (szTitle)
526 {
527 ppage.dwFlags |= PSP_USETITLE;
528 ppage.pszTitle = szTitle;
529 }
530 return CreatePropertySheetPageW(&ppage);
531}
532
533/***************************************************************
534 * TCP/IP Advanced Option Dialog
535 *
536 */
537
538VOID
540 HWND hwndDlg,
542{
543 WCHAR szText[500];
544 /* store context */
546
547 if (LoadStringW(netcfgx_hInstance, IDS_TCPFILTER, szText, sizeof(szText)/sizeof(WCHAR)))
548 {
549 szText[(sizeof(szText)/sizeof(WCHAR))-1] = L'\0';
550 if (SendDlgItemMessageW(hwndDlg, IDC_OPTLIST, LB_ADDSTRING, 0, (LPARAM)szText) != LB_ERR)
552 }
553
554 if (LoadStringW(netcfgx_hInstance, IDS_TCPFILTERDESC, szText, sizeof(szText)/sizeof(WCHAR)))
555 {
556 szText[(sizeof(szText)/sizeof(WCHAR))-1] = L'\0';
557 SendDlgItemMessageW(hwndDlg, IDC_OPTDESC, WM_SETTEXT, 0, (LPARAM)szText);
558 }
559}
560
561
562
566 HWND hwndDlg,
567 UINT uMsg,
570)
571{
574
575 switch(uMsg)
576 {
577 case WM_INITDIALOG:
579 This = (TcpipConfNotifyImpl*)page->lParam;
581 return TRUE;
582 case WM_COMMAND:
583 if (LOWORD(wParam) == IDC_OPTPROP)
584 {
587 GetParent(hwndDlg),
590 break;
591 }
592 }
593 return FALSE;
594}
595
596VOID
598 HWND hDlgCtrl,
599 UINT ResId,
600 UINT SubItem,
601 UINT Size)
602{
603 WCHAR szBuffer[200];
604 LVCOLUMNW lc;
605
606 if (!LoadStringW(netcfgx_hInstance, ResId, szBuffer, sizeof(szBuffer)/sizeof(WCHAR)))
607 return;
608
609 memset(&lc, 0, sizeof(LV_COLUMN) );
611 lc.iSubItem = SubItem;
612 lc.fmt = LVCFMT_FIXED_WIDTH;
613 lc.cx = Size;
614 lc.cchTextMax = wcslen(szBuffer);
615 lc.pszText = szBuffer;
616
617 (void)SendMessageW(hDlgCtrl, LVM_INSERTCOLUMNW, SubItem, (LPARAM)&lc);
618}
619
620VOID
622 HWND hDlgCtrl,
623 IP_ADDR * pAddr,
624 BOOL bSubMask)
625{
626 WCHAR szBuffer[70];
627 DWORD dwIpAddr;
628 UINT itemCount = 0;
629 LVITEMW li;
630
631 while(pAddr)
632 {
633 ZeroMemory(&li, sizeof(li));
634 li.mask = LVIF_TEXT;
635 li.iItem = itemCount;
636 li.iSubItem = 0;
637 dwIpAddr = pAddr->IpAddress;
638 swprintf(szBuffer, L"%lu.%lu.%lu.%lu",
639 FIRST_IPADDRESS(dwIpAddr), SECOND_IPADDRESS(dwIpAddr), THIRD_IPADDRESS(dwIpAddr), FOURTH_IPADDRESS(dwIpAddr));
640
641 li.pszText = szBuffer;
642 li.iItem = SendMessageW(hDlgCtrl, LVM_INSERTITEMW, 0, (LPARAM)&li);
643 if (li.iItem != -1)
644 {
645 if (bSubMask)
646 {
647 dwIpAddr = pAddr->u.Subnetmask;
648 swprintf(szBuffer, L"%lu.%lu.%lu.%lu",
649 FIRST_IPADDRESS(dwIpAddr), SECOND_IPADDRESS(dwIpAddr), THIRD_IPADDRESS(dwIpAddr), FOURTH_IPADDRESS(dwIpAddr));
650 }
651 else
652 {
653 if (pAddr->u.Metric)
654 swprintf(szBuffer, L"%u", pAddr->u.Metric);
655 else
656 LoadStringW(netcfgx_hInstance, IDS_AUTOMATIC, szBuffer, sizeof(szBuffer)/sizeof(WCHAR));
657 }
658
659 li.mask = LVIF_TEXT;
660 li.iSubItem = 1;
661 li.pszText = szBuffer;
662 SendMessageW(hDlgCtrl, LVM_SETITEMW, 0, (LPARAM)&li);
663 }
664 itemCount++;
665 pAddr = pAddr->Next;
666 }
667}
668
669VOID
671 HWND hwndDlg,
673{
674 RECT rect;
675 LVITEMW li;
676 WCHAR szBuffer[100];
677
680 InsertColumnToListView(GetDlgItem(hwndDlg, IDC_IPLIST), IDS_SUBMASK, 1, (rect.right - rect.left - 100));
681
682 if (This->pCurrentConfig->DhcpEnabled)
683 {
684 if (LoadStringW(netcfgx_hInstance, IDS_DHCPACTIVE, szBuffer, sizeof(szBuffer)/sizeof(WCHAR)))
685 {
686 ZeroMemory(&li, sizeof(LVITEMW));
687 li.mask = LVIF_TEXT;
688 li.pszText = szBuffer;
690 }
692 }
693 else
694 {
695 InsertIpAddressToListView(GetDlgItem(hwndDlg, IDC_IPLIST), This->pCurrentConfig->Ip, TRUE);
696 }
697
700
703 InsertColumnToListView(GetDlgItem(hwndDlg, IDC_GWLIST), IDS_METRIC, 1, (rect.right - rect.left - 100));
704
705 InsertIpAddressToListView(GetDlgItem(hwndDlg, IDC_GWLIST), This->pCurrentConfig->Gw, FALSE);
706
709
711}
712
716 HWND hwndDlg,
717 UINT uMsg,
720)
721{
722 WCHAR szBuffer[70];
723 TcpipGwSettings *pGwSettings;
724 DWORD dwIpAddr;
725 LPNMIPADDRESS lpnmipa;
727
728 switch(uMsg)
729 {
730 case WM_INITDIALOG:
731 pGwSettings = (TcpipGwSettings *)lParam;
733
738
739 if (pGwSettings->bAdd)
740 {
741 if (LoadStringW(netcfgx_hInstance, IDS_ADD, szBuffer, sizeof(szBuffer)/sizeof(WCHAR)))
742 {
743 szBuffer[(sizeof(szBuffer)/sizeof(WCHAR))-1] = L'\0';
744 SendDlgItemMessageW(hwndDlg, IDC_OK, WM_SETTEXT, 0, (LPARAM)szBuffer);
745 }
748 }
749 else
750 {
751 if (LoadStringW(netcfgx_hInstance, IDS_MOD, szBuffer, sizeof(szBuffer)/sizeof(WCHAR)))
752 {
753 szBuffer[(sizeof(szBuffer)/sizeof(WCHAR))-1] = L'\0';
754 SendDlgItemMessageW(hwndDlg, IDC_OK, WM_SETTEXT, 0, (LPARAM)szBuffer);
755 }
756
758
759 if (pGwSettings->Metric)
760 {
761 SetDlgItemInt(hwndDlg, IDC_METRIC, pGwSettings->Metric, FALSE);
764 }
765 else
766 {
770 }
771 }
772 return TRUE;
773 case WM_COMMAND:
775 {
777 {
781 }
782 else
783 {
786 }
787 break;
788 }
789 else if (LOWORD(wParam) == IDCANCEL)
790 {
791 EndDialog(hwndDlg, FALSE);
792 break;
793 }
794 else if (LOWORD(wParam) == IDC_OK)
795 {
796 if (SendDlgItemMessageW(hwndDlg, IDC_IPADDR, IPM_GETADDRESS, 0, (LPARAM)&dwIpAddr) == 4)
797 {
798 pGwSettings = (TcpipGwSettings*)GetWindowLongPtr(hwndDlg, DWLP_USER);
799 SendDlgItemMessageW(hwndDlg, IDC_IPADDR, WM_GETTEXT, 16, (LPARAM)pGwSettings->szIP);
800
801 ZeroMemory(&find, sizeof(LVFINDINFOW));
802 find.flags = LVFI_STRING;
803 find.psz = pGwSettings->szIP;
804
806 pGwSettings->Metric = GetDlgItemInt(hwndDlg, IDC_METRIC, NULL, FALSE);
807 else
808 pGwSettings->Metric = 0;
809
810
811 if (SendMessageW(pGwSettings->hDlgCtrl, LVM_FINDITEMW, (WPARAM)-1, (LPARAM)&find) == -1)
812 {
813 EndDialog(hwndDlg, TRUE);
814 break;
815 }
816 if (!pGwSettings->bAdd)
817 {
818 EndDialog(hwndDlg, FALSE);
819 break;
820 }
822 }
823 break;
824 }
825 break;
826 case WM_NOTIFY:
827 lpnmipa = (LPNMIPADDRESS) lParam;
828 if (lpnmipa->hdr.code == IPN_FIELDCHANGED)
829 {
830 if (lpnmipa->hdr.idFrom == IDC_IPADDR)
831 {
832 if (SendDlgItemMessageW(hwndDlg, IDC_IPADDR, IPM_GETADDRESS, 0, (LPARAM)&dwIpAddr) == 4)
834 }
835 }
836 break;
837 }
838 return FALSE;
839}
840
841BOOL
842GetGWListEntry(HWND hDlgCtrl, INT Index, TcpipGwSettings * pGwSettings)
843{
844 LVITEMW li;
845 WCHAR szBuffer[30];
846 BOOL bRet;
847
848 ZeroMemory(&li, sizeof(LVITEMW));
849 li.mask = LVIF_TEXT;
850 li.cchTextMax = 16;
851 li.pszText = pGwSettings->szIP;
852 li.iItem = Index;
853
854 if (!SendMessageW(hDlgCtrl, LVM_GETITEMW, 0, (LPARAM)&li))
855 return FALSE;
856 li.pszText = szBuffer;
857 li.cchTextMax = 30;
858 li.iSubItem = 1;
859
860 bRet = SendMessageW(hDlgCtrl, LVM_GETITEMW, 0, (LPARAM)&li);
861 if (bRet)
862 {
863 pGwSettings->Metric = _wtoi(szBuffer);
864 }
865
866 return bRet;
867}
868
872 HWND hwndDlg,
873 UINT uMsg,
876)
877{
878 LPNMIPADDRESS lpnmipa;
879 DWORD dwIpAddr;
880 TcpipIpSettings *pIpSettings;
881 WCHAR szBuffer[50];
883 LRESULT lResult;
884
885 switch(uMsg)
886 {
887 case WM_INITDIALOG:
888 pIpSettings = (TcpipIpSettings*)lParam;
890
899
900 if (pIpSettings->bAdd)
901 {
902 if (LoadStringW(netcfgx_hInstance, IDS_ADD, szBuffer, sizeof(szBuffer)/sizeof(WCHAR)))
903 {
904 szBuffer[(sizeof(szBuffer)/sizeof(WCHAR))-1] = L'\0';
905 SendDlgItemMessageW(hwndDlg, IDC_OK, WM_SETTEXT, 0, (LPARAM)szBuffer);
906 }
908 }
909 else
910 {
911 if (LoadStringW(netcfgx_hInstance, IDS_MOD, szBuffer, sizeof(szBuffer)/sizeof(WCHAR)))
912 {
913 szBuffer[(sizeof(szBuffer)/sizeof(WCHAR))-1] = L'\0';
914 SendDlgItemMessageW(hwndDlg, IDC_OK, WM_SETTEXT, 0, (LPARAM)szBuffer);
915 }
916
919 }
920 return TRUE;
921 case WM_NOTIFY:
922 lpnmipa = (LPNMIPADDRESS) lParam;
923 if (lpnmipa->hdr.code == IPN_FIELDCHANGED)
924 {
925 if (lpnmipa->hdr.idFrom == IDC_IPADDR)
926 {
927 if (SendDlgItemMessageW(hwndDlg, IDC_IPADDR, IPM_GETADDRESS, 0, (LPARAM)&dwIpAddr) == 4)
928 {
929 if (dwIpAddr <= MAKEIPADDRESS(127, 255, 255, 255))
931 else if (dwIpAddr <= MAKEIPADDRESS(191, 255, 255, 255))
933 else if (dwIpAddr <= MAKEIPADDRESS(223, 255, 255, 255))
934 SendDlgItemMessageW(hwndDlg, IDC_SUBNETMASK, IPM_SETADDRESS, 0, (LPARAM)MAKEIPADDRESS(255, 255, 255, 0));
936 }
937 }
938 }
939 break;
940 case WM_COMMAND:
941 if (LOWORD(wParam) == IDC_OK)
942 {
943 pIpSettings = (TcpipIpSettings*)GetWindowLongPtr(hwndDlg, DWLP_USER);
944 SendDlgItemMessageW(hwndDlg, IDC_IPADDR, WM_GETTEXT, 16, (LPARAM)pIpSettings->szIP);
945 SendDlgItemMessageW(hwndDlg, IDC_SUBNETMASK, WM_GETTEXT, 16, (LPARAM)pIpSettings->szMask);
946
947 ZeroMemory(&find, sizeof(LVFINDINFOW));
948 find.flags = LVFI_STRING;
949 find.psz = pIpSettings->szIP;
950 lResult = SendMessageW(pIpSettings->hDlgCtrl, LVM_FINDITEMW, (WPARAM)-1, (LPARAM)&find);
951
952 if (lResult == -1)
953 {
954 EndDialog(hwndDlg, TRUE);
955 break;
956 }
957 else if (!pIpSettings->bAdd)
958 {
959 EndDialog(hwndDlg, FALSE);
960 break;
961 }
963 break;
964 }
965 else if (LOWORD(wParam) == IDCANCEL)
966 {
967 EndDialog(hwndDlg, FALSE);
968 }
969 break;
970 }
971 return FALSE;
972}
973
974BOOL
977{
978 UINT Index;
980
981 for(Index = 0; Index < Length; Index++)
982 if (iswalnum(szName[Index]) == 0 && szName[Index] != '.' && szName[Index] != '-')
983 return FALSE;
984
985 return TRUE;
986}
987
991 HWND hwndDlg,
992 UINT uMsg,
995)
996{
997 WCHAR szBuffer[100];
998 TcpipSuffixSettings * pSettings;
999 LRESULT lLength;
1000
1001 switch(uMsg)
1002 {
1003 case WM_INITDIALOG:
1004 pSettings = (TcpipSuffixSettings*)lParam;
1005 if (!pSettings->bAdd)
1006 {
1007 SendDlgItemMessageW(hwndDlg, IDC_SUFFIX, WM_SETTEXT, 0, (LPARAM)pSettings->Suffix);
1008 if (LoadStringW(netcfgx_hInstance, IDS_MOD, szBuffer, sizeof(szBuffer)/sizeof(WCHAR)))
1009 {
1010 szBuffer[(sizeof(szBuffer)/sizeof(WCHAR))-1] = L'\0';
1011 SendDlgItemMessageW(hwndDlg, IDC_OK, WM_SETTEXT, 0, (LPARAM)szBuffer);
1012 }
1013 CoTaskMemFree(pSettings->Suffix);
1014 pSettings->Suffix = NULL;
1015 }
1016 else
1017 {
1018 if (LoadStringW(netcfgx_hInstance, IDS_ADD, szBuffer, sizeof(szBuffer)/sizeof(WCHAR)))
1019 {
1020 szBuffer[(sizeof(szBuffer)/sizeof(WCHAR))-1] = L'\0';
1021 SendDlgItemMessageW(hwndDlg, IDC_OK, WM_SETTEXT, 0, (LPARAM)szBuffer);
1022 }
1023 }
1024 SetWindowLongPtr(hwndDlg, DWLP_USER, (LONG_PTR)pSettings);
1025 return TRUE;
1026 case WM_COMMAND:
1027 if (LOWORD(wParam) == IDCANCEL)
1028 {
1029 EndDialog(hwndDlg, FALSE);
1030 break;
1031 }
1032 else if (LOWORD(wParam) == IDC_OK)
1033 {
1034 lLength = SendDlgItemMessageW(hwndDlg, IDC_SUFFIX, WM_GETTEXTLENGTH, 0, 0);
1035 if (lLength)
1036 {
1037 pSettings = (TcpipSuffixSettings*) GetWindowLongPtr(hwndDlg, DWLP_USER);
1038 pSettings->Suffix = (LPWSTR)CoTaskMemAlloc((lLength + 1)* sizeof(WCHAR));
1039 if (pSettings->Suffix)
1040 {
1041 SendDlgItemMessageW(hwndDlg, IDC_SUFFIX, WM_GETTEXT, lLength + 1, (LPARAM)pSettings->Suffix);
1042 if (SendMessageW(pSettings->hDlgCtrl, LB_FINDSTRING, 0, (LPARAM)pSettings->Suffix) != LB_ERR)
1043 {
1045 CoTaskMemFree(pSettings->Suffix);
1046 break;
1047 }
1048
1049 if (!VerifyDNSSuffix(pSettings->Suffix))
1050 {
1052 CoTaskMemFree(pSettings->Suffix);
1053 break;
1054 }
1055 EndDialog(hwndDlg, TRUE);
1056 }
1057 }
1058 break;
1059 }
1060 }
1061 return FALSE;
1062}
1063
1064
1065INT
1067{
1068 LVITEMW li;
1069 UINT iItemCount, iIndex;
1070
1071 iItemCount = ListView_GetItemCount(hDlgCtrl);
1072 if (!iItemCount)
1073 return -1;
1074
1075 for (iIndex = 0; iIndex < iItemCount; iIndex++)
1076 {
1077 ZeroMemory(&li, sizeof(LVITEMW));
1078 li.mask = LVIF_STATE;
1079 li.stateMask = (UINT)-1;
1080 li.iItem = iIndex;
1081 if (SendMessageW(hDlgCtrl, LVM_GETITEMW, 0, (LPARAM)&li))
1082 {
1083 if (li.state & LVIS_SELECTED)
1084 return iIndex;
1085 }
1086 }
1087 return -1;
1088}
1089
1090
1091BOOL
1093{
1094 LVITEMW li;
1095
1096 ZeroMemory(&li, sizeof(LVITEMW));
1097 li.mask = LVIF_TEXT;
1098 li.cchTextMax = 16;
1099 li.pszText = pIpSettings->szIP;
1100 li.iItem = Index;
1101
1102 if (!SendMessageW(hDlgCtrl, LVM_GETITEMW, 0, (LPARAM)&li))
1103 return FALSE;
1104
1105 ZeroMemory(&li, sizeof(LVITEMW));
1106 li.mask = LVIF_TEXT;
1107 li.cchTextMax = 16;
1108 li.pszText = pIpSettings->szMask;
1109 li.iSubItem = 1;
1110 li.iItem = Index;
1111
1112 return SendMessageW(hDlgCtrl, LVM_GETITEMW, 0, (LPARAM)&li);
1113}
1114
1115VOID
1117{
1118 LVITEMW li;
1119
1120 memset(&li, 0x0, sizeof(LVITEMW));
1121 li.iItem = GetSelectedItem(hDlgCtrl);
1122 if (li.iItem < 0)
1123 {
1125 SetFocus(hDlgCtrl);
1126 }
1127 else
1128 {
1129 (void)ListView_DeleteItem(hDlgCtrl, li.iItem);
1130 }
1131}
1132
1133UINT
1135 WCHAR * szBuffer)
1136{
1137 DWORD dwIpAddr = 0;
1138 INT Val;
1139 UINT Index = 3;
1140 LPWSTR pLast = szBuffer;
1141 LPWSTR pNext = szBuffer;
1142
1143
1144 while((pNext = wcschr(pNext, L'.')))
1145 {
1146 pNext[0] = L'\0';
1147 Val = _wtoi(pLast);
1148 dwIpAddr |= (Val << Index * 8);
1149 Index--;
1150 pNext++;
1151 pLast = pNext;
1152 }
1153 dwIpAddr |= _wtoi(pLast);
1154
1155 return dwIpAddr;
1156}
1157
1158UINT
1160 char * sBuffer)
1161{
1162 WCHAR szIp[16];
1163
1164 if (MultiByteToWideChar(CP_ACP, 0, sBuffer, -1, szIp, 16))
1165 {
1166 szIp[15] = L'\0';
1167 return GetIpAddressFromStringW(szIp);
1168 }
1169 return (UINT)-1;
1170}
1171
1172
1173VOID
1175{
1176 IP_ADDR *pNext;
1177
1178 if (!pAddr)
1179 return;
1180
1181 while(pAddr)
1182 {
1183 pNext = pAddr->Next;
1185 pAddr = pNext;
1186 }
1187}
1188
1189BOOL
1190GetListViewItem(HWND hDlgCtrl, UINT Index, UINT SubIndex, WCHAR * szBuffer, UINT BufferSize)
1191{
1192 LVITEMW li;
1193
1194 ZeroMemory(&li, sizeof(LVITEMW));
1195 li.mask = LVIF_TEXT;
1196 li.pszText = szBuffer;
1197 li.iItem = Index;
1198 li.iSubItem = SubIndex;
1199 li.cchTextMax = BufferSize;
1200 return SendMessageW(hDlgCtrl, LVM_GETITEMW, 0, (LPARAM)&li);
1201}
1202
1203VOID
1205 HWND hDlgCtrl,
1207 BOOL bSubmask)
1208{
1209 WCHAR szBuffer[30];
1210
1211 INT iIndex, iCount;
1212 IP_ADDR *pCur, *pLast;
1213
1214 iCount = ListView_GetItemCount(hDlgCtrl);
1215 if (!iCount)
1216 {
1217 return;
1218 }
1219
1220 pLast = NULL;
1221 for(iIndex = 0; iIndex < iCount; iIndex++)
1222 {
1223 if (GetListViewItem(hDlgCtrl, iIndex, 0, szBuffer, sizeof(szBuffer)/sizeof(WCHAR)))
1224 {
1225 pCur = (IP_ADDR*)CoTaskMemAlloc(sizeof(IP_ADDR));
1226 if (!pCur)
1227 break;
1228 ZeroMemory(pCur, sizeof(IP_ADDR));
1229
1230 szBuffer[(sizeof(szBuffer)/sizeof(WCHAR))-1] = L'\0';
1231 pCur->IpAddress = GetIpAddressFromStringW(szBuffer);
1232
1233 if (GetListViewItem(hDlgCtrl, iIndex, 1, szBuffer, sizeof(szBuffer)/sizeof(WCHAR) ))
1234 {
1235 szBuffer[(sizeof(szBuffer)/sizeof(WCHAR))-1] = L'\0';
1236 if (bSubmask)
1237 pCur->u.Subnetmask = GetIpAddressFromStringW(szBuffer);
1238 else
1239 pCur->u.Metric = _wtoi(szBuffer);
1240 }
1241
1242 if (!pLast)
1243 {
1244 if (bSubmask)
1245 This->pCurrentConfig->Ip = pCur;
1246 else
1247 This->pCurrentConfig->Gw = pCur;
1248 }
1249 else
1250 {
1251 pLast->Next = pCur;
1252 }
1253
1254 pLast = pCur;
1255 }
1256 }
1257}
1258
1259
1260INT_PTR
1263 HWND hwndDlg,
1264 UINT uMsg,
1265 WPARAM wParam,
1267)
1268{
1271 INT_PTR res;
1272 WCHAR szBuffer[200];
1273 LPPSHNOTIFY lppsn;
1275 TcpipIpSettings Ip;
1276
1277 LVITEMW li;
1278
1279 switch(uMsg)
1280 {
1281 case WM_INITDIALOG:
1283 This = (TcpipConfNotifyImpl*)page->lParam;
1286 return TRUE;
1287 case WM_NOTIFY:
1288 lppsn = (LPPSHNOTIFY) lParam;
1289 if (lppsn->hdr.code == LVN_ITEMCHANGED)
1290 {
1292 BOOL bEnable;
1293
1294 if (lplv->hdr.idFrom == IDC_IPLIST)
1295 {
1297
1298 bEnable = ((lplv->uNewState & LVIS_SELECTED) != 0) &&
1299 (!This->pCurrentConfig->DhcpEnabled);
1300
1303 }
1304 else if (lplv->hdr.idFrom == IDC_GWLIST)
1305 {
1306 bEnable = ((lplv->uNewState & LVIS_SELECTED) != 0);
1307
1310 }
1311 }
1312 else if (lppsn->hdr.code == PSN_KILLACTIVE)
1313 {
1315 if (!This->pCurrentConfig->DhcpEnabled && ListView_GetItemCount(GetDlgItem(hwndDlg, IDC_IPLIST)) == 0)
1316 {
1319 return TRUE;
1320 }
1321 }
1322 else if (lppsn->hdr.code == PSN_APPLY)
1323 {
1325 FreeIPAddr(This->pCurrentConfig->Gw);
1326 This->pCurrentConfig->Gw = NULL;
1327 FreeIPAddr(This->pCurrentConfig->Ip);
1328 This->pCurrentConfig->Ip = NULL;
1332 return TRUE;
1333 }
1334 break;
1335 case WM_COMMAND:
1337 {
1340 else
1342 }
1343 else if (LOWORD(wParam) == IDC_IPADD)
1344 {
1345 Ip.bAdd = TRUE;
1346 Ip.hDlgCtrl = GetDlgItem(hwndDlg, IDC_IPLIST);
1348 if (res)
1349 {
1350 memset(&li, 0x0, sizeof(LVITEMW));
1351 li.mask = LVIF_TEXT | LVIF_PARAM;
1352 li.iItem = ListView_GetItemCount(GetDlgItem(hwndDlg, IDC_IPLIST));
1353 li.pszText = Ip.szIP;
1354 li.iItem = SendDlgItemMessageW(hwndDlg, IDC_IPLIST, LVM_INSERTITEMW, 0, (LPARAM)&li);
1355 if (li.iItem != -1)
1356 {
1357 li.mask = LVIF_TEXT;
1358 li.iSubItem = 1;
1359 li.pszText = Ip.szMask;
1361 }
1362 }
1363 }
1364 else if (LOWORD(wParam) == IDC_IPMOD)
1365 {
1366 memset(&li, 0x0, sizeof(LVITEMW));
1367 li.iItem = GetSelectedItem(GetDlgItem(hwndDlg, IDC_IPLIST));
1368 if (li.iItem < 0)
1369 {
1370 /* no item selected */
1372 SetFocus(GetDlgItem(hwndDlg, IDC_IPLIST));
1373 break;
1374 }
1375 Ip.bAdd = FALSE;
1376 Ip.hDlgCtrl = GetDlgItem(hwndDlg, IDC_IPLIST);
1377 if (GetIPListEntry(GetDlgItem(hwndDlg, IDC_IPLIST), li.iItem, &Ip))
1378 {
1380 if (res)
1381 {
1382 li.mask = LVIF_TEXT;
1383 li.pszText = Ip.szIP;
1385 li.pszText = Ip.szMask;
1386 li.iSubItem = 1;
1388 }
1389 }
1390 }
1391 else if (LOWORD(wParam) == IDC_IPDEL)
1392 {
1394 break;
1395 }
1396 else if (LOWORD(wParam) == IDC_GWADD)
1397 {
1398 Gw.bAdd = TRUE;
1399 Gw.hDlgCtrl = GetDlgItem(hwndDlg, IDC_GWLIST);
1401 if (res)
1402 {
1403 memset(&li, 0x0, sizeof(LVITEMW));
1404 li.mask = LVIF_TEXT;
1405 li.iItem = ListView_GetItemCount(GetDlgItem(hwndDlg, IDC_GWLIST));
1406 li.pszText = Gw.szIP;
1407 li.iItem = SendDlgItemMessageW(hwndDlg, IDC_GWLIST, LVM_INSERTITEMW, 0, (LPARAM)&li);
1408 if (li.iItem >= 0)
1409 {
1410 if (Gw.Metric)
1411 {
1412 swprintf(szBuffer, L"%u", Gw.Metric);
1413 li.iSubItem = 1;
1414 li.pszText = szBuffer;
1416 }
1417 else
1418 {
1419 if (LoadStringW(netcfgx_hInstance, IDS_AUTOMATIC, szBuffer, sizeof(szBuffer)/sizeof(WCHAR)))
1420 {
1421 szBuffer[(sizeof(szBuffer)/sizeof(WCHAR))-1] = L'\0';
1422 li.iSubItem = 1;
1423 li.pszText = szBuffer;
1425 }
1426 }
1427 }
1428 }
1429 break;
1430 }
1431 else if (LOWORD(wParam) == IDC_GWMOD)
1432 {
1433 memset(&li, 0x0, sizeof(LVITEMW));
1434 li.iItem = GetSelectedItem(GetDlgItem(hwndDlg, IDC_GWLIST));
1435 if (li.iItem < 0)
1436 {
1437 /* no item selected */
1439 SetFocus(GetDlgItem(hwndDlg, IDC_GWLIST));
1440 break;
1441 }
1442 if (GetGWListEntry(GetDlgItem(hwndDlg, IDC_GWLIST), li.iItem, &Gw))
1443 {
1444 Gw.bAdd = FALSE;
1445 Gw.hDlgCtrl = GetDlgItem(hwndDlg, IDC_GWLIST);
1447 if (res)
1448 {
1449 li.mask = LVIF_TEXT;
1450 li.pszText = Gw.szIP;
1452 if (Gw.Metric)
1453 {
1454 swprintf(szBuffer, L"%u", Gw.Metric);
1455 li.iSubItem = 1;
1456 li.pszText = szBuffer;
1458 }
1459 else
1460 {
1461 if (LoadStringW(netcfgx_hInstance, IDS_AUTOMATIC, szBuffer, sizeof(szBuffer)/sizeof(WCHAR)))
1462 {
1463 szBuffer[(sizeof(szBuffer)/sizeof(WCHAR))-1] = L'\0';
1464 li.iSubItem = 1;
1465 li.pszText = szBuffer;
1467 }
1468 }
1469 }
1470 }
1471 break;
1472 }
1473 else if (LOWORD(wParam) == IDC_GWDEL)
1474 {
1476 break;
1477 }
1478 }
1479 return FALSE;
1480}
1481
1482INT_PTR
1485 HWND hwndDlg,
1486 UINT uMsg,
1487 WPARAM wParam,
1489)
1490{
1491 TcpipDnsSettings * pSettings;
1492 WCHAR szBuffer[100];
1493 DWORD dwIpAddr;
1494 LPNMIPADDRESS lpnmipa;
1495
1496 switch(uMsg)
1497 {
1498 case WM_INITDIALOG:
1499 pSettings = (TcpipDnsSettings*)lParam;
1501 if (!pSettings->bAdd)
1502 {
1503 if (LoadStringW(netcfgx_hInstance, IDS_MOD, szBuffer, sizeof(szBuffer)/sizeof(WCHAR)))
1504 {
1505 szBuffer[(sizeof(szBuffer)/sizeof(WCHAR))-1] = L'\0';
1506 SendDlgItemMessageW(hwndDlg, IDC_OK, WM_SETTEXT, 0, (LPARAM)szBuffer);
1507 }
1508 SendDlgItemMessageW(hwndDlg, IDC_IPADDR, WM_SETTEXT, 0, (LPARAM)pSettings->szIP);
1509 EnableWindow(GetDlgItem(hwndDlg, IDC_OK), TRUE);
1510 }
1511 else
1512 {
1513 if (LoadStringW(netcfgx_hInstance, IDS_ADD, szBuffer, sizeof(szBuffer)/sizeof(WCHAR)))
1514 {
1515 szBuffer[(sizeof(szBuffer)/sizeof(WCHAR))-1] = L'\0';
1516 SendDlgItemMessageW(hwndDlg, IDC_OK, WM_SETTEXT, 0, (LPARAM)szBuffer);
1517 }
1518 EnableWindow(GetDlgItem(hwndDlg, IDC_OK), FALSE);
1519 }
1520 return TRUE;
1521 case WM_COMMAND:
1522 if (LOWORD(wParam) == IDCANCEL)
1523 {
1524 EndDialog(hwndDlg, FALSE);
1525 break;
1526 }
1527 else if (LOWORD(wParam) == IDC_OK)
1528 {
1529 pSettings = (TcpipDnsSettings*)GetWindowLongPtr(hwndDlg, DWLP_USER);
1530 SendDlgItemMessageW(hwndDlg, IDC_IPADDR, WM_GETTEXT, 16, (LPARAM)pSettings->szIP);
1531 if (SendMessageW(pSettings->hDlgCtrl, LB_FINDSTRING, 0, (LPARAM)pSettings->szIP) == LB_ERR)
1532 {
1533 if (pSettings->bAdd)
1534 SendMessageW(pSettings->hDlgCtrl, LB_ADDSTRING, 0, (LPARAM)pSettings->szIP);
1535 EndDialog(hwndDlg, TRUE);
1536 break;
1537 }
1538 if (!pSettings->bAdd)
1539 {
1540 EndDialog(hwndDlg, FALSE);
1541 break;
1542 }
1544 break;
1545 }
1546 break;
1547 case WM_NOTIFY:
1548 lpnmipa = (LPNMIPADDRESS) lParam;
1549 if (lpnmipa->hdr.code == IPN_FIELDCHANGED)
1550 {
1551 if (lpnmipa->hdr.idFrom == IDC_IPADDR)
1552 {
1553 if (SendDlgItemMessageW(hwndDlg, IDC_IPADDR, IPM_GETADDRESS, 0, (LPARAM)&dwIpAddr) == 4)
1554 EnableWindow(GetDlgItem(hwndDlg, IDC_OK), TRUE);
1555 }
1556 }
1557 break;
1558 }
1559 return FALSE;
1560}
1561
1562
1563
1564VOID
1566 HWND hwndDlg,
1568{
1569 WCHAR szBuffer[200];
1570 LPWSTR pFirst, pSep, pList;
1571 IP_ADDR * pAddr;
1572 DWORD dwIpAddr;
1573
1574 /* insert DNS addresses */
1575 pAddr = This->pCurrentConfig->Ns;
1576 while(pAddr)
1577 {
1578 dwIpAddr = pAddr->IpAddress;
1579 swprintf(szBuffer, L"%lu.%lu.%lu.%lu",
1580 FIRST_IPADDRESS(dwIpAddr), SECOND_IPADDRESS(dwIpAddr), THIRD_IPADDRESS(dwIpAddr), FOURTH_IPADDRESS(dwIpAddr));
1581
1582 SendDlgItemMessageW(hwndDlg, IDC_DNSADDRLIST, LB_ADDSTRING, 0, (LPARAM)szBuffer);
1583 pAddr = pAddr->Next;
1584 }
1586
1587 if (!This->pCurrentConfig->pDNS)
1588 return;
1589
1590 if (This->pCurrentConfig->pDNS->RegisterAdapterName)
1592 else
1594
1595 if (This->pCurrentConfig->pDNS->RegistrationEnabled)
1597
1598 if (This->pCurrentConfig->pDNS->szDomain[0])
1599 SendDlgItemMessageW(hwndDlg, IDC_SUFFIX, WM_SETTEXT, 0, (LPARAM)szBuffer);
1600
1601 if (This->pCurrentConfig->pDNS->UseDomainNameDevolution)
1603
1604 if (!This->pCurrentConfig->pDNS->szSearchList || (wcslen(This->pCurrentConfig->pDNS->szSearchList) == 0))
1605 {
1608
1609 return;
1610 }
1611
1612 pList = This->pCurrentConfig->pDNS->szSearchList;
1613 if (wcslen(pList))
1614 {
1615 pFirst = pList;
1616 do
1617 {
1618 pSep = wcschr(pFirst, L',');
1619 if (pSep)
1620 {
1621 pSep[0] = L'\0';
1623 pFirst = pSep + 1;
1624 pSep[0] = L',';
1625 }
1626 else
1627 {
1629 break;
1630 }
1631 }while(TRUE);
1632
1636 }
1637}
1638
1639VOID
1640ToggleUpDown(HWND hwndDlg, HWND hDlgCtrl, UINT UpButton, UINT DownButton, UINT ModButton, UINT DelButton)
1641{
1642 LRESULT lResult, lCount;
1643
1644 lResult = SendMessageW(hDlgCtrl, LB_GETCURSEL, 0, 0);
1645 lCount = SendMessageW(hDlgCtrl, LB_GETCOUNT, 0, 0);
1646 if (lResult != LB_ERR)
1647 {
1648 if (lResult == 0)
1649 EnableWindow(GetDlgItem(hwndDlg, UpButton), FALSE);
1650 else
1651 EnableWindow(GetDlgItem(hwndDlg, UpButton), TRUE);
1652
1653 if (lResult < lCount -1)
1654 EnableWindow(GetDlgItem(hwndDlg, DownButton), TRUE);
1655 else
1656 EnableWindow(GetDlgItem(hwndDlg, DownButton), FALSE);
1657 }
1658
1659 if (lCount)
1660 {
1661 EnableWindow(GetDlgItem(hwndDlg, ModButton), TRUE);
1662 EnableWindow(GetDlgItem(hwndDlg, DelButton), TRUE);
1663 }
1664 else
1665 {
1666 EnableWindow(GetDlgItem(hwndDlg, ModButton), FALSE);
1667 EnableWindow(GetDlgItem(hwndDlg, DelButton), FALSE);
1668 EnableWindow(GetDlgItem(hwndDlg, UpButton), FALSE);
1669 EnableWindow(GetDlgItem(hwndDlg, DownButton), FALSE);
1670 }
1671}
1672
1673VOID
1675 HWND hDlgCtrl,
1676 INT pos)
1677{
1678 WCHAR szBuffer[100];
1679 LRESULT lResult;
1680
1681 lResult = SendMessageW(hDlgCtrl, LB_GETCURSEL, 0, 0);
1682 if (lResult != LB_ERR)
1683 {
1684 if (SendMessageW(hDlgCtrl, LB_GETTEXTLEN, (WPARAM)lResult, 0) < sizeof(szBuffer)/sizeof(WCHAR) - 1)
1685 {
1686 if (SendMessageW(hDlgCtrl, LB_GETTEXT, (WPARAM)lResult, (LPARAM)szBuffer) != LB_ERR)
1687 {
1688 SendMessageW(hDlgCtrl, LB_DELETESTRING, (WPARAM)lResult, 0);
1689 SendMessageW(hDlgCtrl, LB_INSERTSTRING, (WPARAM)lResult + pos, (LPARAM)szBuffer);
1690 SendMessageW(hDlgCtrl, LB_SETCURSEL, (WPARAM)lResult + pos, 0);
1691 }
1692 }
1693 }
1694}
1695VOID
1697 HWND hDlgCtrl)
1698{
1699 LRESULT lResult, lCount;
1700
1701 lResult = SendMessageW(hDlgCtrl, LB_GETCURSEL, 0, 0);
1702 if (lResult != LB_ERR)
1703 {
1704 SendMessageW(hDlgCtrl, LB_DELETESTRING, (WPARAM)lResult, 0);
1705 lCount = SendMessageW(hDlgCtrl, LB_GETCOUNT, 0, 0);
1706 if (lResult + 1 < lCount)
1707 SendMessageW(hDlgCtrl, LB_SETCURSEL, (WPARAM)lResult, 0);
1708 else
1709 SendMessageW(hDlgCtrl, LB_SETCURSEL, (WPARAM)lCount-1, 0);
1710 }
1711}
1712
1713LPWSTR
1715 HWND hDlgCtrl)
1716{
1717 DWORD dwSize;
1718 INT iCount, iIndex;
1719 INT_PTR lResult;
1720 LPWSTR pszSearchList, pItem;
1721
1722 iCount = SendMessageW(hDlgCtrl, LB_GETCOUNT, 0, 0);
1723 if (!iCount || iCount == LB_ERR)
1724 return NULL; //BUGBUG
1725
1726 dwSize = 0;
1727
1728 for (iIndex = 0; iIndex < iCount; iIndex++)
1729 {
1730 lResult = SendMessageW(hDlgCtrl, LB_GETTEXTLEN, iIndex, 0);
1731 if (lResult == LB_ERR)
1732 return NULL;
1733
1734 dwSize += lResult + 1;
1735 }
1736
1737 pszSearchList = (LPWSTR)CoTaskMemAlloc((dwSize + 1) * sizeof(WCHAR));
1738 if (!pszSearchList)
1739 return NULL;
1740
1741 pItem = pszSearchList;
1742 for (iIndex = 0; iIndex < iCount; iIndex++)
1743 {
1744 lResult = SendMessageW(hDlgCtrl, LB_GETTEXT, iIndex, (LPARAM)pItem);
1745 if (lResult == LB_ERR)
1746 {
1747 CoTaskMemFree(pszSearchList);
1748 return NULL;
1749 }
1750 dwSize -= lResult + 1;
1751 pItem += wcslen(pItem);
1752 if (iIndex != iCount -1)
1753 {
1754 pItem[0] = L',';
1755 pItem++;
1756 }
1757 }
1758 pItem[0] = L'\0';
1759 return pszSearchList;
1760}
1761
1762VOID
1764 HWND hDlgCtrl,
1766{
1767 INT iCount, iIndex;
1768 WCHAR Ip[16];
1769 IP_ADDR *pCur, *pLast;
1770
1771 FreeIPAddr(This->pCurrentConfig->Ns);
1772 This->pCurrentConfig->Ns = NULL;
1773
1774 iCount = SendMessageW(hDlgCtrl, LB_GETCOUNT, 0, 0);
1775 if (!iCount || iCount == LB_ERR)
1776 {
1777 return;
1778 }
1779
1780 pLast = NULL;
1781 for(iIndex = 0; iIndex < iCount; iIndex++)
1782 {
1783 if (SendMessageW(hDlgCtrl, LB_GETTEXT, iIndex, (LPARAM)Ip) == LB_ERR)
1784 break;
1785
1786 pCur = CoTaskMemAlloc(sizeof(IP_ADDR));
1787 if (!pCur)
1788 break;
1789 ZeroMemory(pCur, sizeof(IP_ADDR));
1790 pCur->IpAddress = GetIpAddressFromStringW(Ip);
1791
1792 if (!pLast)
1793 This->pCurrentConfig->Ns = pCur;
1794 else
1795 pLast->Next = pCur;
1796
1797 pLast = pCur;
1798 pCur = pCur->Next;
1799 }
1800 This->pCurrentConfig->AutoconfigActive = FALSE;
1801}
1802
1803INT_PTR
1806 HWND hwndDlg,
1807 UINT uMsg,
1808 WPARAM wParam,
1810)
1811{
1814 TcpipDnsSettings Dns;
1815 LRESULT lIndex, lLength;
1816 TcpipSuffixSettings Suffix;
1817 LPPSHNOTIFY lppsn;
1818 WCHAR szSuffix[100];
1819 WCHAR szFormat[200];
1820 WCHAR szBuffer[300];
1821
1822
1823 switch(uMsg)
1824 {
1825 case WM_INITDIALOG:
1827 This = (TcpipConfNotifyImpl*)page->lParam;
1832 return TRUE;
1833 case WM_NOTIFY:
1834 lppsn = (LPPSHNOTIFY) lParam;
1835 if (lppsn->hdr.code == PSN_KILLACTIVE)
1836 {
1837 if (SendDlgItemMessageW(hwndDlg, IDC_SELSUFFIX, BM_GETCHECK, 0, 0) == BST_CHECKED &&
1839 {
1842 return TRUE;
1843 }
1844 if (SendDlgItemMessageW(hwndDlg, IDC_SUFFIX, WM_GETTEXT, sizeof(szSuffix)/sizeof(WCHAR), (LPARAM)szSuffix))
1845 {
1846 szSuffix[(sizeof(szSuffix)/sizeof(WCHAR))-1] = L'\0';
1847 if (VerifyDNSSuffix(szSuffix) == FALSE)
1848 {
1849 if (LoadStringW(netcfgx_hInstance, IDS_DNS_SUFFIX, szFormat, sizeof(szFormat)/sizeof(WCHAR)))
1850 {
1851 szFormat[(sizeof(szFormat)/sizeof(WCHAR))-1] = L'\0';
1852 swprintf(szBuffer, szFormat, szSuffix);
1853 if (LoadStringW(netcfgx_hInstance, IDS_TCPIP, szFormat, sizeof(szFormat)/sizeof(WCHAR)))
1854 szFormat[(sizeof(szFormat)/sizeof(WCHAR))-1] = L'\0';
1855 else
1856 szFormat[0] = L'\0';
1857
1858 MessageBoxW(hwndDlg, szBuffer, szFormat, MB_ICONWARNING);
1860 SetFocus(GetDlgItem(hwndDlg, IDC_SUFFIX));
1861 return TRUE;
1862 }
1863 }
1864 }
1865 }
1866 else if (lppsn->hdr.code == PSN_APPLY)
1867 {
1869 if (!This->pCurrentConfig->pDNS)
1870 break;
1871
1874 {
1875 CoTaskMemFree(This->pCurrentConfig->pDNS->szSearchList);
1876 This->pCurrentConfig->pDNS->szSearchList = NULL;
1878 This->pCurrentConfig->pDNS->UseDomainNameDevolution = TRUE;
1879 else
1880 This->pCurrentConfig->pDNS->UseDomainNameDevolution = FALSE;
1881 }
1882 else
1883 {
1884 CoTaskMemFree(This->pCurrentConfig->pDNS->szSearchList);
1885 This->pCurrentConfig->pDNS->szSearchList = NULL;
1886 This->pCurrentConfig->pDNS->UseDomainNameDevolution = FALSE;
1887 This->pCurrentConfig->pDNS->szSearchList = GetListViewEntries(GetDlgItem(hwndDlg, IDC_DNSSUFFIXLIST));
1888 }
1889
1891 {
1892 This->pCurrentConfig->pDNS->RegisterAdapterName = TRUE;
1894 This->pCurrentConfig->pDNS->RegistrationEnabled = TRUE;
1895 else
1896 This->pCurrentConfig->pDNS->RegistrationEnabled = FALSE;
1897 }
1898 else
1899 {
1900 This->pCurrentConfig->pDNS->RegisterAdapterName = FALSE;
1901 This->pCurrentConfig->pDNS->RegistrationEnabled = FALSE;
1902 }
1903 }
1904 break;
1905 case WM_COMMAND:
1907 {
1909 PropSheet_Changed(GetParent(hwndDlg), hwndDlg);
1910 break;
1911 }
1913 {
1915 PropSheet_Changed(GetParent(hwndDlg), hwndDlg);
1916 break;
1917 }
1918 else if (LOWORD(wParam) == IDC_PRIMSUFFIX && HIWORD(wParam) == BN_CLICKED)
1919 {
1921 {
1929 PropSheet_Changed(GetParent(hwndDlg), hwndDlg);
1930 }
1931 }
1932 else if (LOWORD(wParam) == IDC_SELSUFFIX && HIWORD(wParam) == BN_CLICKED)
1933 {
1935 {
1939 PropSheet_Changed(GetParent(hwndDlg), hwndDlg);
1940 }
1941 break;
1942 }
1943 else if (LOWORD(wParam) == IDC_REGSUFFIX && HIWORD(wParam) == BN_CLICKED)
1944 {
1947 else
1949 PropSheet_Changed(GetParent(hwndDlg), hwndDlg);
1950 }
1951 else if (LOWORD(wParam) == IDC_DNSADDRUP && HIWORD(wParam) == BN_CLICKED)
1952 {
1953 MoveItem(GetDlgItem(hwndDlg, IDC_DNSADDRLIST), -1);
1956 PropSheet_Changed(GetParent(hwndDlg), hwndDlg);
1957 break;
1958 }
1960 {
1961 MoveItem(GetDlgItem(hwndDlg, IDC_DNSADDRLIST), 1);
1964 PropSheet_Changed(GetParent(hwndDlg), hwndDlg);
1965 break;
1966 }
1968 {
1969 MoveItem(GetDlgItem(hwndDlg, IDC_DNSSUFFIXLIST), -1);
1972 PropSheet_Changed(GetParent(hwndDlg), hwndDlg);
1973 break;
1974 }
1976 {
1980 PropSheet_Changed(GetParent(hwndDlg), hwndDlg);
1981 break;
1982 }
1983 else if (LOWORD(wParam) == IDC_DNSADDRDEL && HIWORD(wParam) == BN_CLICKED)
1984 {
1988 PropSheet_Changed(GetParent(hwndDlg), hwndDlg);
1989 break;
1990 }
1992 {
1996 PropSheet_Changed(GetParent(hwndDlg), hwndDlg);
1997 break;
1998 }
1999 else if (LOWORD(wParam) == IDC_DNSADDRADD && HIWORD(wParam) == BN_CLICKED)
2000 {
2001 Dns.bAdd = TRUE;
2002 Dns.hDlgCtrl = GetDlgItem(hwndDlg, IDC_DNSADDRLIST);
2004 {
2006 PropSheet_Changed(GetParent(hwndDlg), hwndDlg);
2007 }
2008 break;
2009 }
2010 else if (LOWORD(wParam) == IDC_DNSADDRMOD && HIWORD(wParam) == BN_CLICKED)
2011 {
2012 lIndex = SendDlgItemMessage(hwndDlg, IDC_DNSADDRLIST, LB_GETCURSEL, 0, 0);
2013 if (lIndex != LB_ERR)
2014 {
2015 Dns.bAdd = FALSE;
2016 Dns.hDlgCtrl = GetDlgItem(hwndDlg, IDC_DNSADDRLIST);
2019 {
2021 SendDlgItemMessageW(hwndDlg, IDC_DNSADDRLIST, LB_INSERTSTRING, lIndex, (LPARAM)Dns.szIP);
2022 SendDlgItemMessageW(hwndDlg, IDC_DNSADDRLIST, LB_SETCURSEL, lIndex, 0);
2024 PropSheet_Changed(GetParent(hwndDlg), hwndDlg);
2025 }
2026 }
2027 break;
2028 }
2030 {
2031 Suffix.bAdd = TRUE;
2032 Suffix.hDlgCtrl = GetDlgItem(hwndDlg, IDC_DNSSUFFIXLIST);
2033 Suffix.Suffix = NULL;
2035 {
2037 lIndex = SendDlgItemMessageW(hwndDlg, IDC_DNSSUFFIXLIST, LB_ADDSTRING, 0, (LPARAM)Suffix.Suffix);
2038 if (lIndex != LB_ERR)
2041 PropSheet_Changed(GetParent(hwndDlg), hwndDlg);
2042 CoTaskMemFree(Suffix.Suffix);
2043 }
2044 break;
2045 }
2047 {
2048 lIndex = SendDlgItemMessage(hwndDlg, IDC_DNSSUFFIXLIST, LB_GETCURSEL, 0, 0);
2049 if (lIndex != LB_ERR)
2050 {
2051 Suffix.bAdd = FALSE;
2052 Suffix.hDlgCtrl = GetDlgItem(hwndDlg, IDC_DNSSUFFIXLIST);
2053 lLength = SendMessageW(Suffix.hDlgCtrl, LB_GETTEXTLEN, lIndex, 0);
2054 if (lLength != LB_ERR)
2055 {
2056 Suffix.Suffix = (LPWSTR)CoTaskMemAlloc((lLength + 1) * sizeof(WCHAR));
2057 if (Suffix.Suffix)
2058 {
2059 SendMessageW(Suffix.hDlgCtrl, LB_GETTEXT, lIndex, (LPARAM)Suffix.Suffix);
2060 Suffix.Suffix[lLength] = L'\0';
2062 {
2063 if (Suffix.Suffix)
2064 {
2066 SendDlgItemMessageW(hwndDlg, IDC_DNSSUFFIXLIST, LB_INSERTSTRING, lIndex, (LPARAM)Suffix.Suffix);
2069 CoTaskMemFree(Suffix.Suffix);
2070 }
2072 PropSheet_Changed(GetParent(hwndDlg), hwndDlg);
2073 }
2074 }
2075 }
2076 }
2077 break;
2078 }
2079 }
2080 return FALSE;
2081}
2082
2083static int CALLBACK
2085{
2086 // NOTE: This callback is needed to set large icon correctly.
2087 HICON hIcon;
2088 switch (uMsg)
2089 {
2090 case PSCB_INITIALIZED:
2091 {
2093 SendMessageW(hwndDlg, WM_SETICON, ICON_BIG, (LPARAM)hIcon);
2094 break;
2095 }
2096 }
2097 return 0;
2098}
2099
2100VOID
2102 HWND hwndDlg,
2104{
2105 PROPSHEETHEADERW pinfo;
2106 HPROPSHEETPAGE hppages[3];
2107 WCHAR szBuffer[100];
2108
2112
2113
2114 if (LoadStringW(netcfgx_hInstance, IDS_TCPIP, szBuffer, sizeof(szBuffer)/sizeof(WCHAR)))
2115 szBuffer[(sizeof(szBuffer)/sizeof(WCHAR))-1] = L'\0';
2116 else
2117 szBuffer[0] = L'\0';
2118
2119 ZeroMemory(&pinfo, sizeof(PROPSHEETHEADERW));
2120 pinfo.dwSize = sizeof(PROPSHEETHEADERW);
2121 pinfo.dwFlags = PSH_NOCONTEXTHELP | PSH_PROPTITLE | PSH_NOAPPLYNOW |
2123 pinfo.u3.phpage = hppages;
2124 pinfo.nPages = 3;
2125 pinfo.hwndParent = hwndDlg;
2127 pinfo.pszCaption = szBuffer;
2129 pinfo.pfnCallback = PropSheetProc;
2130
2132 if (PropertySheetW(&pinfo) > 0)
2133 {
2134 InitializeTcpipBasicDlgCtrls(hwndDlg, This->pCurrentConfig);
2135 PropSheet_Changed(GetParent(hwndDlg), hwndDlg);
2136 }
2137}
2138
2139INT_PTR
2142 HWND hwndDlg,
2143 UINT uMsg,
2144 WPARAM wParam,
2145 LPARAM lParam)
2146{
2147 switch(uMsg)
2148 {
2149 case WM_INITDIALOG:
2150 return TRUE;
2151 }
2152 return FALSE;
2153}
2154
2155VOID
2157 HWND hDlg,
2159{
2160 HPROPSHEETPAGE hpage;
2161
2163 if (!hpage)
2164 return;
2165
2166 SendMessageW(hDlg, PSM_INSERTPAGE, 1, (LPARAM)hpage);
2167}
2168
2169INT_PTR
2171 HWND hwndDlg,
2173 BOOL bApply)
2174{
2175 DWORD dwIpAddr;
2176
2177 if (SendDlgItemMessageW(hwndDlg, IDC_NODHCP, BM_GETCHECK, 0, 0) == BST_CHECKED)
2178 {
2179 This->pCurrentConfig->DhcpEnabled = FALSE;
2180 if (SendDlgItemMessageW(hwndDlg, IDC_IPADDR, IPM_GETADDRESS, 0, (LPARAM)&dwIpAddr) != 4)
2181 {
2182 if (bApply)
2183 {
2185 SetFocus(GetDlgItem(hwndDlg, IDC_IPADDR));
2186 return E_FAIL;
2187 }
2188 }
2189 if (!This->pCurrentConfig->Ip)
2190 {
2191 This->pCurrentConfig->Ip = (IP_ADDR*)CoTaskMemAlloc(sizeof(IP_ADDR));
2192 if (!This->pCurrentConfig->Ip)
2193 return E_OUTOFMEMORY;
2194 ZeroMemory(This->pCurrentConfig->Ip, sizeof(IP_ADDR));
2195 }
2196 This->pCurrentConfig->Ip->IpAddress = dwIpAddr;
2197
2198 if (SendDlgItemMessageW(hwndDlg, IDC_SUBNETMASK, IPM_GETADDRESS, 0, (LPARAM)&dwIpAddr) != 4)
2199 {
2200 if (bApply)
2202 if (SendDlgItemMessageW(hwndDlg, IDC_IPADDR, IPM_GETADDRESS, 0, (LPARAM)&dwIpAddr) == 4)
2203 {
2204 if (dwIpAddr <= MAKEIPADDRESS(127, 255, 255, 255))
2205 dwIpAddr = MAKEIPADDRESS(255, 0, 0, 0);
2206 else if (dwIpAddr <= MAKEIPADDRESS(191, 255, 255, 255))
2207 dwIpAddr = MAKEIPADDRESS(255, 255, 0, 0);
2208 else if (dwIpAddr <= MAKEIPADDRESS(223, 255, 255, 255))
2209 dwIpAddr = MAKEIPADDRESS(255, 255, 255, 0);
2210
2212 }
2213 if (bApply)
2214 {
2216 return E_FAIL;
2217 }
2218 }
2219 /* store subnetmask */
2220 This->pCurrentConfig->Ip->u.Subnetmask = dwIpAddr;
2221 }
2222 else
2223 {
2224 This->pCurrentConfig->DhcpEnabled = TRUE;
2225 }
2226
2227 if (SendDlgItemMessageW(hwndDlg, IDC_DEFGATEWAY, IPM_GETADDRESS, 0, (LPARAM)&dwIpAddr) == 4)
2228 {
2229 if (!This->pCurrentConfig->Gw)
2230 {
2231 This->pCurrentConfig->Gw = (IP_ADDR*)CoTaskMemAlloc(sizeof(IP_ADDR));
2232 if (!This->pCurrentConfig->Gw)
2233 return E_OUTOFMEMORY;
2234 ZeroMemory(This->pCurrentConfig->Gw, sizeof(IP_ADDR));
2235 }
2236 /* store default gateway */
2237 This->pCurrentConfig->Gw->IpAddress = dwIpAddr;
2238 }
2239 else
2240 {
2241 if (This->pCurrentConfig->Gw)
2242 {
2243 IP_ADDR * pNextGw = This->pCurrentConfig->Gw->Next;
2244 CoTaskMemFree(This->pCurrentConfig->Gw);
2245 This->pCurrentConfig->Gw = pNextGw;
2246 }
2247 }
2248
2250 {
2251 BOOL bSkip = FALSE;
2252 This->pCurrentConfig->AutoconfigActive = FALSE;
2253 if (SendDlgItemMessageW(hwndDlg, IDC_DNS1, IPM_GETADDRESS, 0, (LPARAM)&dwIpAddr) == 4)
2254 {
2255 if (!This->pCurrentConfig->Ns)
2256 {
2257 This->pCurrentConfig->Ns = (IP_ADDR*)CoTaskMemAlloc(sizeof(IP_ADDR));
2258 if (!This->pCurrentConfig->Ns)
2259 return E_OUTOFMEMORY;
2260 ZeroMemory(This->pCurrentConfig->Ns, sizeof(IP_ADDR));
2261 }
2262 This->pCurrentConfig->Ns->IpAddress = dwIpAddr;
2263 }
2264 else if (This->pCurrentConfig->Ns)
2265 {
2266 IP_ADDR *pTemp = This->pCurrentConfig->Ns->Next;
2267
2268 CoTaskMemFree(This->pCurrentConfig->Ns);
2269 This->pCurrentConfig->Ns = pTemp;
2270 bSkip = TRUE;
2271 }
2272
2273
2274 if (SendDlgItemMessageW(hwndDlg, IDC_DNS2, IPM_GETADDRESS, 0, (LPARAM)&dwIpAddr) == 4)
2275 {
2276 if (!This->pCurrentConfig->Ns || bSkip)
2277 {
2278 if (!This->pCurrentConfig->Ns)
2279 {
2280 This->pCurrentConfig->Ns = (IP_ADDR*)CoTaskMemAlloc(sizeof(IP_ADDR));
2281 if (!This->pCurrentConfig->Ns)
2282 return E_OUTOFMEMORY;
2283 ZeroMemory(This->pCurrentConfig->Ns, sizeof(IP_ADDR));
2284 }
2285 This->pCurrentConfig->Ns->IpAddress = dwIpAddr;
2286 }
2287 else if (!This->pCurrentConfig->Ns->Next)
2288 {
2289 This->pCurrentConfig->Ns->Next = (IP_ADDR*)CoTaskMemAlloc(sizeof(IP_ADDR));
2290 if (!This->pCurrentConfig->Ns->Next)
2291 return E_OUTOFMEMORY;
2292 ZeroMemory(This->pCurrentConfig->Ns->Next, sizeof(IP_ADDR));
2293 This->pCurrentConfig->Ns->Next->IpAddress = dwIpAddr;
2294 }
2295 else
2296 {
2297 This->pCurrentConfig->Ns->Next->IpAddress = dwIpAddr;
2298 }
2299 }
2300 else
2301 {
2302 if (This->pCurrentConfig->Ns && This->pCurrentConfig->Ns->Next)
2303 {
2304 if (This->pCurrentConfig->Ns->Next->Next)
2305 {
2306 IP_ADDR *pTemp = This->pCurrentConfig->Ns->Next->Next;
2307 CoTaskMemFree(This->pCurrentConfig->Ns->Next);
2308 This->pCurrentConfig->Ns->Next = pTemp;
2309 }
2310 else
2311 {
2312 CoTaskMemFree(This->pCurrentConfig->Ns->Next);
2313 This->pCurrentConfig->Ns->Next = NULL;
2314 }
2315 }
2316 }
2317 }
2318 else
2319 {
2320 This->pCurrentConfig->AutoconfigActive = TRUE;
2321 }
2322 return S_OK;
2323}
2324
2325HRESULT
2327 HWND hwndDlg,
2328 TcpipSettings * pCurSettings)
2329{
2334
2339
2344
2349
2354
2355 if (pCurSettings->DhcpEnabled)
2356 {
2362 }
2363 else
2364 {
2366
2367 if (pCurSettings->Ip)
2368 {
2369 /* set current ip address */
2370 SendDlgItemMessageA(hwndDlg, IDC_IPADDR, IPM_SETADDRESS, 0, (LPARAM)pCurSettings->Ip->IpAddress);
2371 /* set current hostmask */
2372 SendDlgItemMessageA(hwndDlg, IDC_SUBNETMASK, IPM_SETADDRESS, 0, (LPARAM)pCurSettings->Ip->u.Subnetmask);
2373 }
2374 }
2375
2376 if (pCurSettings->Gw && pCurSettings->Gw->IpAddress)
2377 {
2378 /* set current gateway */
2379 SendDlgItemMessageA(hwndDlg, IDC_DEFGATEWAY, IPM_SETADDRESS, 0, (LPARAM)pCurSettings->Gw->IpAddress);
2380 }
2381
2382 if (pCurSettings->AutoconfigActive)
2383 {
2387 }
2388 else
2389 {
2393 if (pCurSettings->Ns)
2394 {
2395 SendDlgItemMessageW(hwndDlg, IDC_DNS1, IPM_SETADDRESS, 0, (LPARAM)pCurSettings->Ns->IpAddress);
2396 if (pCurSettings->Ns->Next)
2397 {
2398 SendDlgItemMessageW(hwndDlg, IDC_DNS2, IPM_SETADDRESS, 0, (LPARAM)pCurSettings->Ns->Next->IpAddress);
2399 }
2400 else
2401 {
2403 }
2404 }
2405 else
2406 {
2409 }
2410 }
2411
2412 return S_OK;
2413}
2414
2415HRESULT
2417 IP_ADDR_STRING * pSrc,
2418 IP_ADDR ** pTarget,
2420 LPWSTR szMetric)
2421{
2422 IP_ADDR_STRING * pCurrent;
2423 IP_ADDR *pNew, *pLast;
2424
2425 pCurrent = pSrc;
2426 pLast = NULL;
2427
2428 while(pCurrent)
2429 {
2430 pNew = CoTaskMemAlloc(sizeof(IP_ADDR));
2431 if (!pNew)
2432 {
2433 break;
2434 }
2435 ZeroMemory(pNew, sizeof(IP_ADDR));
2437 if (!pNew->IpAddress)
2438 {
2439 CoTaskMemFree(pNew);
2440 return E_FAIL;
2441 }
2442
2443 if (Type == SUBMASK)
2444 {
2446 pNew->NTEContext = pCurrent->Context;
2447 }
2448 else if (Type == METRIC)
2449 {
2450 if (szMetric && szMetric[0] != L'\0')
2451 {
2452 pNew->u.Metric = _wtoi(szMetric);
2453 szMetric += wcslen(szMetric) + 1;
2454 }
2455 }
2456
2457 if (!pLast)
2458 *pTarget = pNew;
2459 else
2460 pLast->Next = pNew;
2461
2462 pLast = pNew;
2463 pCurrent = pCurrent->Next;
2464
2465 }
2466 pLast->Next = NULL;
2467 return S_OK;
2468}
2469
2470
2471
2472INT_PTR
2475 HWND hwndDlg,
2476 UINT uMsg,
2477 WPARAM wParam,
2479)
2480{
2483 LPNMIPADDRESS lpnmipa;
2484 LPPSHNOTIFY lppsn;
2485 DWORD dwIpAddr;
2486
2487
2488 switch(uMsg)
2489 {
2490 case WM_INITDIALOG:
2492 This = (TcpipConfNotifyImpl*)page->lParam;
2493 if (This->pCurrentConfig)
2494 InitializeTcpipBasicDlgCtrls(hwndDlg, This->pCurrentConfig);
2496 return TRUE;
2497 case WM_NOTIFY:
2498 lppsn = (LPPSHNOTIFY) lParam;
2499 lpnmipa = (LPNMIPADDRESS) lParam;
2500 if (lpnmipa->hdr.code == IPN_FIELDCHANGED)
2501 {
2502 PropSheet_Changed(GetParent(hwndDlg), hwndDlg);
2503 if (lpnmipa->hdr.idFrom == IDC_IPADDR)
2504 {
2505 if (SendDlgItemMessageW(hwndDlg, IDC_IPADDR, IPM_GETADDRESS, 0, (LPARAM)&dwIpAddr) == 4)
2506 {
2507 if (dwIpAddr <= MAKEIPADDRESS(127, 255, 255, 255))
2509 else if (dwIpAddr <= MAKEIPADDRESS(191, 255, 255, 255))
2511 else if (dwIpAddr <= MAKEIPADDRESS(223, 255, 255, 255))
2512 SendDlgItemMessageW(hwndDlg, IDC_SUBNETMASK, IPM_SETADDRESS, 0, (LPARAM)MAKEIPADDRESS(255, 255, 255, 0));
2513 }
2514 }
2515 }
2516 else if (lppsn->hdr.code == PSN_APPLY)
2517 {
2521 else
2523
2524 return TRUE;
2525 }
2526 break;
2527 case WM_COMMAND:
2528 if (HIWORD(wParam) == BN_CLICKED)
2529 {
2530 switch (LOWORD(wParam))
2531 {
2532 case IDC_USEDHCP:
2534 {
2535 PropSheet_Changed(GetParent(hwndDlg), hwndDlg);
2544 }
2545 break;
2546 case IDC_NODHCP:
2547 if (SendDlgItemMessageW(hwndDlg, IDC_NODHCP, BM_GETCHECK, 0, 0) == BST_CHECKED)
2548 {
2549 PropSheet_Changed(GetParent(hwndDlg), hwndDlg);
2554 {
2556 }
2561 SendMessageW(GetParent(hwndDlg), PSM_REMOVEPAGE, 1, 0);
2562 }
2563 break;
2564 case IDC_AUTODNS:
2566 {
2567 PropSheet_Changed(GetParent(hwndDlg), hwndDlg);
2572 }
2573 break;
2574 case IDC_FIXEDDNS:
2576 {
2577 PropSheet_Changed(GetParent(hwndDlg), hwndDlg);
2580 }
2581 break;
2582 case IDC_ADVANCED:
2584 break;
2585 }
2586 break;
2587 }
2588 default:
2589 break;
2590
2591 }
2592 return FALSE;
2593}
2594
2595/***************************************************************
2596 * INetCfgComponentPropertyUi interface
2597 */
2598
2599HRESULT
2600WINAPI
2602 INetCfgComponentPropertyUi * iface,
2603 REFIID iid,
2604 LPVOID * ppvObj)
2605{
2606 //LPOLESTR pStr;
2608
2609 *ppvObj = NULL;
2610
2611
2612 if (IsEqualIID (iid, &IID_IUnknown) ||
2614 {
2615 *ppvObj = This;
2617 return S_OK;
2618 }
2620 {
2621 *ppvObj = (LPVOID*)&This->lpVtblCompControl;
2623 return S_OK;
2624 }
2625
2626 //StringFromCLSID(iid, &pStr);
2627 //MessageBoxW(NULL, pStr, L"INetConnectionPropertyUi_fnQueryInterface", MB_OK);
2628 //CoTaskMemFree(pStr);
2629
2630 return E_NOINTERFACE;
2631}
2632
2633
2634ULONG
2635WINAPI
2637 INetCfgComponentPropertyUi * iface)
2638{
2640 ULONG refCount = InterlockedIncrement(&This->ref);
2641
2642 return refCount;
2643}
2644
2645ULONG
2646WINAPI
2648 INetCfgComponentPropertyUi * iface)
2649{
2651 ULONG refCount = InterlockedDecrement(&This->ref);
2652
2653 if (!refCount)
2654 {
2656 }
2657 return refCount;
2658}
2659
2660HRESULT
2661WINAPI
2663 INetCfgComponentPropertyUi * iface,
2665{
2666 INetLanConnectionUiInfo * pLanInfo;
2667 HRESULT hr;
2669
2670 hr = IUnknown_QueryInterface(pUnkReserved, &IID_INetLanConnectionUiInfo, (LPVOID*)&pLanInfo);
2671 if (FAILED(hr))
2672 return hr;
2673
2674 INetLanConnectionUiInfo_GetDeviceGuid(pLanInfo, &This->NetCfgInstanceId);
2675
2676 //FIXME
2677 // check if tcpip is enabled on that binding */
2678 IUnknown_Release(pUnkReserved);
2679 return S_OK;
2680}
2681
2682HRESULT
2683WINAPI
2685 INetCfgComponentPropertyUi * iface,
2687{
2689
2690 if (!iface || !pUnkReserved)
2691 return E_POINTER;
2692
2693 This->pUnknown = pUnkReserved;
2694 return S_OK;
2695}
2696
2697HRESULT
2700{
2701 LPOLESTR pStr;
2702 WCHAR szBuffer[200];
2703 HKEY hKey;
2704 DWORD dwSize;
2705
2706
2708 if (!This->pCurrentConfig->pDNS)
2709 return E_FAIL;
2710
2711 ZeroMemory(This->pCurrentConfig->pDNS, sizeof(TcpipAdvancedDNSDlgSettings));
2712
2713 if (FAILED(StringFromCLSID(&This->NetCfgInstanceId, &pStr)))
2714 return E_FAIL;
2715
2716 swprintf(szBuffer, L"SYSTEM\\CurrentControlSet\\Services\\Tcpip\\Parameters\\Interfaces\\%s", pStr);
2717 CoTaskMemFree(pStr);
2719 {
2720 dwSize = sizeof(DWORD);
2721 RegQueryValueExW(hKey, L"RegisterAdapterName", NULL, NULL, (LPBYTE)&This->pCurrentConfig->pDNS->RegisterAdapterName, &dwSize);
2722
2723 dwSize = sizeof(DWORD);
2724 RegQueryValueExW(hKey, L"RegistrationEnabled", NULL, NULL, (LPBYTE)&This->pCurrentConfig->pDNS->RegistrationEnabled, &dwSize);
2725
2726 dwSize = sizeof(This->pCurrentConfig->pDNS->szDomain);
2727 RegQueryValueExW(hKey, L"Domain", NULL, NULL, (LPBYTE)This->pCurrentConfig->pDNS->szDomain, &dwSize);
2728
2730 }
2731
2732 if (RegOpenKeyExW(HKEY_LOCAL_MACHINE, L"SYSTEM\\CurrentControlSet\\Services\\Tcpip\\Parameters", 0, KEY_READ, &hKey) == ERROR_SUCCESS)
2733 {
2734 dwSize = sizeof(DWORD);
2735 RegQueryValueExW(hKey, L"UseDomainNameDevolution", NULL, NULL, (LPBYTE)&This->pCurrentConfig->pDNS->UseDomainNameDevolution, &dwSize);
2736
2737 dwSize = 0;
2738 if (RegQueryValueExW(hKey, L"SearchList", NULL, NULL, NULL, &dwSize) == ERROR_SUCCESS)
2739 {
2740 This->pCurrentConfig->pDNS->szSearchList = (LPWSTR)CoTaskMemAlloc(dwSize);
2741 if (This->pCurrentConfig->pDNS->szSearchList)
2742 {
2743 if (RegQueryValueExW(hKey, L"SearchList", NULL, NULL, (LPBYTE)This->pCurrentConfig->pDNS->szSearchList, &dwSize) != ERROR_SUCCESS)
2744 {
2745 CoTaskMemFree(This->pCurrentConfig->pDNS->szSearchList);
2746 This->pCurrentConfig->pDNS->szSearchList = NULL;
2747 }
2748 }
2749 }
2751 }
2752 return S_OK;
2753}
2754
2755LPWSTR
2757{
2758 DWORD dwSize;
2759 LPWSTR pData;
2760
2762 return NULL;
2763
2765 if (!pData)
2766 return NULL;
2767
2769 {
2771 return NULL;
2772 }
2773 *Size = dwSize;
2774 return pData;
2775}
2776
2777HRESULT
2780{
2781 HKEY hKey;
2782 TcpFilterSettings *pFilter;
2783 WCHAR szBuffer[200];
2784 LPOLESTR pStr;
2785 DWORD dwVal, dwSize;
2786
2788 if (!pFilter)
2789 return E_FAIL;
2790
2791 ZeroMemory(pFilter, sizeof(TcpFilterSettings));
2792 This->pCurrentConfig->pFilter = pFilter;
2793
2794
2795 if (RegOpenKeyExW(HKEY_LOCAL_MACHINE, L"SYSTEM\\CurrentControlSet\\Services\\Tcpip\\Parameters", 0, KEY_READ, &hKey) == ERROR_SUCCESS)
2796 {
2797 dwSize = sizeof(DWORD);
2798 if (RegQueryValueExW(hKey, L"EnableSecurityFilters", NULL, NULL, (LPBYTE)&dwVal, &dwSize) == ERROR_SUCCESS)
2799 pFilter->EnableSecurityFilters = dwVal;
2801 }
2802 else
2803 {
2804 pFilter->EnableSecurityFilters = FALSE;
2805 }
2806
2807 if (FAILED(StringFromCLSID(&This->NetCfgInstanceId, &pStr)))
2808 return E_FAIL;
2809
2810 swprintf(szBuffer, L"SYSTEM\\CurrentControlSet\\Services\\Tcpip\\Parameters\\Interfaces\\%s", pStr);
2811 CoTaskMemFree(pStr);
2813 {
2814 return S_OK;
2815 }
2816 pFilter->szTCPAllowedPorts = LoadTcpFilterSettingsFromRegistry(hKey, L"TCPAllowedPorts", &pFilter->TCPSize);
2817 pFilter->szUDPAllowedPorts = LoadTcpFilterSettingsFromRegistry(hKey, L"UDPAllowedPorts", &pFilter->UDPSize);
2818 pFilter->szRawIPAllowedProtocols = LoadTcpFilterSettingsFromRegistry(hKey, L"RawIPAllowedProtocols", &pFilter->IPSize);
2820 return S_OK;
2821}
2822
2823
2824HRESULT
2826{
2828 WCHAR szBuffer[50];
2829 IP_ADAPTER_INFO * pCurrentAdapter;
2830 IP_ADAPTER_INFO * pInfo;
2831 PIP_PER_ADAPTER_INFO pPerInfo;
2833 LPOLESTR pStr;
2834 HRESULT hr;
2835 BOOL bFound;
2836 TcpipSettings * pCurSettings;
2837 ULONG uLength;
2838
2839 if (This->pCurrentConfig)
2840 return S_OK;
2841
2842 hr = StringFromCLSID(&This->NetCfgInstanceId, &pStr);
2843 if (FAILED(hr))
2844 return hr;
2845
2846
2847 dwSize = 0;
2849 {
2850 CoTaskMemFree(pStr);
2851 return E_FAIL;
2852 }
2853
2854 pInfo = CoTaskMemAlloc(dwSize);
2855 if (!pInfo)
2856 {
2857 CoTaskMemFree(pStr);
2858 return E_FAIL;
2859 }
2860
2861 if (GetAdaptersInfo(pInfo, &dwSize) != ERROR_SUCCESS)
2862 {
2863 CoTaskMemFree(pStr);
2864 CoTaskMemFree(pInfo);
2865 return E_FAIL;
2866 }
2867
2868 pCurrentAdapter = pInfo;
2869 bFound = FALSE;
2870 while(pCurrentAdapter)
2871 {
2872 szBuffer[0] = L'\0';
2873 if (MultiByteToWideChar(CP_ACP, 0, pCurrentAdapter->AdapterName, -1, szBuffer, sizeof(szBuffer)/sizeof(szBuffer[0])))
2874 {
2875 szBuffer[(sizeof(szBuffer)/sizeof(WCHAR))-1] = L'\0';
2876 }
2877 if (!_wcsicmp(szBuffer, pStr))
2878 {
2879 bFound = TRUE;
2880 break;
2881 }
2882 pCurrentAdapter = pCurrentAdapter->Next;
2883 }
2884 CoTaskMemFree(pStr);
2885
2886 if (!bFound)
2887 {
2888 CoTaskMemFree(pInfo);
2889 return E_FAIL;
2890 }
2891
2892 pCurSettings = CoTaskMemAlloc(sizeof(TcpipSettings));
2893 if (!pCurSettings)
2894 {
2895 CoTaskMemFree(pInfo);
2896 return E_FAIL;
2897 }
2898
2899 ZeroMemory(pCurSettings, sizeof(TcpipSettings));
2900 This->pCurrentConfig = pCurSettings;
2901 pCurSettings->DhcpEnabled = pCurrentAdapter->DhcpEnabled;
2902 pCurSettings->Index = pCurrentAdapter->Index;
2903
2904 if (!pCurrentAdapter->DhcpEnabled)
2905 {
2906 CopyIpAddrString(&pCurrentAdapter->IpAddressList, &pCurSettings->Ip, SUBMASK, NULL);
2907 }
2908
2909 CopyIpAddrString(&pCurrentAdapter->GatewayList, &pCurSettings->Gw, METRIC, NULL);
2910
2911 uLength = sizeof(IP_PER_ADAPTER_INFO);
2913
2914 if (GetPerAdapterInfo(pCurrentAdapter->Index, &Info, &uLength) == ERROR_BUFFER_OVERFLOW)
2915 {
2916 pPerInfo = (PIP_PER_ADAPTER_INFO)CoTaskMemAlloc(uLength);
2917 if (pPerInfo)
2918 {
2919 Status = GetPerAdapterInfo(pCurrentAdapter->Index, pPerInfo, &uLength);
2920 if (Status == NOERROR)
2921 {
2922 if (!pPerInfo->AutoconfigActive)
2923 {
2924 CopyIpAddrString(&pPerInfo->DnsServerList, &pCurSettings->Ns, IPADDR, NULL);
2925 }
2926 pCurSettings->AutoconfigActive = pPerInfo->AutoconfigActive;
2927 }
2928 CoTaskMemFree(pPerInfo);
2929 }
2930 }
2931 else
2932 {
2933 if (!Info.AutoconfigActive)
2934 {
2935 CopyIpAddrString(&Info.DnsServerList, &pCurSettings->Ns, IPADDR, NULL);
2936 }
2937 pCurSettings->AutoconfigActive = Info.AutoconfigActive;
2938 }
2939
2941 return E_FAIL;
2942
2944 return E_FAIL;
2945
2946 CoTaskMemFree(pInfo);
2947
2948 return S_OK;
2949}
2950
2951HRESULT
2952WINAPI
2954 INetCfgComponentPropertyUi * iface,
2955 DWORD *pdwDefPages,
2956 BYTE **pahpspPrivate,
2957 UINT *pcPages,
2959 LPCWSTR *pszStartPage)
2960{
2961 HPROPSHEETPAGE * hppages;
2962 UINT NumPages;
2963 HRESULT hr;
2965
2966 hr = Initialize(This);
2967 if (FAILED(hr))
2968 return hr;
2969
2970 if (This->pCurrentConfig->DhcpEnabled)
2971 NumPages = 2;
2972 else
2973 NumPages = 1;
2974
2975 hppages = (HPROPSHEETPAGE*) CoTaskMemAlloc(sizeof(HPROPSHEETPAGE) * NumPages);
2976 if (!hppages)
2977 return E_FAIL;
2978
2980 if (!hppages[0])
2981 {
2982 CoTaskMemFree(hppages);
2983 return E_FAIL;
2984 }
2985 if (NumPages == 2)
2986 {
2988 if (!hppages[1])
2989 {
2990 DestroyPropertySheetPage(hppages[0]);
2991 CoTaskMemFree(hppages);
2992 return E_FAIL;
2993 }
2994 }
2995
2996 *pahpspPrivate = (BYTE*)hppages;
2997 *pcPages = NumPages;
2998
2999 return S_OK;
3000}
3001
3002HRESULT
3003WINAPI
3005 INetCfgComponentPropertyUi * iface,
3006 HWND hwndDlg)
3007{
3008MessageBoxW(NULL, L"INetCfgComponentPropertyUi_fnValidateProperties", NULL, MB_OK);
3009 return S_OK;
3010}
3011
3012HRESULT
3013WINAPI
3015 INetCfgComponentPropertyUi * iface)
3016{
3017MessageBoxW(NULL, L"INetCfgComponentPropertyUi_fnApplyProperties", NULL, MB_OK);
3018 return S_OK;
3019}
3020
3021
3022HRESULT
3023WINAPI
3025 INetCfgComponentPropertyUi * iface)
3026{
3027//MessageBoxW(NULL, L"INetCfgComponentPropertyUi_fnCancelProperties", NULL, MB_OK);
3028 return S_OK;
3029}
3030
3031static const INetCfgComponentPropertyUiVtbl vt_NetCfgComponentPropertyUi =
3032{
3042};
3043
3044/***************************************************************
3045 * INetCfgComponentControl interface
3046 */
3047
3048HRESULT
3049WINAPI
3051 INetCfgComponentControl * iface,
3052 REFIID iid,
3053 LPVOID * ppvObj)
3054{
3056 return INetCfgComponentPropertyUi_QueryInterface((INetCfgComponentPropertyUi*)This, iid, ppvObj);
3057}
3058
3059ULONG
3060WINAPI
3062 INetCfgComponentControl * iface)
3063{
3065 return INetCfgComponentPropertyUi_AddRef((INetCfgComponentPropertyUi*)This);
3066}
3067
3068ULONG
3069WINAPI
3071 INetCfgComponentControl * iface)
3072{
3074 return INetCfgComponentPropertyUi_Release((INetCfgComponentPropertyUi*)This);
3075}
3076
3077HRESULT
3078WINAPI
3080 INetCfgComponentControl * iface,
3081 INetCfgComponent *pIComp,
3082 INetCfg *pINetCfg,
3083 BOOL fInstalling)
3084{
3086
3087 This->pNCfg = pINetCfg;
3088 This->pNComp = pIComp;
3089
3090 return S_OK;
3091}
3092
3093static
3094LPWSTR
3096{
3097 LPWSTR pStr, pRet;
3098 DWORD dwSize, dwIpAddr;
3099 WCHAR szBuffer[30];
3100 IP_ADDR *pTemp = pAddr;
3101
3102
3103 dwSize = 0;
3104 while(pTemp)
3105 {
3106 if (Type == IPADDR)
3107 {
3108 dwIpAddr = pTemp->IpAddress;
3109 swprintf(szBuffer, L"%lu.%lu.%lu.%lu",
3110 FIRST_IPADDRESS(dwIpAddr), SECOND_IPADDRESS(dwIpAddr), THIRD_IPADDRESS(dwIpAddr), FOURTH_IPADDRESS(dwIpAddr));
3111 }else if (Type == SUBMASK)
3112 {
3113 dwIpAddr = pTemp->u.Subnetmask;
3114 swprintf(szBuffer, L"%lu.%lu.%lu.%lu",
3115 FIRST_IPADDRESS(dwIpAddr), SECOND_IPADDRESS(dwIpAddr), THIRD_IPADDRESS(dwIpAddr), FOURTH_IPADDRESS(dwIpAddr));
3116 }
3117 else if (Type == METRIC)
3118 {
3119 swprintf(szBuffer, L"%u", pTemp->u.Metric);
3120 }
3121
3122 dwSize += wcslen(szBuffer) + 1;
3123 pTemp = pTemp->Next;
3124 }
3125
3126 if (!dwSize)
3127 return NULL;
3128
3129 pStr = pRet = CoTaskMemAlloc((dwSize+1) * sizeof(WCHAR));
3130 if(!pStr)
3131 return NULL;
3132
3133 pTemp = pAddr;
3134 while(pTemp)
3135 {
3136 if (Type == IPADDR)
3137 {
3138 dwIpAddr = pTemp->IpAddress;
3139 swprintf(pStr, L"%lu.%lu.%lu.%lu",
3140 FIRST_IPADDRESS(dwIpAddr), SECOND_IPADDRESS(dwIpAddr), THIRD_IPADDRESS(dwIpAddr), FOURTH_IPADDRESS(dwIpAddr));
3141 }else if (Type == SUBMASK)
3142 {
3143 dwIpAddr = pTemp->u.Subnetmask;
3144 swprintf(pStr, L"%lu.%lu.%lu.%lu",
3145 FIRST_IPADDRESS(dwIpAddr), SECOND_IPADDRESS(dwIpAddr), THIRD_IPADDRESS(dwIpAddr), FOURTH_IPADDRESS(dwIpAddr));
3146 }
3147 else if (Type == METRIC)
3148 {
3149 swprintf(pStr, L"%u", pTemp->u.Metric);
3150 }
3151
3152 if (bComma)
3153 {
3154 pStr += wcslen(pStr);
3155 if (pTemp->Next)
3156 {
3157 pStr[0] = L',';
3158 pStr++;
3159 }
3160 }
3161 else
3162 {
3163 pStr += wcslen(pStr) + 1;
3164 }
3165 pTemp = pTemp->Next;
3166 }
3167 pStr[0] = L'\0';
3168 *Size = (dwSize+1) * sizeof(WCHAR);
3169 return pRet;
3170}
3171
3172
3173HRESULT
3174WINAPI
3176 INetCfgComponentControl * iface)
3177{
3178 HKEY hKey;
3179 LPOLESTR pStr;
3180 DWORD dwSize;
3181 WCHAR szBuffer[200];
3182 TcpipSettings * pCurrentConfig, *pOldConfig;
3183 ULONG NTEInstance;
3184 DWORD DhcpApiVersion;
3185
3187
3188 pCurrentConfig = This->pCurrentConfig;
3189 This->pCurrentConfig = NULL;
3190
3191 if (FAILED(Initialize(This)))
3192 {
3193 This->pCurrentConfig = pCurrentConfig;
3194 return E_FAIL;
3195 }
3196 pOldConfig = This->pCurrentConfig;
3197 This->pCurrentConfig = pCurrentConfig;
3198
3199 //MessageBoxW(NULL, L"INetCfgComponentControl_fnApplyRegistryChanges", NULL, MB_OK);
3200
3201
3202 if (RegCreateKeyExW(HKEY_LOCAL_MACHINE, L"SYSTEM\\CurrentControlSet\\Services\\Tcpip\\Parameters", 0, NULL, 0, KEY_WRITE, NULL, &hKey, NULL) == ERROR_SUCCESS)
3203 {
3204 if (pCurrentConfig->pDNS)
3205 {
3206 RegSetValueExW(hKey, L"UseDomainNameDevolution", 0, REG_DWORD, (LPBYTE)&pCurrentConfig->pDNS->UseDomainNameDevolution, sizeof(DWORD));
3207 RegSetValueExW(hKey, L"SearchList", 0, REG_SZ, (LPBYTE)pCurrentConfig->pDNS->szSearchList,
3208 (wcslen(pCurrentConfig->pDNS->szSearchList)+1) * sizeof(WCHAR));
3209 }
3210 if (pCurrentConfig->pFilter)
3211 {
3212 RegSetValueExW(hKey, L"EnableSecurityFilters", 0, REG_DWORD,
3213 (LPBYTE)&pCurrentConfig->pFilter->EnableSecurityFilters, sizeof(DWORD));
3214 }
3216 }
3217
3218 if (FAILED(StringFromCLSID(&This->NetCfgInstanceId, &pStr)))
3219 return E_FAIL;
3220
3221 swprintf(szBuffer, L"SYSTEM\\CurrentControlSet\\Services\\Tcpip\\Parameters\\Interfaces\\%s", pStr);
3222 CoTaskMemFree(pStr);
3223
3225 {
3226 if (pCurrentConfig->pDNS)
3227 {
3228 RegSetValueExW(hKey, L"RegisterAdapterName", 0, REG_DWORD, (LPBYTE)&This->pCurrentConfig->pDNS->RegisterAdapterName, sizeof(DWORD));
3229 RegSetValueExW(hKey, L"RegistrationEnabled", 0, REG_DWORD, (LPBYTE)&This->pCurrentConfig->pDNS->RegistrationEnabled, sizeof(DWORD));
3230 RegSetValueExW(hKey, L"Domain", 0, REG_SZ, (LPBYTE)This->pCurrentConfig->pDNS->szDomain,
3231 (wcslen(This->pCurrentConfig->pDNS->szDomain)+1) * sizeof(WCHAR));
3232 }
3233#if 0
3234 if (pCurrentConfig->pFilter)
3235 {
3236 if (pCurrentConfig->pFilter->szTCPAllowedPorts)
3237 {
3238 RegSetValueExW(hKey, L"TCPAllowedPorts", 0, REG_MULTI_SZ,
3239 (LPBYTE)pCurrentConfig->pFilter->szTCPAllowedPorts,
3240 pCurrentConfig->pFilter->TCPSize);
3241 }
3242 if (pCurrentConfig->pFilter->szUDPAllowedPorts)
3243 {
3244 RegSetValueExW(hKey, L"UDPAllowedPorts", 0, REG_MULTI_SZ,
3245 (LPBYTE)pCurrentConfig->pFilter->szUDPAllowedPorts,
3246 pCurrentConfig->pFilter->UDPSize);
3247 }
3248 if (pCurrentConfig->pFilter->szRawIPAllowedProtocols)
3249 {
3250 RegSetValueExW(hKey, L"RawIPAllowedProtocols", 0, REG_MULTI_SZ,
3251 (LPBYTE)pCurrentConfig->pFilter->szRawIPAllowedProtocols,
3252 pCurrentConfig->pFilter->IPSize);
3253 }
3254 }
3255#endif
3256 RegSetValueExW(hKey, L"EnableDHCP", 0, REG_DWORD, (LPBYTE)&pCurrentConfig->DhcpEnabled, sizeof(DWORD));
3257 if (pCurrentConfig->DhcpEnabled)
3258 {
3259 RegSetValueExW(hKey, L"IPAddress", 0, REG_MULTI_SZ, (LPBYTE)L"0.0.0.0\0", 9 * sizeof(WCHAR));
3260 RegSetValueExW(hKey, L"SubnetMask", 0, REG_MULTI_SZ, (LPBYTE)L"0.0.0.0\0", 9 * sizeof(WCHAR));
3261 if (!pOldConfig->DhcpEnabled)
3262 {
3263 /* Delete this adapter's current IP address */
3264 DeleteIPAddress(pOldConfig->Ip->NTEContext);
3265
3266 /* Delete all default routes for this adapter */
3267 dwSize = 0;
3269 {
3270 DWORD Index;
3272 if (pIpForwardTable)
3273 {
3274 if (GetIpForwardTable(pIpForwardTable, &dwSize, FALSE) == NO_ERROR)
3275 {
3276 for (Index = 0; Index < pIpForwardTable->dwNumEntries; Index++)
3277 {
3278 if (pIpForwardTable->table[Index].dwForwardIfIndex == pOldConfig->Index &&
3279 pIpForwardTable->table[Index].dwForwardDest == 0)
3280 {
3281 DeleteIpForwardEntry(&pIpForwardTable->table[Index]);
3282 }
3283 }
3284 }
3285 CoTaskMemFree(pIpForwardTable);
3286 }
3287 }
3288 }
3289 }
3290 else
3291 {
3292 /* Open the DHCP API if DHCP is enabled */
3293 if (pOldConfig->DhcpEnabled && DhcpCApiInitialize(&DhcpApiVersion) == NO_ERROR)
3294 {
3295 /* We have to tell DHCP about this */
3296 DhcpStaticRefreshParams(pCurrentConfig->Index,
3297 htonl(pCurrentConfig->Ip->IpAddress),
3298 htonl(pCurrentConfig->Ip->u.Subnetmask));
3299
3300 /* Close the API */
3302 }
3303 else
3304 {
3305 /* Delete this adapter's current static IP address */
3306 DeleteIPAddress(pOldConfig->Ip->NTEContext);
3307
3308 /* Add the static IP address via the standard IPHLPAPI function */
3309 AddIPAddress(htonl(pCurrentConfig->Ip->IpAddress),
3310 htonl(pCurrentConfig->Ip->u.Subnetmask),
3311 pCurrentConfig->Index,
3312 &pCurrentConfig->Ip->NTEContext,
3313 &NTEInstance);
3314 }
3315
3316 pStr = CreateMultiSzString(pCurrentConfig->Ip, IPADDR, &dwSize, FALSE);
3317 if(pStr)
3318 {
3319 RegSetValueExW(hKey, L"IPAddress", 0, REG_MULTI_SZ, (LPBYTE)pStr, dwSize);
3320 CoTaskMemFree(pStr);
3321 }
3322
3323 pStr = CreateMultiSzString(pCurrentConfig->Ip, SUBMASK, &dwSize, FALSE);
3324 if(pStr)
3325 {
3326 RegSetValueExW(hKey, L"SubnetMask", 0, REG_MULTI_SZ, (LPBYTE)pStr, dwSize);
3327 CoTaskMemFree(pStr);
3328 }
3329
3330 /* Delete all default routes for this adapter */
3331 dwSize = 0;
3333 {
3334 DWORD Index;
3336 if (pIpForwardTable)
3337 {
3338 if (GetIpForwardTable(pIpForwardTable, &dwSize, FALSE) == NO_ERROR)
3339 {
3340 for (Index = 0; Index < pIpForwardTable->dwNumEntries; Index++)
3341 {
3342 if (pIpForwardTable->table[Index].dwForwardIfIndex == pOldConfig->Index &&
3343 pIpForwardTable->table[Index].dwForwardDest == 0)
3344 {
3345 DeleteIpForwardEntry(&pIpForwardTable->table[Index]);
3346 }
3347 }
3348 }
3349 CoTaskMemFree(pIpForwardTable);
3350 }
3351 }
3352 }
3353
3354 if (pCurrentConfig->Gw)
3355 {
3356 MIB_IPFORWARDROW RouterMib;
3357 ZeroMemory(&RouterMib, sizeof(MIB_IPFORWARDROW));
3358
3359 RouterMib.dwForwardMetric1 = 1;
3360 RouterMib.dwForwardIfIndex = pOldConfig->Index;
3361 RouterMib.dwForwardNextHop = htonl(pCurrentConfig->Gw->IpAddress);
3362
3363 //TODO
3364 // add multiple gw addresses when required
3365
3366 if (CreateIpForwardEntry(&RouterMib) == NO_ERROR)
3367 {
3368 pStr = CreateMultiSzString(pCurrentConfig->Gw, IPADDR, &dwSize, FALSE);
3369 if(pStr)
3370 {
3371 RegSetValueExW(hKey, L"DefaultGateway", 0, REG_MULTI_SZ, (LPBYTE)pStr, dwSize);
3372 CoTaskMemFree(pStr);
3373 }
3374
3375 pStr = CreateMultiSzString(pCurrentConfig->Gw, METRIC, &dwSize, FALSE);
3376 if(pStr)
3377 {
3378 RegSetValueExW(hKey, L"DefaultGatewayMetric", 0, REG_MULTI_SZ, (LPBYTE)pStr, dwSize);
3379 CoTaskMemFree(pStr);
3380 }
3381 }
3382 }
3383 else
3384 {
3385 RegSetValueExW(hKey, L"DefaultGateway", 0, REG_MULTI_SZ, (LPBYTE)L"", 1 * sizeof(WCHAR));
3386 RegSetValueExW(hKey, L"DefaultGatewayMetric", 0, REG_MULTI_SZ, (LPBYTE)L"\0", sizeof(WCHAR) * 2);
3387 }
3388
3389 if (!pCurrentConfig->Ns || pCurrentConfig->AutoconfigActive)
3390 {
3391 RegDeleteValueW(hKey, L"NameServer");
3392 }
3393 else
3394 {
3395 pStr = CreateMultiSzString(pCurrentConfig->Ns, IPADDR, &dwSize, TRUE);
3396 if(pStr)
3397 {
3398 RegSetValueExW(hKey, L"NameServer", 0, REG_SZ, (LPBYTE)pStr, dwSize);
3399 //RegDeleteValueW(hKey, L"DhcpNameServer");
3400 CoTaskMemFree(pStr);
3401 }
3402 }
3403
3405 }
3406 return S_OK;
3407}
3408
3409HRESULT
3410WINAPI
3412 INetCfgComponentControl * iface,
3413 INetCfgPnpReconfigCallback *pICallback)
3414{
3415 //MessageBoxW(NULL, L"INetCfgComponentControl_fnApplyPnpChanges", NULL, MB_OK);
3416 return S_OK;
3417}
3418
3419HRESULT
3420WINAPI
3422 INetCfgComponentControl * iface)
3423{
3424 //MessageBoxW(NULL, L"INetCfgComponentControl_fnCancelChanges", NULL, MB_OK);
3425 return S_OK;
3426}
3427
3428static const INetCfgComponentControlVtbl vt_NetCfgComponentControl =
3429{
3437};
3438
3439HRESULT
3440WINAPI
3442{
3444
3445 if (!ppv)
3446 return E_POINTER;
3447
3449 if (!This)
3450 return E_OUTOFMEMORY;
3451
3452 This->ref = 1;
3453 This->lpVtbl = (const INetCfgComponentPropertyUi*)&vt_NetCfgComponentPropertyUi;
3454 This->lpVtblCompControl = (const INetCfgComponentControl*)&vt_NetCfgComponentControl;
3455 This->pNCfg = NULL;
3456 This->pUnknown = NULL;
3457 This->pNComp = NULL;
3458 This->pCurrentConfig = NULL;
3459
3460 if (!SUCCEEDED (INetCfgComponentPropertyUi_QueryInterface ((INetCfgComponentPropertyUi*)This, riid, ppv)))
3461 {
3462 INetCfgComponentPropertyUi_Release((INetCfgComponentPropertyUi*)This);
3463 return E_NOINTERFACE;
3464 }
3465
3466 INetCfgComponentPropertyUi_Release((INetCfgComponentPropertyUi*)This);
3467 return S_OK;
3468}
Type
Definition: Type.h:7
#define InterlockedIncrement
Definition: armddk.h:53
#define InterlockedDecrement
Definition: armddk.h:52
#define IDC_OK
Definition: resource.h:59
static void AddButton(HWND hwndToolBar, int nImage, int nCommand)
Definition: wordpad.c:155
const GUID IID_IUnknown
#define RegCloseKey(hKey)
Definition: registry.h:47
WPARAM wParam
Definition: combotst.c:138
LPARAM lParam
Definition: combotst.c:139
static HWND hwndParent
Definition: cryptui.c:300
static TAGID TAGID find
Definition: db.cpp:155
#define NO_ERROR
Definition: dderror.h:5
#define ERROR_INSUFFICIENT_BUFFER
Definition: dderror.h:10
#define E_OUTOFMEMORY
Definition: ddrawi.h:100
#define E_FAIL
Definition: ddrawi.h:102
#define BufferSize
Definition: mmc.h:75
#define DLGPROC
Definition: maze.c:62
#define ERROR_SUCCESS
Definition: deptool.c:10
void WINAPI DhcpCApiCleanup(void)
Definition: dhcpcsvc.c:71
DWORD APIENTRY DhcpCApiInitialize(LPDWORD Version)
Definition: dhcpcsvc.c:26
DWORD APIENTRY DhcpStaticRefreshParams(DWORD AdapterIndex, DWORD Address, DWORD Netmask)
Definition: dhcpcsvc.c:191
#define NULL
Definition: types.h:112
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
#define IDS_METRIC
Definition: resource.h:77
#define IDC_ADVANCED
Definition: resource.h:11
LONG WINAPI RegCreateKeyExW(_In_ HKEY hKey, _In_ LPCWSTR lpSubKey, _In_ DWORD Reserved, _In_opt_ LPWSTR lpClass, _In_ DWORD dwOptions, _In_ REGSAM samDesired, _In_opt_ LPSECURITY_ATTRIBUTES lpSecurityAttributes, _Out_ PHKEY phkResult, _Out_opt_ LPDWORD lpdwDisposition)
Definition: reg.c:1091
LONG WINAPI RegOpenKeyExW(HKEY hKey, LPCWSTR lpSubKey, DWORD ulOptions, REGSAM samDesired, PHKEY phkResult)
Definition: reg.c:3353
LONG WINAPI RegSetValueExW(_In_ HKEY hKey, _In_ LPCWSTR lpValueName, _In_ DWORD Reserved, _In_ DWORD dwType, _In_ CONST BYTE *lpData, _In_ DWORD cbData)
Definition: reg.c:4897
LONG WINAPI RegDeleteValueW(HKEY hKey, LPCWSTR lpValueName)
Definition: reg.c:2352
LONG WINAPI RegQueryValueExW(_In_ HKEY hkeyorg, _In_ LPCWSTR name, _In_ LPDWORD reserved, _In_ LPDWORD type, _In_ LPBYTE data, _In_ LPDWORD count)
Definition: reg.c:4118
HPROPSHEETPAGE WINAPI CreatePropertySheetPageW(LPCPROPSHEETPAGEW lpPropSheetPage)
Definition: propsheet.c:3075
INT_PTR WINAPI PropertySheetW(LPCPROPSHEETHEADERW lppsh)
Definition: propsheet.c:2905
BOOL WINAPI DestroyPropertySheetPage(HPROPSHEETPAGE hPropPage)
Definition: propsheet.c:3144
#define wcschr
Definition: compat.h:17
#define CP_ACP
Definition: compat.h:109
#define CALLBACK
Definition: compat.h:35
#define MultiByteToWideChar
Definition: compat.h:110
HINSTANCE netcfgx_hInstance
Definition: netcfgx.c:15
#define IDC_NODHCP
Definition: resource.h:24
#define IDS_TCPFILTERDESC
Definition: resource.h:101
#define IDC_IPDEL
Definition: resource.h:37
#define IDS_DISABLE_FILTER
Definition: resource.h:119
#define IDC_GWADD
Definition: resource.h:39
#define IDC_IP_RESTRICT
Definition: resource.h:82
#define IDC_DNS1
Definition: resource.h:30
#define IDC_DNSADDRMOD
Definition: resource.h:52
#define IDD_TCPIP_ADVOPT_DLG
Definition: resource.h:12
#define IDC_OPTLIST
Definition: resource.h:67
#define IDC_DNSSUFFIXLIST
Definition: resource.h:57
#define IDS_PROT_RANGE
Definition: resource.h:117
#define IDS_TCP_PORTS
Definition: resource.h:113
#define IDD_TCPIPADDIP_DLG
Definition: resource.h:14
#define IDC_PORT_VAL
Definition: resource.h:88
#define IDC_IP_DEL
Definition: resource.h:85
#define IDC_DNSSUFFIXUP
Definition: resource.h:58
#define IDC_DNSSUFFIXDEL
Definition: resource.h:62
#define IDC_GWDEL
Definition: resource.h:41
#define IDC_AUTOMETRIC
Definition: resource.h:42
#define IDC_IP_ALLOW_ALL
Definition: resource.h:81
#define IDS_SUBMASK
Definition: resource.h:104
#define IDS_DUP_GW
Definition: resource.h:125
#define IDC_DNSSUFFIXDOWN
Definition: resource.h:59
#define IDS_NOITEMSEL
Definition: resource.h:109
#define IDD_TCPIP_ALTCF_DLG
Definition: resource.h:9
#define IDC_USEDHCP
Definition: resource.h:23
#define IDC_SUBNETMASK
Definition: resource.h:26
#define IDC_FIXEDDNS
Definition: resource.h:29
#define IDD_TCPIP_FILTER_DLG
Definition: resource.h:13
#define IDC_SUFFIX
Definition: resource.h:63
#define IDD_TCPIPDNS_DLG
Definition: resource.h:16
#define IDC_IPLIST
Definition: resource.h:34
#define IDC_OPTPROP
Definition: resource.h:68
#define IDC_USESUFFIX
Definition: resource.h:65
#define IDC_DNSADDRADD
Definition: resource.h:51
#define IDC_USE_FILTER
Definition: resource.h:86
#define IDC_IP_LIST
Definition: resource.h:83
#define IDC_USEMETRIC
Definition: resource.h:45
#define IDD_TCPIPGW_DLG
Definition: resource.h:15
#define IDC_AUTODNS
Definition: resource.h:28
#define IDD_TCPIP_ADVIP_DLG
Definition: resource.h:10
#define IDC_METRICTXT
Definition: resource.h:44
#define IDC_UDP_LIST
Definition: resource.h:78
#define IDS_IP_PROTO
Definition: resource.h:115
#define IDC_TCP_RESTRICT
Definition: resource.h:72
#define IDC_GWMOD
Definition: resource.h:40
#define IDS_AUTOMATIC
Definition: resource.h:108
#define IDC_METRIC
Definition: resource.h:43
#define IDC_DNS2
Definition: resource.h:31
#define IDC_TCP_ADD
Definition: resource.h:74
#define IDS_DHCPACTIVE
Definition: resource.h:107
#define IDS_TCPIP
Definition: resource.h:110
#define IDC_DEFGATEWAY
Definition: resource.h:27
#define IDC_UDP_DEL
Definition: resource.h:80
#define IDC_IP_ADD
Definition: resource.h:84
#define IDS_DOMAIN_SUFFIX
Definition: resource.h:121
#define IDC_DNSADDRDEL
Definition: resource.h:53
#define IDS_UDP_PORTS
Definition: resource.h:114
#define IDC_UDP_ALLOW_ALL
Definition: resource.h:76
#define IDC_TCP_ALLOW_ALL
Definition: resource.h:71
#define IDC_DNSADDRUP
Definition: resource.h:49
#define IDS_NO_SUBMASK_SET
Definition: resource.h:100
#define IDS_TCPFILTER
Definition: resource.h:102
#define IDS_DUP_NUMBER
Definition: resource.h:118
#define IDC_REGSUFFIX
Definition: resource.h:64
#define IDC_PRIMSUFFIX
Definition: resource.h:54
#define IDS_NO_SUFFIX
Definition: resource.h:120
#define IDD_TCPIP_BASIC_DLG
Definition: resource.h:8
#define IDS_GATEWAY
Definition: resource.h:105
#define IDD_TCPIPSUFFIX_DLG
Definition: resource.h:17
#define IDS_PORT_RANGE
Definition: resource.h:116
#define IDC_IPADD
Definition: resource.h:35
#define IDC_IPMOD
Definition: resource.h:36
#define IDD_TCPIP_ADVDNS_DLG
Definition: resource.h:11
#define IDC_TCP_LIST
Definition: resource.h:73
#define IDS_ADD
Definition: resource.h:111
#define IDC_UDP_ADD
Definition: resource.h:79
#define IDS_DUP_IPADDR
Definition: resource.h:124
#define IDC_UDP_RESTRICT
Definition: resource.h:77
#define IDC_SELSUFFIX
Definition: resource.h:56
#define IDS_MOD
Definition: resource.h:112
#define IDC_IPADDR
Definition: resource.h:25
#define IDI_NETWORK
Definition: resource.h:4
#define IDS_DUP_SUFFIX
Definition: resource.h:123
#define IDC_DNSADDRDOWN
Definition: resource.h:50
#define IDS_IPADDR
Definition: resource.h:103
#define IDC_PORT_DESC
Definition: resource.h:87
#define IDS_DNS_SUFFIX
Definition: resource.h:122