From c7364bef38b8fa093768b2fd715116d46f8d3a7f Mon Sep 17 00:00:00 2001 From: Cameron Gutman Date: Tue, 14 Jul 2009 19:43:57 +0000 Subject: [PATCH] - Renew the IP address of all adapters when using /renew - Leave the critical section in failure case - Check for NULL adapter (CID 499) - Implement IpRenewAddress and IpReleaseAddress - Fixes ipconfig /release and ipconfig /renew svn path=/trunk/; revision=41955 --- .../applications/network/ipconfig/ipconfig.c | 24 ++++--- reactos/base/services/dhcp/api.c | 17 +++-- reactos/base/services/dhcp/pipe.c | 2 +- reactos/dll/win32/iphlpapi/iphlpapi.rbuild | 1 + reactos/dll/win32/iphlpapi/iphlpapi_main.c | 67 +++++++++++++------ .../reactos/libs/dhcp/rosdhcp_public.h | 2 +- 6 files changed, 75 insertions(+), 38 deletions(-) diff --git a/reactos/base/applications/network/ipconfig/ipconfig.c b/reactos/base/applications/network/ipconfig/ipconfig.c index 3210c39a6c0..c7ecc38897a 100644 --- a/reactos/base/applications/network/ipconfig/ipconfig.c +++ b/reactos/base/applications/network/ipconfig/ipconfig.c @@ -573,6 +573,7 @@ VOID Release(LPTSTR Index) VOID Renew(LPTSTR Index) { IP_ADAPTER_INDEX_MAP AdapterInfo; + DWORD i; /* if interface is not given, query GetInterfaceInfo */ if (Index == NULL) @@ -603,8 +604,19 @@ VOID Renew(LPTSTR Index) /* Make a second call to GetInterfaceInfo to get the actual data we want */ if (GetInterfaceInfo(pInfo, &ulOutBufLen) == NO_ERROR ) { - CopyMemory(&AdapterInfo, &pInfo->Adapter[0], sizeof(IP_ADAPTER_INDEX_MAP)); - _tprintf(_T("name - %S\n"), pInfo->Adapter[0].Name); + for (i = 0; i < pInfo->NumAdapters; i++) + { + CopyMemory(&AdapterInfo, &pInfo->Adapter[i], sizeof(IP_ADAPTER_INDEX_MAP)); + _tprintf(_T("name - %S\n"), pInfo->Adapter[i].Name); + + + /* Call IpRenewAddress to renew the IP address on the specified adapter. */ + if (IpRenewAddress(&AdapterInfo) != NO_ERROR) + { + _tprintf(_T("\nAn error occured while renew interface %s : "), _T("*name*")); + DoFormatMessage(0); + } + } } else { @@ -623,14 +635,6 @@ VOID Renew(LPTSTR Index) * ipconfig /renew *con* will renew all cards with 'con' in their name */ } - - - /* Call IpRenewAddress to renew the IP address on the specified adapter. */ - if (IpRenewAddress(&AdapterInfo) != NO_ERROR) - { - _tprintf(_T("\nAn error occured while renew interface %s : "), _T("*name*")); - DoFormatMessage(0); - } } diff --git a/reactos/base/services/dhcp/api.c b/reactos/base/services/dhcp/api.c index b2d9c9e2ad5..c1ec11e11db 100644 --- a/reactos/base/services/dhcp/api.c +++ b/reactos/base/services/dhcp/api.c @@ -61,10 +61,14 @@ DWORD DSQueryHWInfo( PipeSendFunc Send, COMM_DHCP_REQ *Req ) { Adapter = AdapterFindIndex( Req->AdapterIndex ); - Reply.QueryHWInfo.AdapterIndex = Req->AdapterIndex; - Reply.QueryHWInfo.MediaType = Adapter->IfMib.dwType; - Reply.QueryHWInfo.Mtu = Adapter->IfMib.dwMtu; - Reply.QueryHWInfo.Speed = Adapter->IfMib.dwSpeed; + Reply.Reply = Adapter ? 1 : 0; + + if (Adapter) { + Reply.QueryHWInfo.AdapterIndex = Req->AdapterIndex; + Reply.QueryHWInfo.MediaType = Adapter->IfMib.dwType; + Reply.QueryHWInfo.Mtu = Adapter->IfMib.dwMtu; + Reply.QueryHWInfo.Speed = Adapter->IfMib.dwSpeed; + } ApiUnlock(); @@ -99,14 +103,13 @@ DWORD DSRenewIpAddressLease( PipeSendFunc Send, COMM_DHCP_REQ *Req ) { Adapter = AdapterFindIndex( Req->AdapterIndex ); - Reply.Reply = Adapter ? 1 : 0; - if( !Adapter || Adapter->DhclientState.state != S_BOUND ) { Reply.Reply = 0; + ApiUnlock(); return Send( &Reply ); } - Adapter->DhclientState.state = S_BOUND; + Reply.Reply = 1; send_discover( &Adapter->DhclientInfo ); state_bound( &Adapter->DhclientInfo ); diff --git a/reactos/base/services/dhcp/pipe.c b/reactos/base/services/dhcp/pipe.c index 026343b9086..9ea0402c413 100644 --- a/reactos/base/services/dhcp/pipe.c +++ b/reactos/base/services/dhcp/pipe.c @@ -89,7 +89,7 @@ DWORD WINAPI PipeThreadProc( LPVOID Parameter ) { } HANDLE PipeInit() { - CommPipe = CreateNamedPipe + CommPipe = CreateNamedPipeW ( DHCP_PIPE_NAME, PIPE_ACCESS_DUPLEX | FILE_FLAG_FIRST_PIPE_INSTANCE, PIPE_TYPE_MESSAGE | PIPE_READMODE_MESSAGE | PIPE_WAIT, diff --git a/reactos/dll/win32/iphlpapi/iphlpapi.rbuild b/reactos/dll/win32/iphlpapi/iphlpapi.rbuild index 22385f0432c..6582639fe05 100644 --- a/reactos/dll/win32/iphlpapi/iphlpapi.rbuild +++ b/reactos/dll/win32/iphlpapi/iphlpapi.rbuild @@ -2,6 +2,7 @@ . include/reactos/wine + include wine ntdll kernel32 diff --git a/reactos/dll/win32/iphlpapi/iphlpapi_main.c b/reactos/dll/win32/iphlpapi/iphlpapi_main.c index a908f492d0a..5f8abd17211 100644 --- a/reactos/dll/win32/iphlpapi/iphlpapi_main.c +++ b/reactos/dll/win32/iphlpapi/iphlpapi_main.c @@ -48,6 +48,8 @@ #include "resinfo.h" #include "route.h" #include "wine/debug.h" +#include "dhcpcsdk.h" +#include "dhcp/rosdhcp_public.h" WINE_DEFAULT_DEBUG_CHANNEL(iphlpapi); @@ -1880,19 +1882,33 @@ DWORD WINAPI GetUniDirectionalAdapterInfo(PIP_UNIDIRECTIONAL_ADAPTER_ADDRESS pIP * Success: NO_ERROR * Failure: error code from winerror.h * - * NOTES - * Since GetAdaptersInfo never returns adapters that have DHCP enabled, - * this function does nothing. - * - * FIXME - * Stub, returns ERROR_NOT_SUPPORTED. */ DWORD WINAPI IpReleaseAddress(PIP_ADAPTER_INDEX_MAP AdapterInfo) { + COMM_DHCP_REPLY Reply; + COMM_DHCP_REQ Request; + DWORD BytesRead; + + Request.AdapterIndex = AdapterInfo->Index; + Request.Type = DhcpReqReleaseIpAddress; + TRACE("AdapterInfo %p\n", AdapterInfo); - /* not a stub, never going to support this (and I never mark an adapter as - DHCP enabled, see GetAdaptersInfo, so this should never get called) */ - return ERROR_NOT_SUPPORTED; + + if (CallNamedPipe(DHCP_PIPE_NAME, + &Request, + sizeof(Request), + &Reply, + sizeof(Reply), + &BytesRead, + NMPWAIT_USE_DEFAULT_WAIT)) + { + if (Reply.Reply) + return NO_ERROR; + + return ERROR_INVALID_PARAMETER; + } + + return ERROR_PROC_NOT_FOUND; } @@ -1907,20 +1923,33 @@ DWORD WINAPI IpReleaseAddress(PIP_ADAPTER_INDEX_MAP AdapterInfo) * RETURNS * Success: NO_ERROR * Failure: error code from winerror.h - * - * NOTES - * Since GetAdaptersInfo never returns adapters that have DHCP enabled, - * this function does nothing. - * - * FIXME - * Stub, returns ERROR_NOT_SUPPORTED. */ DWORD WINAPI IpRenewAddress(PIP_ADAPTER_INDEX_MAP AdapterInfo) { + COMM_DHCP_REPLY Reply; + COMM_DHCP_REQ Request; + DWORD BytesRead; + + Request.AdapterIndex = AdapterInfo->Index; + Request.Type = DhcpReqRenewIpAddress; + TRACE("AdapterInfo %p\n", AdapterInfo); - /* not a stub, never going to support this (and I never mark an adapter as - DHCP enabled, see GetAdaptersInfo, so this should never get called) */ - return ERROR_NOT_SUPPORTED; + + if (CallNamedPipe(DHCP_PIPE_NAME, + &Request, + sizeof(Request), + &Reply, + sizeof(Reply), + &BytesRead, + NMPWAIT_USE_DEFAULT_WAIT)) + { + if (Reply.Reply) + return NO_ERROR; + + return ERROR_INVALID_PARAMETER; + } + + return ERROR_PROC_NOT_FOUND; } diff --git a/reactos/include/reactos/libs/dhcp/rosdhcp_public.h b/reactos/include/reactos/libs/dhcp/rosdhcp_public.h index 7e0c34a652b..5779184e32f 100644 --- a/reactos/include/reactos/libs/dhcp/rosdhcp_public.h +++ b/reactos/include/reactos/libs/dhcp/rosdhcp_public.h @@ -48,6 +48,6 @@ typedef union _COMM_DHCP_REPLY { } GetAdapterInfo; } COMM_DHCP_REPLY; -#define DHCP_PIPE_NAME "\\\\.\\pipe\\dhcpclient" +#define DHCP_PIPE_NAME L"\\\\.\\pipe\\dhcpclient" #endif/*ROSDHCP_PUBLIC_H*/