[PATCH] ws2_32: Use if_nameindex() instead of SIOCGIFNAME.
Paul Gofman
pgofman at codeweavers.com
Tue Jan 19 04:11:58 CST 2021
Fixes Mac build broken by 03fcb54c0e852b93b94bd11225237af84cdc3697
Wine-Bug: https://bugs.winehq.org/show_bug.cgi?id=50525
Signed-off-by: Paul Gofman <pgofman at codeweavers.com>
---
The alternative would be to use if_indextoname(), but the current problem is
that it is available both in iphlpapi.dll and native libc. The function gets
a prototype from native net/if.h but is linked to WINAPI variant from iphlpapi.
Working that around probably does not worth it.
dlls/ws2_32/socket.c | 25 +++++++++++++++++++------
1 file changed, 19 insertions(+), 6 deletions(-)
diff --git a/dlls/ws2_32/socket.c b/dlls/ws2_32/socket.c
index 31ea9b339ed..5def84ce973 100644
--- a/dlls/ws2_32/socket.c
+++ b/dlls/ws2_32/socket.c
@@ -4797,6 +4797,7 @@ static DWORD get_interface_list(SOCKET s, void *out_buff, DWORD out_size, DWORD
DWORD size, interface_count = 0, ret;
INTERFACE_INFO *info = out_buff;
PMIB_IPADDRTABLE table = NULL;
+ struct if_nameindex *if_ni;
DWORD status = 0;
int fd;
@@ -4823,7 +4824,7 @@ static DWORD get_interface_list(SOCKET s, void *out_buff, DWORD out_size, DWORD
}
if (GetIpAddrTable(table, &size, TRUE) != NO_ERROR)
{
- ERR("Unable to get interface table./\n");
+ ERR("Unable to get interface table.\n");
status = WSAEINVAL;
goto done;
}
@@ -4835,24 +4836,36 @@ static DWORD get_interface_list(SOCKET s, void *out_buff, DWORD out_size, DWORD
goto done;
}
+ if (!(if_ni = if_nameindex()))
+ {
+ ERR("Unable to get interface name index.\n");
+ status = WSAEINVAL;
+ goto done;
+ }
+
for (; interface_count < table->dwNumEntries; ++interface_count, ++info)
{
unsigned int addr, mask;
struct ifreq if_info;
+ unsigned int i;
memset(info, 0, sizeof(*info));
- if_info.ifr_ifindex = table->table[interface_count].dwIndex;
- if (ioctl(fd, SIOCGIFNAME, &if_info) < 0)
+ for (i = 0; if_ni[i].if_index || if_ni[i].if_name; ++i)
+ if (if_ni[i].if_index == table->table[interface_count].dwIndex)
+ break;
+
+ if (!if_ni[i].if_name)
{
- ERR("Error obtaining interface name for ifindex %d.\n", if_info.ifr_ifindex);
+ ERR("Error obtaining interface name for ifindex %u.\n", table->table[interface_count].dwIndex);
status = WSAEINVAL;
break;
}
+ lstrcpynA(if_info.ifr_name, if_ni[i].if_name, IFNAMSIZ);
if (ioctl(fd, SIOCGIFFLAGS, &if_info) < 0)
{
- ERR("Error obtaining status flags for socket!\n");
+ ERR("Error obtaining status flags for socket.\n");
status = WSAEINVAL;
break;
}
@@ -4888,7 +4901,7 @@ static DWORD get_interface_list(SOCKET s, void *out_buff, DWORD out_size, DWORD
info->iiBroadcastAddress.AddressIn.sin_addr.WS_s_addr = addr | ~mask;
}
}
-
+ if_freenameindex(if_ni);
done:
heap_free(table);
*total_bytes = sizeof(INTERFACE_INFO) * interface_count;
--
2.29.2
More information about the wine-devel
mailing list