mirror of
https://github.com/dolphin-emu/dolphin.git
synced 2025-05-11 04:57:09 +03:00
Fix bogus UPnP requests
UPNP_AddPortMapping needs our IP address, however enet_address_get_host will return 0.0.0.0 or a host name in most cases. This gets our IP address from the socket to the IGD.
This commit is contained in:
parent
78b68b707f
commit
9a01ced032
2 changed files with 12 additions and 11 deletions
|
@ -937,6 +937,7 @@ std::vector<std::pair<std::string, std::string>> NetPlayServer::GetInterfaceList
|
||||||
|
|
||||||
struct UPNPUrls NetPlayServer::m_upnp_urls;
|
struct UPNPUrls NetPlayServer::m_upnp_urls;
|
||||||
struct IGDdatas NetPlayServer::m_upnp_data;
|
struct IGDdatas NetPlayServer::m_upnp_data;
|
||||||
|
std::string NetPlayServer::m_upnp_ourip;
|
||||||
u16 NetPlayServer::m_upnp_mapped = 0;
|
u16 NetPlayServer::m_upnp_mapped = 0;
|
||||||
bool NetPlayServer::m_upnp_inited = false;
|
bool NetPlayServer::m_upnp_inited = false;
|
||||||
bool NetPlayServer::m_upnp_error = false;
|
bool NetPlayServer::m_upnp_error = false;
|
||||||
|
@ -953,23 +954,17 @@ void NetPlayServer::TryPortmapping(u16 port)
|
||||||
// UPnP thread: try to map a port
|
// UPnP thread: try to map a port
|
||||||
void NetPlayServer::mapPortThread(const u16 port)
|
void NetPlayServer::mapPortThread(const u16 port)
|
||||||
{
|
{
|
||||||
ENetAddress adr = {ENET_HOST_ANY, port};
|
|
||||||
char cIP[20];
|
|
||||||
|
|
||||||
enet_address_get_host(&adr, cIP, 20);
|
|
||||||
std::string ourIP(cIP);
|
|
||||||
|
|
||||||
if (!m_upnp_inited)
|
if (!m_upnp_inited)
|
||||||
if (!initUPnP())
|
if (!initUPnP())
|
||||||
goto fail;
|
goto fail;
|
||||||
|
|
||||||
if (!UPnPMapPort(ourIP, port))
|
if (!UPnPMapPort(m_upnp_ourip, port))
|
||||||
goto fail;
|
goto fail;
|
||||||
|
|
||||||
NOTICE_LOG(NETPLAY, "Successfully mapped port %d to %s.", port, ourIP.c_str());
|
NOTICE_LOG(NETPLAY, "Successfully mapped port %d to %s.", port, m_upnp_ourip.c_str());
|
||||||
return;
|
return;
|
||||||
fail:
|
fail:
|
||||||
WARN_LOG(NETPLAY, "Failed to map port %d to %s.", port, ourIP.c_str());
|
WARN_LOG(NETPLAY, "Failed to map port %d to %s.", port, m_upnp_ourip.c_str());
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -986,6 +981,7 @@ bool NetPlayServer::initUPnP()
|
||||||
{
|
{
|
||||||
std::vector<UPNPDev*> igds;
|
std::vector<UPNPDev*> igds;
|
||||||
int descXMLsize = 0, upnperror = 0;
|
int descXMLsize = 0, upnperror = 0;
|
||||||
|
char cIP[20];
|
||||||
|
|
||||||
// Don't init if already inited
|
// Don't init if already inited
|
||||||
if (m_upnp_inited)
|
if (m_upnp_inited)
|
||||||
|
@ -1027,15 +1023,19 @@ bool NetPlayServer::initUPnP()
|
||||||
std::unique_ptr<char, decltype(&std::free)> descXML(nullptr, std::free);
|
std::unique_ptr<char, decltype(&std::free)> descXML(nullptr, std::free);
|
||||||
int statusCode = 200;
|
int statusCode = 200;
|
||||||
#if MINIUPNPC_API_VERSION >= 16
|
#if MINIUPNPC_API_VERSION >= 16
|
||||||
descXML.reset(static_cast<char*>(miniwget(dev->descURL, &descXMLsize, 0, &statusCode)));
|
descXML.reset(static_cast<char*>(
|
||||||
|
miniwget_getaddr(dev->descURL, &descXMLsize, cIP, sizeof(cIP), 0, &statusCode)));
|
||||||
#else
|
#else
|
||||||
descXML.reset(static_cast<char*>(miniwget(dev->descURL, &descXMLsize, 0)));
|
descXML.reset(
|
||||||
|
static_cast<char*>(miniwget_getaddr(dev->descURL, &descXMLsize, cIP, sizeof(cIP), 0)));
|
||||||
#endif
|
#endif
|
||||||
if (descXML && statusCode == 200)
|
if (descXML && statusCode == 200)
|
||||||
{
|
{
|
||||||
parserootdesc(descXML.get(), descXMLsize, &m_upnp_data);
|
parserootdesc(descXML.get(), descXMLsize, &m_upnp_data);
|
||||||
GetUPNPUrls(&m_upnp_urls, &m_upnp_data, dev->descURL, 0);
|
GetUPNPUrls(&m_upnp_urls, &m_upnp_data, dev->descURL, 0);
|
||||||
|
|
||||||
|
m_upnp_ourip = cIP;
|
||||||
|
|
||||||
NOTICE_LOG(NETPLAY, "Got info from IGD at %s.", dev->descURL);
|
NOTICE_LOG(NETPLAY, "Got info from IGD at %s.", dev->descURL);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
|
@ -134,6 +134,7 @@ private:
|
||||||
|
|
||||||
static struct UPNPUrls m_upnp_urls;
|
static struct UPNPUrls m_upnp_urls;
|
||||||
static struct IGDdatas m_upnp_data;
|
static struct IGDdatas m_upnp_data;
|
||||||
|
static std::string m_upnp_ourip;
|
||||||
static u16 m_upnp_mapped;
|
static u16 m_upnp_mapped;
|
||||||
static bool m_upnp_inited;
|
static bool m_upnp_inited;
|
||||||
static bool m_upnp_error;
|
static bool m_upnp_error;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue