Network: Only use a single interface for UPnP

This commit is contained in:
twinaphex 2021-12-05 03:47:48 +01:00
parent 9f01ebf0a9
commit 6f60ee9b6e
2 changed files with 21 additions and 14 deletions

View File

@ -34,13 +34,13 @@ struct natt_status
{ {
/* True if we've resolved an external IPv4 address */ /* True if we've resolved an external IPv4 address */
bool have_inet4; bool have_inet4;
/* External IPv4 address */
struct sockaddr_in ext_inet4_addr;
#if defined(AF_INET6) && !defined(HAVE_SOCKET_LEGACY) && !defined(_3DS)
/* True if we've resolved an external IPv6 address */ /* True if we've resolved an external IPv6 address */
bool have_inet6; bool have_inet6;
/* External IPv6 address */
/** External IPv4 address */
struct sockaddr_in ext_inet4_addr;
#if defined(AF_INET6) && !defined(HAVE_SOCKET_LEGACY) && !defined(_3DS)
/** External IPv6 address */
struct sockaddr_in6 ext_inet6_addr; struct sockaddr_in6 ext_inet6_addr;
#endif #endif
}; };

View File

@ -173,7 +173,7 @@ static bool natt_open_port(struct natt_status *status,
memcpy(&status->ext_inet4_addr, ext_addrinfo->ai_addr, memcpy(&status->ext_inet4_addr, ext_addrinfo->ai_addr,
sizeof(status->ext_inet4_addr)); sizeof(status->ext_inet4_addr));
} }
#if defined(AF_INET6) && !defined(HAVE_SOCKET_LEGACY) #if defined(AF_INET6) && !defined(_3DS)
else if (ext_addrinfo->ai_family == AF_INET6 && else if (ext_addrinfo->ai_family == AF_INET6 &&
ext_addrinfo->ai_addrlen >= sizeof(status->ext_inet6_addr)) ext_addrinfo->ai_addrlen >= sizeof(status->ext_inet6_addr))
{ {
@ -212,7 +212,6 @@ bool natt_open_port_any(struct natt_status *status,
struct addrinfo *addr; struct addrinfo *addr;
char port_str[6]; char port_str[6];
struct addrinfo hints = {0}; struct addrinfo hints = {0};
bool ret = false;
/* get our interfaces */ /* get our interfaces */
if (!net_ifinfo_new(&list)) if (!net_ifinfo_new(&list))
@ -225,8 +224,11 @@ bool natt_open_port_any(struct natt_status *status,
struct net_ifinfo_entry *entry = &list.entries[i]; struct net_ifinfo_entry *entry = &list.entries[i];
/* ignore localhost */ /* ignore localhost */
if (string_is_equal(entry->host, "127.0.0.1") || if (string_is_equal(entry->host, "127.0.0.1"))
string_is_equal(entry->host, "::1")) continue;
/* ignore IPv6 for now */
if (strchr(entry->host, ':'))
continue; continue;
addr = NULL; addr = NULL;
@ -237,17 +239,20 @@ bool natt_open_port_any(struct natt_status *status,
/* make a request for this host */ /* make a request for this host */
if (natt_open_port(status, addr->ai_addr, addr->ai_addrlen, if (natt_open_port(status, addr->ai_addr, addr->ai_addrlen,
proto)) proto))
ret = true; {
freeaddrinfo_retro(addr);
net_ifinfo_free(&list);
return true;
}
freeaddrinfo_retro(addr); freeaddrinfo_retro(addr);
} }
net_ifinfo_free(&list); net_ifinfo_free(&list);
return ret;
#else
return false;
#endif #endif
return false;
} }
bool natt_close_port(struct natt_status *status, bool natt_close_port(struct natt_status *status,
@ -272,11 +277,13 @@ bool natt_close_port(struct natt_status *status,
addr = (struct sockaddr *) &status->ext_inet4_addr; addr = (struct sockaddr *) &status->ext_inet4_addr;
addrlen = sizeof(status->ext_inet4_addr); addrlen = sizeof(status->ext_inet4_addr);
} }
#if defined(AF_INET6) && !defined(_3DS)
else if (status->have_inet6) else if (status->have_inet6)
{ {
addr = (struct sockaddr *) &status->ext_inet6_addr; addr = (struct sockaddr *) &status->ext_inet6_addr;
addrlen = sizeof(status->ext_inet6_addr); addrlen = sizeof(status->ext_inet6_addr);
} }
#endif
else else
return false; return false;