Author: cgutman
Date: Tue Jul 14 21:43:57 2009
New Revision: 41955
URL:
http://svn.reactos.org/svn/reactos?rev=41955&view=rev
Log:
- 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
Modified:
trunk/reactos/base/applications/network/ipconfig/ipconfig.c
trunk/reactos/base/services/dhcp/api.c
trunk/reactos/base/services/dhcp/pipe.c
trunk/reactos/dll/win32/iphlpapi/iphlpapi.rbuild
trunk/reactos/dll/win32/iphlpapi/iphlpapi_main.c
trunk/reactos/include/reactos/libs/dhcp/rosdhcp_public.h
Modified: trunk/reactos/base/applications/network/ipconfig/ipconfig.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/base/applications/network/…
==============================================================================
--- trunk/reactos/base/applications/network/ipconfig/ipconfig.c [iso-8859-1] (original)
+++ trunk/reactos/base/applications/network/ipconfig/ipconfig.c [iso-8859-1] Tue Jul 14
21:43:57 2009
@@ -573,6 +573,7 @@
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 @@
/* 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
{
@@ -622,14 +634,6 @@
* i.e. ipconfig /renew Eth* will renew all cards starting with Eth...
* 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);
}
}
Modified: trunk/reactos/base/services/dhcp/api.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/base/services/dhcp/api.c?r…
==============================================================================
--- trunk/reactos/base/services/dhcp/api.c [iso-8859-1] (original)
+++ trunk/reactos/base/services/dhcp/api.c [iso-8859-1] Tue Jul 14 21:43:57 2009
@@ -61,10 +61,14 @@
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 @@
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 );
Modified: trunk/reactos/base/services/dhcp/pipe.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/base/services/dhcp/pipe.c?…
==============================================================================
--- trunk/reactos/base/services/dhcp/pipe.c [iso-8859-1] (original)
+++ trunk/reactos/base/services/dhcp/pipe.c [iso-8859-1] Tue Jul 14 21:43:57 2009
@@ -89,7 +89,7 @@
}
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,
Modified: trunk/reactos/dll/win32/iphlpapi/iphlpapi.rbuild
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/dll/win32/iphlpapi/iphlpap…
==============================================================================
--- trunk/reactos/dll/win32/iphlpapi/iphlpapi.rbuild [iso-8859-1] (original)
+++ trunk/reactos/dll/win32/iphlpapi/iphlpapi.rbuild [iso-8859-1] Tue Jul 14 21:43:57
2009
@@ -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>
Modified: trunk/reactos/dll/win32/iphlpapi/iphlpapi_main.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/dll/win32/iphlpapi/iphlpap…
==============================================================================
--- trunk/reactos/dll/win32/iphlpapi/iphlpapi_main.c [iso-8859-1] (original)
+++ trunk/reactos/dll/win32/iphlpapi/iphlpapi_main.c [iso-8859-1] Tue Jul 14 21:43:57
2009
@@ -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 @@
* 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 @@
* 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;
}
Modified: trunk/reactos/include/reactos/libs/dhcp/rosdhcp_public.h
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/include/reactos/libs/dhcp/…
==============================================================================
--- trunk/reactos/include/reactos/libs/dhcp/rosdhcp_public.h [iso-8859-1] (original)
+++ trunk/reactos/include/reactos/libs/dhcp/rosdhcp_public.h [iso-8859-1] Tue Jul 14
21:43:57 2009
@@ -48,6 +48,6 @@
} GetAdapterInfo;
} COMM_DHCP_REPLY;
-#define DHCP_PIPE_NAME "\\\\.\\pipe\\dhcpclient"
+#define DHCP_PIPE_NAME L"\\\\.\\pipe\\dhcpclient"
#endif/*ROSDHCP_PUBLIC_H*/