added ORBIS_NET_CTL_INFO_IP_ADDRESS case in sceNetCtlGetInfo

This commit is contained in:
georgemoralis 2024-10-09 20:32:03 +03:00
parent c030e821cb
commit ba55486e9f
2 changed files with 28 additions and 1 deletions

View file

@ -1,6 +1,15 @@
// SPDX-FileCopyrightText: Copyright 2024 shadPS4 Emulator Project
// SPDX-License-Identifier: GPL-2.0-or-later
#ifdef WIN32
#define _WINSOCK_DEPRECATED_NO_WARNINGS
#include <Ws2tcpip.h>
#include <iphlpapi.h>
#include <winsock2.h>
#else
#include <arpa/inet.h>
#endif
#include "common/logging/log.h"
#include "common/singleton.h"
#include "core/libraries/error_codes.h"
@ -154,10 +163,27 @@ int PS4_SYSV_ABI sceNetCtlGetInfo(int code, OrbisNetCtlInfo* info) {
case ORBIS_NET_CTL_INFO_LINK:
info->link = ORBIS_NET_CTL_LINK_DISCONNECTED;
break;
case ORBIS_NET_CTL_INFO_IP_ADDRESS: {
strcpy(info->ip_address,
"127.0.0.1"); // placeholder in case gethostbyname can't find another ip
char devname[80];
gethostname(devname, 80);
struct hostent* resolved = gethostbyname(devname);
for (int i = 0; resolved->h_addr_list[i] != nullptr; ++i) {
struct in_addr addrIn;
memcpy(&addrIn, resolved->h_addr_list[i], sizeof(u32));
char* addr = inet_ntoa(addrIn);
if (strcmp(addr, "127.0.0.1") != 0) {
strcpy(info->ip_address, addr);
break;
}
}
break;
}
default:
LOG_ERROR(Lib_NetCtl, "{} unsupported code", code);
}
LOG_ERROR(Lib_NetCtl, "(STUBBED) called");
LOG_DEBUG(Lib_NetCtl, "(STUBBED) called");
return ORBIS_OK;
}

View file

@ -50,6 +50,7 @@ typedef union OrbisNetCtlInfo {
// GetInfo codes
constexpr int ORBIS_NET_CTL_INFO_DEVICE = 1;
constexpr int ORBIS_NET_CTL_INFO_LINK = 4;
constexpr int ORBIS_NET_CTL_INFO_IP_ADDRESS = 14;
int PS4_SYSV_ABI sceNetBweCheckCallbackIpcInt();
int PS4_SYSV_ABI sceNetBweClearEventIpcInt();