Attempt to fix UPnP for some Windows devices (#13402)

Yet another attempt at it.
This commit is contained in:
Cthulhu-throwaway 2021-12-23 19:52:01 -03:00 committed by GitHub
parent c6369b7861
commit ec97c86756
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 8 additions and 12 deletions

View File

@ -94,7 +94,8 @@ bool natt_init(void)
#if !defined(_MSC_VER) || _MSC_VER > 1400 #if !defined(_MSC_VER) || _MSC_VER > 1400
#if defined(_WIN32) && defined(IP_MULTICAST_IF) #if defined(_WIN32) && defined(IP_MULTICAST_IF)
if (GetBestRoute(0xDFFFFFFF, 0, &ip_forward) == NO_ERROR) if (GetBestRoute(inet_addr("223.255.255.255"),
0, &ip_forward) == NO_ERROR)
{ {
IF_INDEX index = ip_forward.dwForwardIfIndex; IF_INDEX index = ip_forward.dwForwardIfIndex;
PMIB_IPADDRTABLE table = malloc(sizeof(MIB_IPADDRTABLE)); PMIB_IPADDRTABLE table = malloc(sizeof(MIB_IPADDRTABLE));

View File

@ -241,8 +241,7 @@ bool init_netplay_discovery(void)
int fd = socket_init( int fd = socket_init(
(void **) &addr, 0, NULL, (void **) &addr, 0, NULL,
SOCKET_TYPE_DATAGRAM); SOCKET_TYPE_DATAGRAM);
bool ret = fd >= 0 && bool ret = fd >= 0;
socket_bind(fd, addr);
if (ret) if (ret)
{ {
@ -250,7 +249,8 @@ bool init_netplay_discovery(void)
#if defined(_WIN32) && defined(IP_MULTICAST_IF) #if defined(_WIN32) && defined(IP_MULTICAST_IF)
MIB_IPFORWARDROW ip_forward; MIB_IPFORWARDROW ip_forward;
if (GetBestRoute(0xDFFFFFFF, 0, &ip_forward) == NO_ERROR) if (GetBestRoute(inet_addr("223.255.255.255"),
0, &ip_forward) == NO_ERROR)
{ {
IF_INDEX index = ip_forward.dwForwardIfIndex; IF_INDEX index = ip_forward.dwForwardIfIndex;
PMIB_IPADDRTABLE table = malloc(sizeof(MIB_IPADDRTABLE)); PMIB_IPADDRTABLE table = malloc(sizeof(MIB_IPADDRTABLE));
@ -306,16 +306,11 @@ bool init_netplay_discovery(void)
} }
#endif #endif
if (!socket_bind(fd, addr))
{
socket_close(fd);
net_st->lan_ad_client_fd = -1;
return false;
}
net_st->lan_ad_client_fd = fd; net_st->lan_ad_client_fd = fd;
ret = socket_bind(fd, addr);
} }
else if (!ret)
{ {
if (fd >= 0) if (fd >= 0)
socket_close(fd); socket_close(fd);