Add fallback if getnameinfo fails

This commit is contained in:
Florian Märkl 2020-12-30 12:37:28 +01:00
commit 89c3175d71
No known key found for this signature in database
GPG key ID: 125BC8A5A6A1E857
2 changed files with 4 additions and 4 deletions

View file

@ -155,7 +155,7 @@ typedef struct chiaki_session_t
bool ps5;
struct addrinfo *host_addrinfos;
struct addrinfo *host_addrinfo_selected;
char hostname[128];
char hostname[256];
char regist_key[CHIAKI_RPCRYPT_KEY_SIZE];
uint8_t morning[CHIAKI_RPCRYPT_KEY_SIZE];
uint8_t did[CHIAKI_RP_DID_SIZE];

View file

@ -596,11 +596,11 @@ static ChiakiErrorCode session_thread_request_session(ChiakiSession *session, Ch
set_port(sa, htons(SESSION_PORT));
// TODO: this can block, make cancelable somehow
int r = getnameinfo(sa, (socklen_t)ai->ai_addrlen, session->connect_info.hostname, sizeof(session->connect_info.hostname), NULL, 0, 0);
int r = getnameinfo(sa, (socklen_t)ai->ai_addrlen, session->connect_info.hostname, sizeof(session->connect_info.hostname), NULL, 0, NI_NUMERICHOST);
if(r != 0)
{
free(sa);
continue;
CHIAKI_LOGE(session->log, "getnameinfo failed with %s, filling the hostname with fallback", gai_strerror(r));
memcpy(session->connect_info.hostname, "unknown", 8);
}
CHIAKI_LOGI(session->log, "Trying to request session from %s:%d", session->connect_info.hostname, SESSION_PORT);