From ec97c86756308920b45185404646eb599576e2be Mon Sep 17 00:00:00 2001 From: Cthulhu-throwaway <96153783+Cthulhu-throwaway@users.noreply.github.com> Date: Thu, 23 Dec 2021 19:52:01 -0300 Subject: [PATCH] Attempt to fix UPnP for some Windows devices (#13402) Yet another attempt at it. --- libretro-common/net/net_natt.c | 3 ++- network/netplay/netplay_frontend.c | 17 ++++++----------- 2 files changed, 8 insertions(+), 12 deletions(-) diff --git a/libretro-common/net/net_natt.c b/libretro-common/net/net_natt.c index 9d5144f9d2..bfe7c570a7 100644 --- a/libretro-common/net/net_natt.c +++ b/libretro-common/net/net_natt.c @@ -94,7 +94,8 @@ bool natt_init(void) #if !defined(_MSC_VER) || _MSC_VER > 1400 #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; PMIB_IPADDRTABLE table = malloc(sizeof(MIB_IPADDRTABLE)); diff --git a/network/netplay/netplay_frontend.c b/network/netplay/netplay_frontend.c index 1d0a7e37ad..1d670a3d9a 100644 --- a/network/netplay/netplay_frontend.c +++ b/network/netplay/netplay_frontend.c @@ -241,8 +241,7 @@ bool init_netplay_discovery(void) int fd = socket_init( (void **) &addr, 0, NULL, SOCKET_TYPE_DATAGRAM); - bool ret = fd >= 0 && - socket_bind(fd, addr); + bool ret = fd >= 0; if (ret) { @@ -250,7 +249,8 @@ bool init_netplay_discovery(void) #if defined(_WIN32) && defined(IP_MULTICAST_IF) 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; PMIB_IPADDRTABLE table = malloc(sizeof(MIB_IPADDRTABLE)); @@ -306,16 +306,11 @@ bool init_netplay_discovery(void) } #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; + + ret = socket_bind(fd, addr); } - else + if (!ret) { if (fd >= 0) socket_close(fd);