- 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
This commit is contained in:
Cameron Gutman 2009-07-14 19:43:57 +00:00
parent 45a41f9932
commit c7364bef38
6 changed files with 75 additions and 38 deletions

View file

@ -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);
}
}

View file

@ -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 );

View file

@ -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,

View file

@ -2,6 +2,7 @@
<importlibrary definition="iphlpapi.spec" />
<include base="iphlpapi">.</include>
<include base="ReactOS">include/reactos/wine</include>
<include base="dhcp">include</include>
<library>wine</library>
<library>ntdll</library>
<library>kernel32</library>

View file

@ -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;
}

View file

@ -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*/