[IPHLPAPI]

Make GetAdaptersAddresses work, with parameters check.
More work is needed :
-it returns the loopback, which shouldn't appear with default flags.
-the required size is fixed.

svn path=/trunk/; revision=66981
This commit is contained in:
Sylvain Petreolle 2015-03-30 18:10:36 +00:00
parent 0e91e9fc18
commit e5e4c2bbf0

View file

@ -9,7 +9,7 @@
#include "iphlpapi_private.h"
WINE_DEFAULT_DEBUG_CHANNEL(iphlpapi);
#if 1
/* Helper for GetAdaptersAddresses:
* Retrieves the list of network adapters from tcpip.sys */
static
@ -283,6 +283,8 @@ GetAdaptersAddresses(
ULONG i;
ULONG TotalSize = 0, RemainingSize;
BYTE* Ptr = (BYTE*)pAdapterAddresses;
DWORD MIN_SIZE = 15 * 1024;
PIP_ADAPTER_ADDRESSES PreviousAA = NULL;
FIXME("GetAdaptersAddresses - Semi Stub: Family %u, Flags 0x%08x, Reserved %p, pAdapterAddress %p, pOutBufLen %p.\n",
Family, Flags, Reserved, pAdapterAddresses, pOutBufLen);
@ -290,6 +292,14 @@ GetAdaptersAddresses(
if (!pOutBufLen)
return ERROR_INVALID_PARAMETER;
// FIXME: the exact needed size should be computed first, BEFORE doing any write to the output buffer.
// As suggested by MSDN, require a 15 KB buffer, which allows to React properly to length checks.
if(!Ptr || *pOutBufLen < MIN_SIZE)
{
*pOutBufLen = MIN_SIZE;
return ERROR_BUFFER_OVERFLOW;
}
switch(Family)
{
case AF_INET:
@ -334,7 +344,7 @@ GetAdaptersAddresses(
/* Let's see if we got any adapter. */
for (i = 0; i < InterfacesCount; i++)
{
PIP_ADAPTER_ADDRESSES CurrentAA = (PIP_ADAPTER_ADDRESSES)Ptr, PreviousAA = NULL;
PIP_ADAPTER_ADDRESSES CurrentAA = (PIP_ADAPTER_ADDRESSES)Ptr;
ULONG CurrentAASize = 0;
if (InterfacesList[i].tei_entity == IF_ENTITY)
@ -346,6 +356,10 @@ GetAdaptersAddresses(
/* Remember we got one */
AdaptersCount++;
/* Set the pointer to this instance in the previous one*/
if(PreviousAA)
PreviousAA->Next = CurrentAA;
/* Of course we need some space for the base structure. */
CurrentAASize = sizeof(IP_ADAPTER_ADDRESSES);
@ -409,7 +423,6 @@ GetAdaptersAddresses(
CurrentAA->Mtu = Entry->if_mtu;
CurrentAA->IfType = Entry->if_type;
CurrentAA->OperStatus = Entry->if_operstatus;
CurrentAA->Next = PreviousAA;
/* Next items */
Ptr = (BYTE*)(CurrentAA + 1);
@ -628,6 +641,7 @@ Success:
HeapFree(GetProcessHeap(), 0, InterfacesList);
NtClose(TcpFile);
*pOutBufLen = TotalSize;
TRACE("TotalSize: %x\n", *pOutBufLen);
return ERROR_SUCCESS;
Error:
@ -637,3 +651,4 @@ Error:
NtClose(TcpFile);
return RtlNtStatusToDosError(Status);
}
#endif