Re: [1/2] iphlpapi: Add GetUnicastIpAddressEntry implementation (try 3)
On Sun, Feb 5, 2017 at 7:25 PM, André Hentschel <nerv(a)dawncrow.de> wrote:
Signed-off-by: André Hentschel <nerv(a)dawncrow.de> ---
For https://bugs.winehq.org/show_bug.cgi?id=41753 try 2: Many thanks to Bruno and Hans for the feedback! try 3: Proper patch numbering
Thanks for the new patch ;-) I'm testing it now and I just have some doubts.
dlls/iphlpapi/iphlpapi.spec | 2 +- dlls/iphlpapi/iphlpapi_main.c | 69 +++++++++++++++++++++++++++++++++++++++++++ include/netioapi.h | 17 +++++++++++ include/ws2def.h | 13 ++++++++ include/ws2ipdef.h | 7 +++++ 5 files changed, 107 insertions(+), 1 deletion(-)
diff --git a/dlls/iphlpapi/iphlpapi.spec b/dlls/iphlpapi/iphlpapi.spec index 500267c..1a1f8f7 100644 --- a/dlls/iphlpapi/iphlpapi.spec +++ b/dlls/iphlpapi/iphlpapi.spec @@ -147,7 +147,7 @@ @ stub GetUdpStatsFromStack @ stdcall GetUdpTable( ptr ptr long ) @ stub GetUdpTableFromStack -#@ stub GetUnicastIpAddressEntry +@ stdcall GetUnicastIpAddressEntry( ptr ) #@ stub GetUnicastIpAddressTable @ stdcall GetUniDirectionalAdapterInfo( ptr ptr ) @ stdcall Icmp6CreateFile() diff --git a/dlls/iphlpapi/iphlpapi_main.c b/dlls/iphlpapi/iphlpapi_main.c index 1daf54d..cfa5d9d 100644 --- a/dlls/iphlpapi/iphlpapi_main.c +++ b/dlls/iphlpapi/iphlpapi_main.c @@ -2467,6 +2467,75 @@ DWORD WINAPI GetExtendedUdpTable(PVOID pUdpTable, PDWORD pdwSize, BOOL bOrder, return ret; }
+DWORD WINAPI GetUnicastIpAddressEntry(MIB_UNICASTIPADDRESS_ROW *row) +{ + char buf[MAX_ADAPTER_NAME], *name; + DWORD ret = ERROR_FILE_NOT_FOUND; + IP_ADAPTER_ADDRESSES *aa, *ptr; + ULONG size = 0; + + TRACE("%p\n", row); + + if (!row) + return ERROR_INVALID_PARAMETER; + + if ((!(name = getInterfaceNameByIndex( row->InterfaceIndex, buf )) && + !(name = getInterfaceNameByIndex( row->InterfaceLuid.Info.NetLuidIndex, buf )))) + return ERROR_FILE_NOT_FOUND;
The second test for row->InterfaceLuid.Info.NetLuidIndex is really necessary? Because if I remove it the tests don't fail. Actually this is the main point, if I remove the whole if and add a ret = ERROR_FILE_NOT_FOUND before the for (like it was in v1) the tests also pass.
+ ret = GetAdaptersAddresses(row->Address.si_family, 0, NULL, NULL, &size); + if (ret != ERROR_BUFFER_OVERFLOW) + return ret; + if (!(ptr = HeapAlloc(GetProcessHeap(), 0, size))) + return ERROR_OUTOFMEMORY; + if ((ret = GetAdaptersAddresses(row->Address.si_family, 0, NULL, ptr, &size))) + { + HeapFree(GetProcessHeap(), 0, ptr); + return ret; + } + + for (aa = ptr; aa; aa = aa->Next) + { + IP_ADAPTER_UNICAST_ADDRESS *ua; + + if (aa->u.s.IfIndex != row->InterfaceIndex) + continue; + + ret = ERROR_NOT_FOUND; + + ua = aa->FirstUnicastAddress; + while (ua) + { + SOCKADDR_INET *uaaddr = (SOCKADDR_INET *)ua->Address.lpSockaddr; + + if ((row->Address.si_family == WS_AF_INET6 && !memcmp(&row->Address.Ipv6.sin6_addr, &uaaddr->Ipv6.sin6_addr, sizeof(row->Address.Ipv6.sin6_addr))) || + (row->Address.si_family == WS_AF_INET && !memcmp(&row->Address.Ipv4.sin_addr, &uaaddr->Ipv4.sin_addr, sizeof(row->Address.Ipv4.sin_addr))))
I forgot this in v1 but this line is also too long, sorry. By the way, what about comparing the ipv4 directly (Ipv4.sin_addr.S_un.S_addr ==)?
participants (1)
-
Bruno Jesus