diff --git a/core/network/ggpo.cpp b/core/network/ggpo.cpp index 64218ffc4..cc99e4296 100644 --- a/core/network/ggpo.cpp +++ b/core/network/ggpo.cpp @@ -25,6 +25,7 @@ #include "cfg/option.h" #include "oslib/oslib.h" #include "oslib/i18n.h" +#include "net_platform.h" #include 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;