for details see https://bugs.winehq.org/show_bug.cgi?id=56065 This change adds an implementation of Win32 API function GetAnycastIpAddressTable() that is used by Adoptium OpenJDK 21 and later to initialize Secure Random Generator. This implementation does not return real information, it just says "no entries found".
From: Rastislav Stanik git@rastos.org
for details see https://bugs.winehq.org/show_bug.cgi?id=56065 --- dlls/iphlpapi/iphlpapi.spec | 2 +- dlls/iphlpapi/iphlpapi_main.c | 25 +++++++++++++++++++++++++ include/netioapi.h | 13 +++++++++++++ 3 files changed, 39 insertions(+), 1 deletion(-)
diff --git a/dlls/iphlpapi/iphlpapi.spec b/dlls/iphlpapi/iphlpapi.spec index ef2c576947d..feb46c2b35f 100644 --- a/dlls/iphlpapi/iphlpapi.spec +++ b/dlls/iphlpapi/iphlpapi.spec @@ -73,7 +73,7 @@ @ stdcall GetAdaptersAddresses( long long ptr ptr ptr ) @ stdcall GetAdaptersInfo( ptr ptr ) #@ stub GetAnycastIpAddressEntry -#@ stub GetAnycastIpAddressTable +@ stdcall GetAnycastIpAddressTable(long ptr) @ stdcall GetBestInterface( long ptr ) @ stdcall GetBestInterfaceEx( ptr ptr ) @ stub GetBestInterfaceFromStack diff --git a/dlls/iphlpapi/iphlpapi_main.c b/dlls/iphlpapi/iphlpapi_main.c index 9c7582b71fb..4ee377f0d0e 100644 --- a/dlls/iphlpapi/iphlpapi_main.c +++ b/dlls/iphlpapi/iphlpapi_main.c @@ -3597,6 +3597,31 @@ static void unicast_row_fill( MIB_UNICASTIPADDRESS_ROW *row, USHORT fam, void *k row->CreationTimeStamp.QuadPart = stat->creation_time; }
+DWORD WINAPI GetAnycastIpAddressTable(ADDRESS_FAMILY family, MIB_ANYCASTIPADDRESS_TABLE **table) +{ + DWORD err, size; + TRACE( "%u, %p\n", family, table ); + + if (!table || (family != AF_INET && family != AF_INET6 && family != AF_UNSPEC)) + return ERROR_INVALID_PARAMETER; + + FIXME(":stub - returning empty MIB_ANYCASTIPADDRESS_TABLE\n"); + + size = FIELD_OFFSET(MIB_ANYCASTIPADDRESS_TABLE, Table[0]); + *table = heap_alloc( size ); + if (!*table) + { + err = ERROR_NOT_ENOUGH_MEMORY; + goto err; + } + (*table)->NumEntries = 0; + err = NO_ERROR; + +err: + return err; +} + + DWORD WINAPI GetUnicastIpAddressEntry(MIB_UNICASTIPADDRESS_ROW *row) { struct nsi_ipv4_unicast_key key4; diff --git a/include/netioapi.h b/include/netioapi.h index 8c1491f9efa..24b4f42d645 100644 --- a/include/netioapi.h +++ b/include/netioapi.h @@ -166,12 +166,25 @@ typedef struct _MIB_UNICASTIPADDRESS_ROW LARGE_INTEGER CreationTimeStamp; } MIB_UNICASTIPADDRESS_ROW, *PMIB_UNICASTIPADDRESS_ROW;
+typedef struct _MIB_ANYCASTIPADDRESS_ROW { + SOCKADDR_INET Address; + NET_LUID InterfaceLuid; + NET_IFINDEX InterfaceIndex; + SCOPE_ID ScopeId; +} MIB_ANYCASTIPADDRESS_ROW, *PMIB_ANYCASTIPADDRESS_ROW; + typedef struct _MIB_UNICASTIPADDRESS_TABLE { ULONG NumEntries; MIB_UNICASTIPADDRESS_ROW Table[1]; } MIB_UNICASTIPADDRESS_TABLE, *PMIB_UNICASTIPADDRESS_TABLE;
+typedef struct _MIB_ANYCASTIPADDRESS_TABLE +{ + ULONG NumEntries; + MIB_ANYCASTIPADDRESS_ROW Table[ANY_SIZE]; +} MIB_ANYCASTIPADDRESS_TABLE, *PMIB_ANYCASTIPADDRESS_TABLE; + typedef struct _IP_ADDRESS_PREFIX { SOCKADDR_INET Prefix;
Aida Jonikienė (@DodoGTA) commented about dlls/iphlpapi/iphlpapi_main.c:
row->CreationTimeStamp.QuadPart = stat->creation_time;
}
+DWORD WINAPI GetAnycastIpAddressTable(ADDRESS_FAMILY family, MIB_ANYCASTIPADDRESS_TABLE **table) +{
- DWORD err, size;
- TRACE( "%u, %p\n", family, table );
Can you change this to a FIXME with `(%u %p): stub\n` string inside (as it's commonly done for stub functions)?
Aida Jonikienė (@DodoGTA) commented about dlls/iphlpapi/iphlpapi_main.c:
row->CreationTimeStamp.QuadPart = stat->creation_time;
}
+DWORD WINAPI GetAnycastIpAddressTable(ADDRESS_FAMILY family, MIB_ANYCASTIPADDRESS_TABLE **table) +{
- DWORD err, size;
- TRACE( "%u, %p\n", family, table );
- if (!table || (family != AF_INET && family != AF_INET6 && family != AF_UNSPEC))
return ERROR_INVALID_PARAMETER;
- FIXME(":stub - returning empty MIB_ANYCASTIPADDRESS_TABLE\n");
This string should be changed to just `returning empty MIB_ANYCASTIPADDRESS_TABLE\n` instead (or this FIXME can be removed entirely because the one above would serve its purpose)
Aida Jonikienė (@DodoGTA) commented about dlls/iphlpapi/iphlpapi_main.c:
+{
- DWORD err, size;
- TRACE( "%u, %p\n", family, table );
- if (!table || (family != AF_INET && family != AF_INET6 && family != AF_UNSPEC))
return ERROR_INVALID_PARAMETER;
- FIXME(":stub - returning empty MIB_ANYCASTIPADDRESS_TABLE\n");
- size = FIELD_OFFSET(MIB_ANYCASTIPADDRESS_TABLE, Table[0]);
- *table = heap_alloc( size );
- if (!*table)
- {
err = ERROR_NOT_ENOUGH_MEMORY;
goto err;
- }
This can be simplified to `if (!*table) return ERROR_NOT_ENOUGH_MEMORY;`
Aida Jonikienė (@DodoGTA) commented about dlls/iphlpapi/iphlpapi_main.c:
return ERROR_INVALID_PARAMETER;
- FIXME(":stub - returning empty MIB_ANYCASTIPADDRESS_TABLE\n");
- size = FIELD_OFFSET(MIB_ANYCASTIPADDRESS_TABLE, Table[0]);
- *table = heap_alloc( size );
- if (!*table)
- {
err = ERROR_NOT_ENOUGH_MEMORY;
goto err;
- }
- (*table)->NumEntries = 0;
- err = NO_ERROR;
+err:
- return err;
To complement the change above this can be just be `return NO_ERROR;` (make sure to remove the unused `err` variable)
Aida Jonikienė (@DodoGTA) commented about dlls/iphlpapi/iphlpapi.spec:
@ stdcall GetAdaptersAddresses( long long ptr ptr ptr ) @ stdcall GetAdaptersInfo( ptr ptr ) #@ stub GetAnycastIpAddressEntry -#@ stub GetAnycastIpAddressTable +@ stdcall GetAnycastIpAddressTable(long ptr)
This is definitely a nit but can you add the spaces near the brackets like in other lines for consistency?
Also for the commit message you should use the `<Wine component>: <change message>.` format with the dot included to meet Julliard's standards (like `mfc42: Add stub DLL.` or `ntdll/tests: Add more CONTEXT_EX tests.`)
For linked bug reports the standard practice is to add a Wine-Bug header to the bottom with the bug report URL (like `Wine-Bug: https://bugs.winehq.org/show_bug.cgi?id=53093%60)
Aida Jonikienė (@DodoGTA) commented about include/netioapi.h:
LARGE_INTEGER CreationTimeStamp;
} MIB_UNICASTIPADDRESS_ROW, *PMIB_UNICASTIPADDRESS_ROW;
+typedef struct _MIB_ANYCASTIPADDRESS_ROW {
- SOCKADDR_INET Address;
- NET_LUID InterfaceLuid;
- NET_IFINDEX InterfaceIndex;
- SCOPE_ID ScopeId;
+} MIB_ANYCASTIPADDRESS_ROW, *PMIB_ANYCASTIPADDRESS_ROW;
I just missed that you have defined a duplicate struct (can you remove it?)
Aida Jonikienė (@DodoGTA) commented about include/netioapi.h:
- NET_IFINDEX InterfaceIndex;
- SCOPE_ID ScopeId;
+} MIB_ANYCASTIPADDRESS_ROW, *PMIB_ANYCASTIPADDRESS_ROW;
typedef struct _MIB_UNICASTIPADDRESS_TABLE { ULONG NumEntries; MIB_UNICASTIPADDRESS_ROW Table[1]; } MIB_UNICASTIPADDRESS_TABLE, *PMIB_UNICASTIPADDRESS_TABLE;
+typedef struct _MIB_ANYCASTIPADDRESS_TABLE +{
- ULONG NumEntries;
- MIB_ANYCASTIPADDRESS_ROW Table[ANY_SIZE];
+} MIB_ANYCASTIPADDRESS_TABLE, *PMIB_ANYCASTIPADDRESS_TABLE;
Same issue for this struct
Aida Jonikienė (@DodoGTA) commented about dlls/iphlpapi/iphlpapi_main.c:
row->CreationTimeStamp.QuadPart = stat->creation_time;
}
+DWORD WINAPI GetAnycastIpAddressTable(ADDRESS_FAMILY family, MIB_ANYCASTIPADDRESS_TABLE **table) +{
- DWORD err, size;
- TRACE( "%u, %p\n", family, table );
- if (!table || (family != AF_INET && family != AF_INET6 && family != AF_UNSPEC))
return ERROR_INVALID_PARAMETER;
- FIXME(":stub - returning empty MIB_ANYCASTIPADDRESS_TABLE\n");
- size = FIELD_OFFSET(MIB_ANYCASTIPADDRESS_TABLE, Table[0]);
- *table = heap_alloc( size );
`sizeof(MIB_ANYCASTIPADDRESS_TABLE)` would be a better size calculation (also maybe use `heap_alloc_zero` for safety)
On Thu Jan 25 20:50:51 2024 +0000, Aida Jonikienė wrote:
This can be simplified to `if (!*table) return ERROR_NOT_ENOUGH_MEMORY;`
I was inspired with the similar function GetUnicastIpAddressTable() a little further down. But I agree with you.
On Thu Jan 25 20:58:00 2024 +0000, Aida Jonikienė wrote:
I just missed that you have defined a duplicate struct (can you remove it?)
Hold on. Note that there are two structures with similar names: MIB_UNICASTIPADDRESS_ROW MIB_ANYCASTIPADDRESS_ROW
On Thu Jan 25 20:58:01 2024 +0000, Aida Jonikienė wrote:
Same issue for this struct
Similar to above - there are two structure with very similar names but not identical: MIB_UNICASTIPADDRESS_TABLE vs MIB_ANYCASTIPADDRESS_TABLE.
On Thu Jan 25 21:04:53 2024 +0000, Aida Jonikienė wrote:
`sizeof(MIB_ANYCASTIPADDRESS_TABLE)` would be a better size calculation (also maybe use `heap_alloc_zero` for safety)
Again I took inspiration from existing function GetUnicastIpAddressTable(). Basically the new code is supposed to return a structure that has member "NumEntries" and that member says how many structures of type MIB_ANYCASTIPADDRESS_ROW follow. Since I'm going to return zero rows, then the array of rows is zero-length. Of course I can allocate one row (rather then zero) that will not be used/populated with any data. Is that acceptable?
On Thu Jan 25 20:50:52 2024 +0000, Aida Jonikienė wrote:
This is definitely a nit but can you add the spaces near the brackets like in other lines for consistency?
Sure.