Commit 67c8a82f authored by Huw Davies's avatar Huw Davies Committed by Alexandre Julliard

iphlpapi: Implement GetUnicastIpAddressEntry() on top of nsi.

parent 2f3ab0b2
...@@ -2696,69 +2696,48 @@ static void unicast_row_fill( MIB_UNICASTIPADDRESS_ROW *row, USHORT fam, void *k ...@@ -2696,69 +2696,48 @@ static void unicast_row_fill( MIB_UNICASTIPADDRESS_ROW *row, USHORT fam, void *k
DWORD WINAPI GetUnicastIpAddressEntry(MIB_UNICASTIPADDRESS_ROW *row) DWORD WINAPI GetUnicastIpAddressEntry(MIB_UNICASTIPADDRESS_ROW *row)
{ {
IP_ADAPTER_ADDRESSES *aa, *ptr; struct nsi_ipv4_unicast_key key4;
ULONG size = 0; struct nsi_ipv6_unicast_key key6;
DWORD ret; struct nsi_ip_unicast_rw rw;
struct nsi_ip_unicast_dynamic dyn;
struct nsi_ip_unicast_static stat;
const NPI_MODULEID *mod;
DWORD err, key_size;
void *key;
TRACE("%p\n", row); TRACE( "%p\n", row );
if (!row) if (!row) return ERROR_INVALID_PARAMETER;
return ERROR_INVALID_PARAMETER; mod = ip_module_id( row->Address.si_family );
if (!mod) return ERROR_INVALID_PARAMETER;
ret = GetAdaptersAddresses(row->Address.si_family, 0, NULL, NULL, &size); if (!row->InterfaceLuid.Value)
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); err = ConvertInterfaceIndexToLuid( row->InterfaceIndex, &row->InterfaceLuid );
return ret; if (err) return err;
} }
ret = ERROR_FILE_NOT_FOUND; if (row->Address.si_family == WS_AF_INET)
for (aa = ptr; aa; aa = aa->Next)
{
IP_ADAPTER_UNICAST_ADDRESS *ua;
if (aa->u.s.IfIndex != row->InterfaceIndex &&
memcmp(&aa->Luid, &row->InterfaceLuid, sizeof(row->InterfaceLuid)))
continue;
ret = ERROR_NOT_FOUND;
ua = aa->FirstUnicastAddress;
while (ua)
{ {
SOCKADDR_INET *uaaddr = (SOCKADDR_INET *)ua->Address.lpSockaddr; key4.luid = row->InterfaceLuid;
key4.addr = row->Address.Ipv4.sin_addr;
if ((row->Address.si_family == WS_AF_INET6 && key4.pad = 0;
!memcmp(&row->Address.Ipv6.sin6_addr, &uaaddr->Ipv6.sin6_addr, sizeof(uaaddr->Ipv6.sin6_addr))) || key = &key4;
(row->Address.si_family == WS_AF_INET && key_size = sizeof(key4);
row->Address.Ipv4.sin_addr.S_un.S_addr == uaaddr->Ipv4.sin_addr.S_un.S_addr))
{
memcpy(&row->InterfaceLuid, &aa->Luid, sizeof(aa->Luid));
row->InterfaceIndex = aa->u.s.IfIndex;
row->PrefixOrigin = ua->PrefixOrigin;
row->SuffixOrigin = ua->SuffixOrigin;
row->ValidLifetime = ua->ValidLifetime;
row->PreferredLifetime = ua->PreferredLifetime;
row->OnLinkPrefixLength = ua->OnLinkPrefixLength;
row->SkipAsSource = 0;
row->DadState = ua->DadState;
if (row->Address.si_family == WS_AF_INET6)
row->ScopeId.u.Value = row->Address.Ipv6.sin6_scope_id;
else
row->ScopeId.u.Value = 0;
NtQuerySystemTime(&row->CreationTimeStamp);
HeapFree(GetProcessHeap(), 0, ptr);
return NO_ERROR;
}
ua = ua->Next;
} }
else if (row->Address.si_family == WS_AF_INET6)
{
key6.luid = row->InterfaceLuid;
key6.addr = row->Address.Ipv6.sin6_addr;
key = &key6;
key_size = sizeof(key6);
} }
HeapFree(GetProcessHeap(), 0, ptr); else return ERROR_INVALID_PARAMETER;
return ret; err = NsiGetAllParameters( 1, mod, NSI_IP_UNICAST_TABLE, key, key_size, &rw, sizeof(rw),
&dyn, sizeof(dyn), &stat, sizeof(stat) );
if (!err) unicast_row_fill( row, row->Address.si_family, key, &rw, &dyn, &stat );
return err;
} }
DWORD WINAPI GetUnicastIpAddressTable(ADDRESS_FAMILY family, MIB_UNICASTIPADDRESS_TABLE **table) DWORD WINAPI GetUnicastIpAddressTable(ADDRESS_FAMILY family, MIB_UNICASTIPADDRESS_TABLE **table)
......
...@@ -1962,7 +1962,7 @@ static void test_GetUnicastIpAddressEntry(void) ...@@ -1962,7 +1962,7 @@ static void test_GetUnicastIpAddressEntry(void)
memset( &row, 0, sizeof(row) ); memset( &row, 0, sizeof(row) );
ret = pGetUnicastIpAddressEntry( &row ); ret = pGetUnicastIpAddressEntry( &row );
todo_wine ok( ret == ERROR_INVALID_PARAMETER, "got %u\n", ret ); ok( ret == ERROR_INVALID_PARAMETER, "got %u\n", ret );
memset( &row, 0, sizeof(row) ); memset( &row, 0, sizeof(row) );
row.Address.Ipv4.sin_family = AF_INET; row.Address.Ipv4.sin_family = AF_INET;
...@@ -1974,7 +1974,7 @@ static void test_GetUnicastIpAddressEntry(void) ...@@ -1974,7 +1974,7 @@ static void test_GetUnicastIpAddressEntry(void)
memset( &row, 0, sizeof(row) ); memset( &row, 0, sizeof(row) );
row.InterfaceIndex = 123; row.InterfaceIndex = 123;
ret = pGetUnicastIpAddressEntry( &row ); ret = pGetUnicastIpAddressEntry( &row );
todo_wine ok( ret == ERROR_INVALID_PARAMETER, "got %u\n", ret ); ok( ret == ERROR_INVALID_PARAMETER, "got %u\n", ret );
memset( &row, 0, sizeof(row) ); memset( &row, 0, sizeof(row) );
row.InterfaceIndex = get_interface_index(); row.InterfaceIndex = get_interface_index();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment