mirror of
https://github.com/reactos/reactos.git
synced 2024-12-28 10:04:49 +00:00
tcpip: make sure to clean up failed adapter bindings
ndis: manage global adapter list correctly ncpa: wip code from my old tree ... it can now be used to set a static ip addr at least. more to come svn path=/trunk/; revision=21851
This commit is contained in:
parent
2160fab7c2
commit
5a74450800
9 changed files with 288 additions and 339 deletions
|
@ -77,7 +77,7 @@ BEGIN
|
|||
LTEXT "Alternate DNS server:", -1, 14, 186, 135, 8
|
||||
CONTROL "",IDC_DNS2,"SysIPAddress32",WS_TABSTOP,150,186-2,80,12
|
||||
PUSHBUTTON "&Advanced", IDC_ADVANCED, 186, 209, 50, 14, WS_DISABLED | WS_TABSTOP
|
||||
}
|
||||
END
|
||||
|
||||
|
||||
STRINGTABLE
|
||||
|
|
|
@ -322,22 +322,24 @@ NICPropertyPageProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
|
|||
|
||||
if(_tcscmp(tpszTCPIPClsID,tpszClsIDText)==0)
|
||||
{
|
||||
IP_ADAPTER_INFO Adapters[64];
|
||||
IP_ADAPTER_INFO *Adapters = LocalAlloc( LMEM_FIXED, sizeof(IP_ADAPTER_INFO) * 64 );
|
||||
IP_ADAPTER_INFO *pAdapter;
|
||||
TCHAR *tpszCfgInstanceID;
|
||||
DWORD dwSize = sizeof(Adapters);
|
||||
memset(&Adapters,0x00,sizeof(Adapters));
|
||||
DWORD dwSize = sizeof(*Adapters) * 64;
|
||||
memset(Adapters,0x00,dwSize);
|
||||
if(GetAdaptersInfo(Adapters,&dwSize)!=ERROR_SUCCESS)
|
||||
break;;
|
||||
break;
|
||||
pAdapter = Adapters;
|
||||
tpszCfgInstanceID = (TCHAR*)pPage->lParam;
|
||||
while(pAdapter)
|
||||
{
|
||||
TCHAR tpszAdatperName[MAX_PATH];
|
||||
swprintf(tpszAdatperName,L"%S",pAdapter->AdapterName);
|
||||
DPRINT("IPHLPAPI returned: %S\n", tpszAdatperName);
|
||||
if(_tcscmp(tpszAdatperName,tpszCfgInstanceID)==0)
|
||||
TCHAR tpszAdatperName[MAX_PATH];
|
||||
swprintf(tpszAdatperName,L"%S",pAdapter->AdapterName);
|
||||
DPRINT("IPHLPAPI returned: %S\n", tpszAdatperName);
|
||||
if(_tcscmp(tpszAdatperName,tpszCfgInstanceID)==0)
|
||||
{
|
||||
memcpy(Adapters,pAdapter,sizeof(*pAdapter));
|
||||
pAdapter = Adapters;
|
||||
DisplayTCPIPProperties(hwndDlg,pAdapter);
|
||||
break;
|
||||
} else
|
||||
|
|
|
@ -1,10 +1,29 @@
|
|||
/*
|
||||
* PROJECT: ReactOS Network Control Panel
|
||||
* LICENSE: GPL - See COPYING in the top level directory
|
||||
* FILE: lib/cpl/system/tcpip_properties.c
|
||||
* PURPOSE: ReactOS Network Control Panel
|
||||
* COPYRIGHT: Copyright 2004 Gero Kuehn (reactos.filter@gkware.com)
|
||||
* Copyright 2006 Ge van Geldorp <gvg@reactos.org>
|
||||
* ReactOS
|
||||
* Copyright (C) 2004 ReactOS Team
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
||||
*/
|
||||
/* $Id$
|
||||
*
|
||||
* PROJECT: ReactOS Network Control Panel
|
||||
* FILE: lib/cpl/system/tcpip_properties.c
|
||||
* PURPOSE: ReactOS Network Control Panel
|
||||
* PROGRAMMER: Gero Kuehn (reactos.filter@gkware.com)
|
||||
* UPDATE HISTORY:
|
||||
* 08-15-2004 Created
|
||||
*/
|
||||
|
||||
#include <stdlib.h>
|
||||
|
@ -30,368 +49,263 @@
|
|||
|
||||
#endif
|
||||
|
||||
|
||||
#include "resource.h"
|
||||
#include "ncpa.h"
|
||||
|
||||
#define NDEBUG
|
||||
#include <debug.h>
|
||||
extern void InitPropSheetPage(PROPSHEETPAGE *psp, WORD idDlg, DLGPROC DlgProc, LPARAM lParam);
|
||||
|
||||
typedef struct _TCPIP_PROPERTIES_DATA {
|
||||
DWORD AdapterIndex;
|
||||
char *AdapterName;
|
||||
BOOL DhcpEnabled;
|
||||
DWORD IpAddress;
|
||||
DWORD SubnetMask;
|
||||
DWORD Gateway;
|
||||
DWORD Dns1;
|
||||
DWORD Dns2;
|
||||
BOOL OldDhcpEnabled;
|
||||
DWORD OldIpAddress;
|
||||
DWORD OldSubnetMask;
|
||||
DWORD OldGateway;
|
||||
DWORD OldDns1;
|
||||
DWORD OldDns2;
|
||||
} TCPIP_PROPERTIES_DATA, *PTCPIP_PROPERTIES_DATA;
|
||||
|
||||
void InitPropSheetPage(PROPSHEETPAGE *psp, WORD idDlg, DLGPROC DlgProc);
|
||||
DWORD APIENTRY DhcpNotifyConfigChange(LPWSTR ServerName, LPWSTR AdapterName,
|
||||
BOOL NewIpAddress, DWORD IpIndex,
|
||||
DWORD IpAddress, DWORD SubnetMask,
|
||||
int DhcpAction);
|
||||
|
||||
|
||||
static void
|
||||
ManualDNS(HWND Dlg, BOOL Enabled) {
|
||||
CheckDlgButton(Dlg, IDC_FIXEDDNS,
|
||||
Enabled ? BST_CHECKED : BST_UNCHECKED);
|
||||
CheckDlgButton(Dlg, IDC_AUTODNS,
|
||||
Enabled ? BST_UNCHECKED : BST_CHECKED);
|
||||
EnableWindow(GetDlgItem(Dlg, IDC_DNS1), Enabled);
|
||||
EnableWindow(GetDlgItem(Dlg, IDC_DNS2), Enabled);
|
||||
if (! Enabled) {
|
||||
SendDlgItemMessage(Dlg, IDC_DNS1, IPM_CLEARADDRESS, 0, 0);
|
||||
SendDlgItemMessage(Dlg, IDC_DNS2, IPM_CLEARADDRESS, 0, 0);
|
||||
}
|
||||
void EnableDHCP( HWND hwndDlg, BOOL Enabled ) {
|
||||
CheckDlgButton(hwndDlg,IDC_USEDHCP,Enabled ? BST_CHECKED : BST_UNCHECKED);
|
||||
CheckDlgButton(hwndDlg,IDC_NODHCP,Enabled ? BST_UNCHECKED : BST_CHECKED);
|
||||
}
|
||||
|
||||
static void
|
||||
EnableDHCP(HWND Dlg, BOOL Enabled) {
|
||||
CheckDlgButton(Dlg, IDC_USEDHCP, Enabled ? BST_CHECKED : BST_UNCHECKED);
|
||||
CheckDlgButton(Dlg, IDC_NODHCP, Enabled ? BST_UNCHECKED : BST_CHECKED);
|
||||
EnableWindow(GetDlgItem(Dlg, IDC_IPADDR), ! Enabled);
|
||||
EnableWindow(GetDlgItem(Dlg, IDC_SUBNETMASK), ! Enabled);
|
||||
EnableWindow(GetDlgItem(Dlg, IDC_DEFGATEWAY), ! Enabled);
|
||||
EnableWindow(GetDlgItem(Dlg, IDC_AUTODNS), Enabled);
|
||||
if (Enabled) {
|
||||
SendDlgItemMessage(Dlg, IDC_IPADDR, IPM_CLEARADDRESS, 0, 0);
|
||||
SendDlgItemMessage(Dlg, IDC_SUBNETMASK, IPM_CLEARADDRESS, 0, 0);
|
||||
SendDlgItemMessage(Dlg, IDC_DEFGATEWAY, IPM_CLEARADDRESS, 0, 0);
|
||||
} else {
|
||||
ManualDNS(Dlg, TRUE);
|
||||
}
|
||||
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);
|
||||
}
|
||||
|
||||
static void
|
||||
ShowError(HWND Parent, UINT MsgId)
|
||||
{
|
||||
WCHAR Error[32], Msg[64];
|
||||
BOOL GetAddressFromField( HWND hwndDlg, UINT CtlId,
|
||||
DWORD *dwIPAddr,
|
||||
const char **AddressString ) {
|
||||
LRESULT lResult;
|
||||
struct in_addr inIPAddr;
|
||||
|
||||
if (0 == LoadStringW((HINSTANCE) GetWindowLongPtrW(Parent, GWLP_HINSTANCE),
|
||||
IDS_ERROR, Error, sizeof(Error) / sizeof(Error[0]))) {
|
||||
wcscpy(Error, L"Error");
|
||||
}
|
||||
if (0 == LoadStringW((HINSTANCE) GetWindowLongPtrW(Parent, GWLP_HINSTANCE),
|
||||
MsgId, Msg, sizeof(Msg) / sizeof(Msg[0]))) {
|
||||
wcscpy(Msg, L"Unknown error");
|
||||
}
|
||||
MessageBoxW(Parent, Msg, Error, MB_OK | MB_ICONSTOP);
|
||||
}
|
||||
*AddressString = NULL;
|
||||
|
||||
static BOOL
|
||||
ValidateAndStore(HWND Dlg, PTCPIP_PROPERTIES_DATA DlgData)
|
||||
{
|
||||
DWORD IpAddress;
|
||||
|
||||
DlgData->DhcpEnabled = (BST_CHECKED ==
|
||||
IsDlgButtonChecked(Dlg, IDC_USEDHCP));
|
||||
if (! DlgData->DhcpEnabled) {
|
||||
if (4 != SendMessageW(GetDlgItem(Dlg, IDC_IPADDR), IPM_GETADDRESS,
|
||||
0, (LPARAM) &IpAddress)) {
|
||||
ShowError(Dlg, IDS_ENTER_VALID_IPADDRESS);
|
||||
SetFocus(GetDlgItem(Dlg, IDC_IPADDR));
|
||||
return FALSE;
|
||||
}
|
||||
DlgData->IpAddress = htonl(IpAddress);
|
||||
if (4 != SendMessageW(GetDlgItem(Dlg, IDC_SUBNETMASK), IPM_GETADDRESS,
|
||||
0, (LPARAM) &IpAddress)) {
|
||||
ShowError(Dlg, IDS_ENTER_VALID_SUBNET);
|
||||
SetFocus(GetDlgItem(Dlg, IDC_SUBNETMASK));
|
||||
return FALSE;
|
||||
}
|
||||
DlgData->SubnetMask = htonl(IpAddress);
|
||||
if (4 != SendMessageW(GetDlgItem(Dlg, IDC_DEFGATEWAY), IPM_GETADDRESS,
|
||||
0, (LPARAM) &IpAddress)) {
|
||||
DlgData->Gateway = INADDR_NONE;
|
||||
} else {
|
||||
DlgData->Gateway = htonl(IpAddress);
|
||||
}
|
||||
ASSERT(BST_CHECKED == IsDlgButtonChecked(Dlg, IDC_FIXEDDNS));
|
||||
} else {
|
||||
DlgData->IpAddress = INADDR_NONE;
|
||||
DlgData->SubnetMask = INADDR_NONE;
|
||||
DlgData->Gateway = INADDR_NONE;
|
||||
}
|
||||
|
||||
if (BST_CHECKED == IsDlgButtonChecked(Dlg, IDC_FIXEDDNS)) {
|
||||
if (4 != SendMessageW(GetDlgItem(Dlg, IDC_DNS1), IPM_GETADDRESS,
|
||||
0, (LPARAM) &IpAddress)) {
|
||||
DlgData->Dns1 = INADDR_NONE;
|
||||
} else {
|
||||
DlgData->Dns1 = htonl(IpAddress);
|
||||
}
|
||||
if (4 != SendMessageW(GetDlgItem(Dlg, IDC_DNS2), IPM_GETADDRESS,
|
||||
0, (LPARAM) &IpAddress)) {
|
||||
DlgData->Dns2 = INADDR_NONE;
|
||||
} else {
|
||||
DlgData->Dns2 = htonl(IpAddress);
|
||||
}
|
||||
} else {
|
||||
DlgData->Dns1 = INADDR_NONE;
|
||||
DlgData->Dns2 = INADDR_NONE;
|
||||
}
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
static BOOL
|
||||
InternTCPIPSettings(HWND Dlg, PTCPIP_PROPERTIES_DATA DlgData) {
|
||||
BOOL Changed;
|
||||
BOOL IpChanged;
|
||||
int DhcpAction;
|
||||
LPWSTR AdapterName;
|
||||
lResult = SendMessage(GetDlgItem(hwndDlg, IDC_IPADDR), IPM_GETADDRESS, 0,
|
||||
(ULONG_PTR)dwIPAddr);
|
||||
if( lResult != 4 ) return FALSE;
|
||||
|
||||
if (! ValidateAndStore(Dlg, DlgData)) {
|
||||
/* Should never happen, we should have validated at PSN_KILLACTIVE */
|
||||
ASSERT(FALSE);
|
||||
return FALSE;
|
||||
}
|
||||
*dwIPAddr = htonl(*dwIPAddr);
|
||||
inIPAddr.s_addr = *dwIPAddr;
|
||||
*AddressString = inet_ntoa(inIPAddr);
|
||||
if( !*AddressString ) return FALSE;
|
||||
|
||||
Changed = FALSE;
|
||||
if (DlgData->DhcpEnabled) {
|
||||
Changed = ! DlgData->OldDhcpEnabled;
|
||||
IpChanged = FALSE;
|
||||
DhcpAction = 1;
|
||||
} else {
|
||||
Changed = DlgData->OldDhcpEnabled ||
|
||||
DlgData->IpAddress != DlgData->OldIpAddress ||
|
||||
DlgData->SubnetMask != DlgData->OldSubnetMask;
|
||||
IpChanged = DlgData->OldDhcpEnabled ||
|
||||
DlgData->IpAddress != DlgData->OldIpAddress;
|
||||
DhcpAction = 2;
|
||||
}
|
||||
|
||||
if (Changed) {
|
||||
AdapterName = HeapAlloc(GetProcessHeap(), 0,
|
||||
(strlen(DlgData->AdapterName) + 1) *
|
||||
sizeof(WCHAR));
|
||||
if (NULL == AdapterName) {
|
||||
ShowError(Dlg, IDS_OUT_OF_MEMORY);
|
||||
return FALSE;
|
||||
}
|
||||
MultiByteToWideChar(CP_THREAD_ACP, 0, DlgData->AdapterName, -1,
|
||||
AdapterName, strlen(DlgData->AdapterName) + 1);
|
||||
if (0 == DhcpNotifyConfigChange(NULL, AdapterName, IpChanged,
|
||||
DlgData->AdapterIndex,
|
||||
DlgData->IpAddress,
|
||||
DlgData->SubnetMask, DhcpAction)) {
|
||||
HeapFree(GetProcessHeap(), 0, AdapterName);
|
||||
ShowError(Dlg, IDS_CANNOT_SAVE_CHANGES);
|
||||
return FALSE;
|
||||
}
|
||||
HeapFree(GetProcessHeap(), 0, AdapterName);
|
||||
}
|
||||
|
||||
/* FIXME Save default gateway and DNS entries */
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
static INT_PTR CALLBACK
|
||||
TCPIPPropertyPageProc(HWND Dlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
|
||||
|
||||
|
||||
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, Disposition;
|
||||
const char *AddressString;
|
||||
BOOL RetVal = FALSE;
|
||||
BOOL DhcpEnabled = FALSE;
|
||||
MIB_IPFORWARDROW RowToAdd = { 0 };
|
||||
|
||||
DbgPrint("TCPIP_PROPERTIES: InternTCPIPSettings\n");
|
||||
|
||||
if(pPage)
|
||||
pInfo = (IP_ADAPTER_INFO *)pPage->lParam;
|
||||
|
||||
DbgPrint("TCPIP_PROPERTIES: pPage: 0x%x pInfo: 0x%x\n", pPage, pInfo);
|
||||
|
||||
if( !pPage || !pInfo ) goto cleanup;
|
||||
|
||||
DbgPrint("TCPIP_PROPERTIES: AdapterName: %s\n", pInfo->AdapterName);
|
||||
|
||||
_stprintf(pszRegKey,_T("SYSTEM\\CurrentControlSet\\Services\\TCPIP\\Parameters\\Interfaces\\%S"),pInfo->AdapterName);
|
||||
if(RegCreateKeyEx
|
||||
(HKEY_LOCAL_MACHINE,pszRegKey,0,NULL,
|
||||
REG_OPTION_NON_VOLATILE,KEY_ALL_ACCESS,NULL,&hKey,&Disposition)!=ERROR_SUCCESS) {
|
||||
DbgPrint("TCPIP_PROPERTIES: Could not open HKLM\\%S\n", pszRegKey);
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
if( !GetAddressFromField
|
||||
( hwndDlg, IDC_IPADDR, &IpAddress, &AddressString ) ||
|
||||
RegSetValueEx
|
||||
( hKey, _T("IPAddress"), 0, REG_SZ, AddressString,
|
||||
strlen(AddressString) ) != ERROR_SUCCESS )
|
||||
goto cleanup;
|
||||
|
||||
DbgPrint("TCPIP_PROPERTIES: IpAddress: %x\n", IpAddress);
|
||||
|
||||
if( !GetAddressFromField
|
||||
( hwndDlg, IDC_SUBNETMASK, &NetMask, &AddressString ) ||
|
||||
RegSetValueEx
|
||||
( hKey, _T("SubnetMask"), 0, REG_SZ, AddressString,
|
||||
strlen(AddressString) ) != ERROR_SUCCESS )
|
||||
goto cleanup;
|
||||
|
||||
DbgPrint("TCPIP_PROPERTIES: NetMask: %x\n", NetMask);
|
||||
|
||||
if( !GetAddressFromField
|
||||
( hwndDlg, IDC_DEFGATEWAY, &Gateway, &AddressString ) ||
|
||||
RegSetValueEx
|
||||
( hKey, _T("DefaultGateway"), 0, REG_SZ, AddressString,
|
||||
strlen(AddressString) ) != ERROR_SUCCESS )
|
||||
goto cleanup;
|
||||
|
||||
if( DhcpEnabled ) {
|
||||
DbgPrint("TCPIP_PROPERTIES: Lease address\n");
|
||||
DhcpLeaseIpAddress( pInfo->Index );
|
||||
} else {
|
||||
/* If not on DHCP then add a default gateway, assuming one was specified */
|
||||
DbgPrint("TCPIP_PROPERTIES: Adding gateway entry\n");
|
||||
DhcpReleaseIpAddressLease( pInfo->Index );
|
||||
DhcpStaticRefreshParams( pInfo->Index, IpAddress, NetMask );
|
||||
|
||||
RowToAdd.dwForwardMask = 0;
|
||||
RowToAdd.dwForwardMetric1 = 1;
|
||||
RowToAdd.dwForwardNextHop = Gateway;
|
||||
|
||||
CreateIpForwardEntry( &RowToAdd );
|
||||
}
|
||||
|
||||
DbgPrint("TCPIP_PROPERTIES: Done changing settings\n");
|
||||
|
||||
cleanup:
|
||||
if( hKey ) RegCloseKey( hKey );
|
||||
|
||||
return RetVal;
|
||||
}
|
||||
|
||||
INT_PTR CALLBACK
|
||||
TCPIPPropertyPageProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
|
||||
{
|
||||
LPPROPSHEETPAGEW Page;
|
||||
PTCPIP_PROPERTIES_DATA DlgData;
|
||||
LPNMHDR Nmhdr;
|
||||
PROPSHEETPAGE *pPage = (PROPSHEETPAGE *)GetWindowLongPtr(hwndDlg,GWL_USERDATA);
|
||||
IP_ADAPTER_INFO *pInfo = NULL;
|
||||
int StaticDNS = 0;
|
||||
char *NextDNSServer;
|
||||
|
||||
DlgData = (PTCPIP_PROPERTIES_DATA) GetWindowLongPtrW(Dlg, GWL_USERDATA);
|
||||
switch(uMsg) {
|
||||
if(pPage)
|
||||
pInfo = (IP_ADAPTER_INFO *)pPage->lParam;
|
||||
|
||||
switch(uMsg)
|
||||
{
|
||||
case WM_INITDIALOG:
|
||||
Page = (LPPROPSHEETPAGEW) lParam;
|
||||
DlgData = (PTCPIP_PROPERTIES_DATA) Page->lParam;
|
||||
SetWindowLongPtrW(Dlg, GWL_USERDATA, Page->lParam);
|
||||
{
|
||||
pPage = (PROPSHEETPAGE *)lParam;
|
||||
pInfo = (IP_ADAPTER_INFO *)pPage->lParam;
|
||||
EnableWindow(GetDlgItem(hwndDlg,IDC_ADVANCED),FALSE);
|
||||
SetWindowLongPtr(hwndDlg,GWL_USERDATA, (LPARAM)pPage);
|
||||
|
||||
EnableWindow(GetDlgItem(Dlg, IDC_ADVANCED), FALSE);
|
||||
EnableDHCP( hwndDlg, pInfo->DhcpEnabled );
|
||||
|
||||
EnableDHCP(Dlg, DlgData->OldDhcpEnabled);
|
||||
|
||||
if (! DlgData->OldDhcpEnabled)
|
||||
{
|
||||
if (INADDR_NONE != DlgData->OldIpAddress) {
|
||||
SendDlgItemMessage(Dlg, IDC_IPADDR, IPM_SETADDRESS, 0,
|
||||
ntohl(DlgData->OldIpAddress));
|
||||
}
|
||||
if (INADDR_NONE != DlgData->OldSubnetMask) {
|
||||
SendDlgItemMessage(Dlg, IDC_SUBNETMASK, IPM_SETADDRESS, 0,
|
||||
ntohl(DlgData->OldSubnetMask));
|
||||
}
|
||||
if (INADDR_NONE != DlgData->OldGateway) {
|
||||
SendDlgItemMessage(Dlg, IDC_DEFGATEWAY, IPM_SETADDRESS, 0,
|
||||
ntohl(DlgData->OldGateway));
|
||||
DWORD dwIPAddr;
|
||||
IP_ADDR_STRING *pString;
|
||||
pString = &pInfo->IpAddressList;
|
||||
while(pString->Next)
|
||||
pString = pString->Next;
|
||||
dwIPAddr = ntohl(inet_addr(pString->IpAddress.String));
|
||||
SendDlgItemMessage(hwndDlg,IDC_IPADDR,IPM_SETADDRESS,0,dwIPAddr);
|
||||
dwIPAddr = ntohl(inet_addr(pString->IpMask.String));
|
||||
SendDlgItemMessage(hwndDlg,IDC_SUBNETMASK,IPM_SETADDRESS,0,dwIPAddr);
|
||||
|
||||
pString = &pInfo->GatewayList;
|
||||
while(pString->Next)
|
||||
pString = pString->Next;
|
||||
dwIPAddr = ntohl(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 = ntohl(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 );
|
||||
}
|
||||
}
|
||||
|
||||
if (INADDR_NONE != DlgData->OldDns1) {
|
||||
SendDlgItemMessage(Dlg, IDC_DNS1, IPM_SETADDRESS, 0,
|
||||
ntohl(DlgData->OldDns1));
|
||||
if (INADDR_NONE != DlgData->OldDns2) {
|
||||
SendDlgItemMessage(Dlg, IDC_DNS2, IPM_SETADDRESS, 0,
|
||||
ntohl(DlgData->OldDns2));
|
||||
}
|
||||
}
|
||||
ManualDNS(Dlg, INADDR_NONE != DlgData->OldDns1);
|
||||
break;
|
||||
|
||||
}
|
||||
break;
|
||||
case WM_DESTROY:
|
||||
case WM_COMMAND:
|
||||
switch(LOWORD(wParam)) {
|
||||
switch(LOWORD(wParam))
|
||||
{
|
||||
case IDC_FIXEDDNS:
|
||||
ManualDNS(Dlg, TRUE);
|
||||
return TRUE;
|
||||
ManualDNS( hwndDlg, TRUE );
|
||||
break;
|
||||
|
||||
case IDC_AUTODNS:
|
||||
ManualDNS(Dlg, FALSE);
|
||||
return TRUE;
|
||||
ManualDNS( hwndDlg, FALSE );
|
||||
break;
|
||||
|
||||
case IDC_USEDHCP:
|
||||
EnableDHCP(Dlg, TRUE);
|
||||
return TRUE;
|
||||
EnableDHCP( hwndDlg, TRUE );
|
||||
break;
|
||||
|
||||
case IDC_NODHCP:
|
||||
EnableDHCP(Dlg, FALSE);
|
||||
return TRUE;
|
||||
}
|
||||
break;
|
||||
EnableDHCP( hwndDlg, FALSE );
|
||||
break;
|
||||
|
||||
case WM_NOTIFY:
|
||||
Nmhdr = (LPNMHDR) lParam;
|
||||
|
||||
switch(Nmhdr->code) {
|
||||
case PSN_KILLACTIVE:
|
||||
/* Do validation here, must set FALSE to continue */
|
||||
SetWindowLongPtrW(Dlg, DWL_MSGRESULT,
|
||||
(LONG_PTR) ! ValidateAndStore(Dlg, DlgData));
|
||||
return TRUE;
|
||||
|
||||
case PSN_APPLY:
|
||||
case 0:
|
||||
/* Set the IP Address and DNS Information so we won't
|
||||
* be doing all this for nothing */
|
||||
SetWindowLongPtrW(Dlg, DWL_MSGRESULT,
|
||||
InternTCPIPSettings(Dlg, DlgData) ?
|
||||
PSNRET_NOERROR : PSNRET_INVALID);
|
||||
return TRUE;
|
||||
InternTCPIPSettings( hwndDlg );
|
||||
LocalFree((void *)pPage->lParam);
|
||||
LocalFree(pPage);
|
||||
break;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
static BOOL
|
||||
LoadDataFromInfo(PTCPIP_PROPERTIES_DATA DlgData, IP_ADAPTER_INFO *Info)
|
||||
void DisplayTCPIPProperties(HWND hParent,IP_ADAPTER_INFO *pInfo)
|
||||
{
|
||||
IP_ADDR_STRING *pString;
|
||||
WCHAR RegKey[MAX_PATH];
|
||||
HKEY hKey;
|
||||
char Dns[MAX_PATH];
|
||||
DWORD Size;
|
||||
DWORD Type;
|
||||
char *NextDnsServer;
|
||||
PROPSHEETPAGE *psp = LocalAlloc( LMEM_FIXED, sizeof(PROPSHEETPAGE) );
|
||||
PROPSHEETHEADER psh;
|
||||
INITCOMMONCONTROLSEX cce;
|
||||
|
||||
DlgData->AdapterName = Info->AdapterName;
|
||||
DlgData->AdapterIndex = Info->Index;
|
||||
DbgPrint("TCPIP_PROPERTIES: psp = %x\n", psp);
|
||||
|
||||
DlgData->OldDhcpEnabled = Info->DhcpEnabled;
|
||||
cce.dwSize = sizeof(INITCOMMONCONTROLSEX);
|
||||
cce.dwICC = ICC_INTERNET_CLASSES;
|
||||
InitCommonControlsEx(&cce);
|
||||
|
||||
pString = &Info->IpAddressList;
|
||||
while (NULL != pString->Next) {
|
||||
pString = pString->Next;
|
||||
}
|
||||
DlgData->OldIpAddress = inet_addr(pString->IpAddress.String);
|
||||
DlgData->OldSubnetMask = inet_addr(pString->IpMask.String);
|
||||
pString = &Info->GatewayList;
|
||||
while (NULL != pString->Next) {
|
||||
pString = pString->Next;
|
||||
}
|
||||
DlgData->OldGateway = inet_addr(pString->IpAddress.String);
|
||||
ZeroMemory(&psh, sizeof(PROPSHEETHEADER));
|
||||
psh.dwSize = sizeof(PROPSHEETHEADER);
|
||||
psh.dwFlags = PSH_PROPSHEETPAGE | PSH_NOAPPLYNOW;
|
||||
psh.hwndParent = hParent;
|
||||
psh.hInstance = hApplet;
|
||||
psh.hIcon = LoadIcon(hApplet, MAKEINTRESOURCE(IDI_CPLSYSTEM));
|
||||
psh.pszCaption = NULL;//Caption;
|
||||
psh.nPages = 1;
|
||||
psh.nStartPage = 0;
|
||||
psh.ppsp = psp;
|
||||
psh.pfnCallback = NULL;
|
||||
|
||||
DlgData->OldDns1 = INADDR_NONE;
|
||||
DlgData->OldDns2 = INADDR_NONE;
|
||||
swprintf(RegKey,
|
||||
L"SYSTEM\\CurrentControlSet\\Services\\TCPIP\\Parameters\\Interfaces\\%S",
|
||||
Info->AdapterName);
|
||||
if (ERROR_SUCCESS == RegOpenKeyW(HKEY_LOCAL_MACHINE, RegKey, &hKey)) {
|
||||
Size = sizeof(Dns);
|
||||
RegQueryValueExA(hKey, "NameServer", NULL, &Type, (BYTE *)Dns,
|
||||
&Size);
|
||||
RegCloseKey(hKey);
|
||||
DbgPrint("TCPIP_PROPERTIES: About to InitPropSheetPage (pInfo: %x)\n", pInfo);
|
||||
|
||||
if ('\0' != Dns[0]) {
|
||||
DlgData->OldDns1 = inet_addr(Dns);
|
||||
NextDnsServer = strchr(Dns, ',');
|
||||
if (NULL != NextDnsServer && '\0' != *NextDnsServer) {
|
||||
DlgData->OldDns2 = inet_addr(NextDnsServer);
|
||||
}
|
||||
}
|
||||
}
|
||||
InitPropSheetPage(psp, IDD_TCPIPPROPERTIES, TCPIPPropertyPageProc, (LPARAM)pInfo);
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
void
|
||||
DisplayTCPIPProperties(HWND hParent, IP_ADAPTER_INFO *pInfo)
|
||||
{
|
||||
PROPSHEETPAGEW psp[1];
|
||||
PROPSHEETHEADERW psh;
|
||||
INITCOMMONCONTROLSEX cce;
|
||||
TCPIP_PROPERTIES_DATA DlgData;
|
||||
|
||||
if (! LoadDataFromInfo(&DlgData, pInfo))
|
||||
{
|
||||
ShowError(hParent, IDS_CANNOT_LOAD_CONFIG);
|
||||
return;
|
||||
}
|
||||
|
||||
cce.dwSize = sizeof(INITCOMMONCONTROLSEX);
|
||||
cce.dwICC = ICC_INTERNET_CLASSES;
|
||||
InitCommonControlsEx(&cce);
|
||||
|
||||
ZeroMemory(&psh, sizeof(PROPSHEETHEADER));
|
||||
psh.dwSize = sizeof(PROPSHEETHEADER);
|
||||
psh.dwFlags = PSH_PROPSHEETPAGE | PSH_NOAPPLYNOW;
|
||||
psh.hwndParent = hParent;
|
||||
psh.hInstance = hApplet;
|
||||
psh.hIcon = LoadIcon(hApplet, MAKEINTRESOURCE(IDI_CPLSYSTEM));
|
||||
psh.pszCaption = NULL;//Caption;
|
||||
psh.nPages = sizeof(psp) / sizeof(PROPSHEETPAGE);
|
||||
psh.nStartPage = 0;
|
||||
psh.ppsp = psp;
|
||||
psh.pfnCallback = NULL;
|
||||
|
||||
InitPropSheetPage(&psp[0], IDD_TCPIPPROPERTIES, TCPIPPropertyPageProc);
|
||||
psp[0].lParam = (LPARAM) &DlgData;
|
||||
|
||||
if (PropertySheetW(&psh) == -1)
|
||||
{
|
||||
ShowError(hParent, IDS_CANNOT_CREATE_PROPSHEET);
|
||||
}
|
||||
|
||||
return;
|
||||
DbgPrint("TCPIP_PROPERTIES: About to realize property sheet\n", psp);
|
||||
|
||||
if (PropertySheet(&psh) == -1)
|
||||
{
|
||||
MessageBox(hParent,_T("Unable to create property sheet"),_T("Error"),MB_ICONSTOP);
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
|
|
@ -500,6 +500,13 @@ typedef struct _NDIS40_MINIPORT_CHARACTERISTICS {
|
|||
#define MAX(value1, value2) \
|
||||
((value1 > value2)? value1 : value2)
|
||||
|
||||
#define ExInterlockedRemoveEntryList(_List,_Lock) \
|
||||
{ KIRQL OldIrql; \
|
||||
KeAcquireSpinLock(_Lock, &OldIrql); \
|
||||
RemoveEntryList(_List); \
|
||||
KeReleaseSpinLock(_Lock, OldIrql); \
|
||||
}
|
||||
|
||||
#endif /* __NDISSYS_H */
|
||||
|
||||
/* EOF */
|
||||
|
|
|
@ -1331,6 +1331,7 @@ NdisIPnPStartDevice(
|
|||
ExAllocatePool(PagedPool, ResourceListSize);
|
||||
if (Adapter->NdisMiniportBlock.AllocatedResources == NULL)
|
||||
{
|
||||
ExInterlockedRemoveEntryList( &Adapter->ListEntry, &AdapterListLock );
|
||||
return STATUS_INSUFFICIENT_RESOURCES;
|
||||
}
|
||||
|
||||
|
@ -1340,6 +1341,7 @@ NdisIPnPStartDevice(
|
|||
{
|
||||
ExFreePool(Adapter->NdisMiniportBlock.AllocatedResources);
|
||||
Adapter->NdisMiniportBlock.AllocatedResources = NULL;
|
||||
ExInterlockedRemoveEntryList( &Adapter->ListEntry, &AdapterListLock );
|
||||
return STATUS_INSUFFICIENT_RESOURCES;
|
||||
}
|
||||
|
||||
|
@ -1420,6 +1422,7 @@ NdisIPnPStartDevice(
|
|||
SelectedMediumIndex >= MEDIA_ARRAY_SIZE)
|
||||
{
|
||||
NDIS_DbgPrint(MIN_TRACE, ("MiniportInitialize() failed for an adapter.\n"));
|
||||
ExInterlockedRemoveEntryList( &Adapter->ListEntry, &AdapterListLock );
|
||||
return (NTSTATUS)NdisStatus;
|
||||
}
|
||||
|
||||
|
@ -1461,6 +1464,7 @@ NdisIPnPStartDevice(
|
|||
NDIS_DbgPrint(MIN_TRACE, ("error: unsupported media\n"));
|
||||
ASSERT(FALSE);
|
||||
/* FIXME - KeReleaseSpinLock(&Adapter->NdisMiniportBlock.Lock, OldIrql); */
|
||||
ExInterlockedRemoveEntryList( &Adapter->ListEntry, &AdapterListLock );
|
||||
return STATUS_UNSUCCESSFUL;
|
||||
}
|
||||
|
||||
|
@ -1472,6 +1476,7 @@ NdisIPnPStartDevice(
|
|||
ExFreePool(Adapter->LookaheadBuffer);
|
||||
Adapter->LookaheadBuffer = NULL;
|
||||
}
|
||||
ExInterlockedRemoveEntryList( &Adapter->ListEntry, &AdapterListLock );
|
||||
return (NTSTATUS)NdisStatus;
|
||||
}
|
||||
|
||||
|
|
|
@ -906,7 +906,7 @@ VOID GetName( PUNICODE_STRING RegistryKey,
|
|||
AppendUnicodeString( OutName, &PartialRegistryKey, FALSE );
|
||||
}
|
||||
|
||||
VOID BindAdapter(
|
||||
BOOLEAN BindAdapter(
|
||||
PLAN_ADAPTER Adapter,
|
||||
PNDIS_STRING RegistryPath)
|
||||
/*
|
||||
|
@ -937,7 +937,7 @@ VOID BindAdapter(
|
|||
sizeof(ULONG));
|
||||
if (NdisStatus != NDIS_STATUS_SUCCESS) {
|
||||
TI_DbgPrint(DEBUG_DATALINK, ("Could not set lookahead buffer size (0x%X).\n", NdisStatus));
|
||||
return;
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
/* Bind the adapter to IP layer */
|
||||
|
@ -953,7 +953,7 @@ VOID BindAdapter(
|
|||
|
||||
if (!IF) {
|
||||
TI_DbgPrint(MIN_TRACE, ("Insufficient resources.\n"));
|
||||
return;
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -973,6 +973,9 @@ VOID BindAdapter(
|
|||
Status = FindDeviceDescForAdapter( &IF->Name, &IF->Description );
|
||||
TI_DbgPrint(DEBUG_DATALINK,("Adapter Description: %wZ\n",
|
||||
&IF->Description));
|
||||
} else {
|
||||
IPDestroyInterface( IF );
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
DefaultMask.Type = IP_ADDRESS_V4;
|
||||
|
@ -1010,11 +1013,12 @@ VOID BindAdapter(
|
|||
if (NdisStatus != NDIS_STATUS_SUCCESS) {
|
||||
TI_DbgPrint(DEBUG_DATALINK, ("Could not set packet filter (0x%X).\n", NdisStatus));
|
||||
IPDestroyInterface(IF);
|
||||
return;
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
Adapter->Context = IF;
|
||||
Adapter->State = LAN_STATE_STARTED;
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
|
||||
|
@ -1097,6 +1101,7 @@ NDIS_STATUS LANRegisterAdapter(
|
|||
if (NdisStatus == NDIS_STATUS_PENDING)
|
||||
KeWaitForSingleObject(&IF->Event, UserRequest, KernelMode, FALSE, NULL);
|
||||
else if (NdisStatus != NDIS_STATUS_SUCCESS) {
|
||||
TI_DbgPrint(DEBUG_DATALINK,("denying adapter %wZ\n", AdapterName));
|
||||
exFreePool(IF);
|
||||
return NdisStatus;
|
||||
}
|
||||
|
@ -1133,6 +1138,7 @@ NDIS_STATUS LANRegisterAdapter(
|
|||
&IF->MTU,
|
||||
sizeof(UINT));
|
||||
if (NdisStatus != NDIS_STATUS_SUCCESS) {
|
||||
TI_DbgPrint(DEBUG_DATALINK,("denying adapter %wZ (NDISCall)\n", AdapterName));
|
||||
exFreePool(IF);
|
||||
return NdisStatus;
|
||||
}
|
||||
|
@ -1193,7 +1199,11 @@ NDIS_STATUS LANRegisterAdapter(
|
|||
&AdapterListLock);
|
||||
|
||||
/* Bind adapter to IP layer */
|
||||
BindAdapter(IF, RegistryPath);
|
||||
if( !BindAdapter(IF, RegistryPath) ) {
|
||||
TI_DbgPrint(DEBUG_DATALINK,("denying adapter %wZ (BindAdapter)\n", AdapterName));
|
||||
exFreePool(IF);
|
||||
return NDIS_STATUS_NOT_ACCEPTED;
|
||||
}
|
||||
|
||||
TI_DbgPrint(DEBUG_DATALINK, ("Leaving.\n"));
|
||||
|
||||
|
|
|
@ -1505,7 +1505,12 @@ NTSTATUS DispTdiSetIPAddress( PIRP Irp, PIO_STACK_LOCATION IrpSp ) {
|
|||
(PIP_SET_ADDRESS)Irp->AssociatedIrp.SystemBuffer;
|
||||
IF_LIST_ITER(IF);
|
||||
|
||||
TI_DbgPrint(MID_TRACE,("Setting IP Address for adapter %d\n",
|
||||
IpAddrChange->NteIndex));
|
||||
|
||||
ForEachInterface(IF) {
|
||||
TI_DbgPrint(MID_TRACE,("Looking at adapter %d\n", IF->Index));
|
||||
|
||||
if( IF->Unicast.Address.IPv4Address == IpAddrChange->Address ) {
|
||||
Status = STATUS_DUPLICATE_OBJECTID;
|
||||
break;
|
||||
|
|
|
@ -60,17 +60,23 @@ VOID RemoveTDIInterfaceEntity( PIP_INTERFACE Interface ) {
|
|||
KIRQL OldIrql;
|
||||
UINT i;
|
||||
|
||||
TI_DbgPrint(DEBUG_INFO,("Removing TDI entry 0x%x\n", Interface));
|
||||
|
||||
TcpipAcquireSpinLock( &EntityListLock, &OldIrql );
|
||||
|
||||
/* Remove entities that have this interface as context
|
||||
* In the future, this might include AT_ENTITY types, too
|
||||
*/
|
||||
for( i = 0; i < EntityCount; i++ ) {
|
||||
TI_DbgPrint(DEBUG_INFO,("--> examining TDI entry 0x%x\n", EntityList[i].context));
|
||||
if( EntityList[i].context == Interface ) {
|
||||
if( i != EntityCount-1 )
|
||||
if( i != EntityCount-1 ) {
|
||||
memcpy( &EntityList[i],
|
||||
&EntityList[--EntityCount],
|
||||
sizeof(EntityList[i]) );
|
||||
} else {
|
||||
EntityCount--;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -14,7 +14,7 @@
|
|||
#ifndef NDEBUG
|
||||
DWORD DebugTraceLevel = DEBUG_ULTRA & ~(DEBUG_LOCK | DEBUG_PBUFFER);
|
||||
#else
|
||||
DWORD DebugTraceLevel = 0;
|
||||
DWORD DebugTraceLevel = DEBUG_DATALINK;
|
||||
#endif /* NDEBUG */
|
||||
|
||||
PDEVICE_OBJECT TCPDeviceObject = NULL;
|
||||
|
|
Loading…
Reference in a new issue