From b3ababce9aa8f9ee09f2151898587f5c02aac45c Mon Sep 17 00:00:00 2001 From: Gregor Richards Date: Wed, 30 Nov 2016 00:25:16 -0500 Subject: [PATCH] Fix Netplay IPv6 support --- libretro-common/net/net_compat.c | 7 +++++-- network/netplay/netplay.c | 14 ++++++++++++++ 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/libretro-common/net/net_compat.c b/libretro-common/net/net_compat.c index e61c145b9c..0976068f0b 100644 --- a/libretro-common/net/net_compat.c +++ b/libretro-common/net/net_compat.c @@ -165,11 +165,14 @@ int getaddrinfo_retro(const char *node, const char *service, (void)in_addr; (void)info; + if (!hints->ai_family) + { #if defined(_WIN32) || defined(HAVE_SOCKET_LEGACY) - hints->ai_family = AF_INET; + hints->ai_family = AF_INET; #else - hints->ai_family = AF_UNSPEC; + hints->ai_family = AF_UNSPEC; #endif + } #ifdef HAVE_SOCKET_LEGACY info = (struct addrinfo*)calloc(1, sizeof(*info)); diff --git a/network/netplay/netplay.c b/network/netplay/netplay.c index 074b70e6ea..3fcea60f06 100644 --- a/network/netplay/netplay.c +++ b/network/netplay/netplay.c @@ -129,6 +129,10 @@ static bool init_tcp_socket(netplay_t *netplay, const char *server, port_buf[0] = '\0'; +#ifdef AF_INET6 + if (!server) + hints.ai_family = AF_INET6; +#endif hints.ai_socktype = SOCK_STREAM; if (!server) hints.ai_flags = AI_PASSIVE; @@ -140,6 +144,16 @@ static bool init_tcp_socket(netplay_t *netplay, const char *server, if (!res) return false; + /* If we're serving on IPv6, make sure we accept all connections, including + * IPv4 */ +#ifdef AF_INET6 + if (!server && res->ai_family == AF_INET6) + { + struct sockaddr_in6 *sin6 = (struct sockaddr_in6 *) res->ai_addr; + sin6->sin6_addr = in6addr_any; + } +#endif + /* If "localhost" is used, it is important to check every possible * address for IPv4/IPv6. */ tmp_info = res;