mirror of
https://github.com/flyinghead/flycast.git
synced 2026-11-07 09:16:10 -10:00
ggpo: resolve the peer host name (#2514)
GGPO parses the peer address with inet_pton() only, so a host name in the Peer field silently becomes 0.0.0.0 and the session never syncs, without any error. Resolve non-numeric addresses with getaddrinfo() before handing them to GGPO, and fail with a clear message when the name cannot be resolved. Co-authored-by: unjordi <[email protected]> [ci skip]
This commit is contained in:
1 parent
e6d3365c0b
commit
fa3c526e4f
1 file changed
+20
@@ -25,6 +25,7 @@
|
||||
#include "cfg/option.h"
|
||||
#include "oslib/oslib.h"
|
||||
#include "oslib/i18n.h"
|
||||
#include "net_platform.h"
|
||||
#include <algorithm>
|
||||
|
||||
namespace ggpo
|
||||
@@ -595,6 +596,25 @@ void startSession(int localPort, int localPlayerNum)
|
||||
peerPort = atoi(config::NetworkServer.get().substr(colon + 1).c_str());
|
||||
}
|
||||
player.type = GGPO_PLAYERTYPE_REMOTE;
|
||||
// GGPO only takes a dotted IPv4 address: resolve host names here
|
||||
in_addr peerAddr;
|
||||
if (inet_pton(AF_INET, peerIp.c_str(), &peerAddr) != 1)
|
||||
{
|
||||
addrinfo hints {};
|
||||
hints.ai_family = AF_INET;
|
||||
hints.ai_socktype = SOCK_DGRAM;
|
||||
addrinfo *result = nullptr;
|
||||
if (getaddrinfo(peerIp.c_str(), nullptr, &hints, &result) != 0 || result == nullptr)
|
||||
{
|
||||
stopSession();
|
||||
throw FlycastException(strprintf(i18n::T("GGPO: unknown peer address %s"), peerIp.c_str()));
|
||||
}
|
||||
char address[INET_ADDRSTRLEN];
|
||||
inet_ntop(AF_INET, &((sockaddr_in *)result->ai_addr)->sin_addr, address, sizeof(address));
|
||||
freeaddrinfo(result);
|
||||
NOTICE_LOG(NETWORK, "GGPO: peer %s resolved to %s", peerIp.c_str(), address);
|
||||
peerIp = address;
|
||||
}
|
||||
strcpy(player.u.remote.ip_address, peerIp.c_str());
|
||||
player.u.remote.port = peerPort;
|
||||
player.player_num = (1 - localPlayerNum) + 1;
|
||||
|
||||
Reference in new issue
Block a user