Implement inet_ntop and CELL_NET_CTL_INFO_LINK

Also fixed the default address not being set for all cases. Also tried
to fix the Win32 version of CELL_NET_CTL_INFO_IP_ADDRESS failing the
first time around.
This commit is contained in:
Raul Tambre 2016-01-04 12:14:00 +02:00
parent 8f937bda0f
commit f8446b227b
2 changed files with 28 additions and 10 deletions

View File

@ -164,18 +164,32 @@ s32 cellNetCtlGetInfo(s32 code, vm::ptr<CellNetCtlInfo> info)
freeifaddrs(ifaddr);
#endif
}
else if (code == CELL_NET_CTL_INFO_LINK)
{
if (rpcs3::config.misc.net.status.value() == misc_net_status::ip_obtained)
{
info->link = CELL_NET_CTL_LINK_CONNECTED;
}
else
{
info->link = CELL_NET_CTL_LINK_DISCONNECTED;
}
}
else if (code == CELL_NET_CTL_INFO_IP_ADDRESS)
{
// 0.0.0.0 seems to be the default address when no ethernet cables are connected to the PS3
strcpy_trunc(info->ip_address, "0.0.0.0");
#ifdef _WIN32
ULONG bufLen = sizeof(IP_ADAPTER_INFO) + 1;
PIP_ADAPTER_INFO pAdapterInfo = (PIP_ADAPTER_INFO)malloc(bufLen);
ULONG bufLen = sizeof(IP_ADAPTER_INFO);
PIP_ADAPTER_INFO pAdapterInfo = (IP_ADAPTER_INFO*)malloc(bufLen);
DWORD ret;
ret = GetAdaptersInfo(pAdapterInfo, &bufLen);
if (ret == ERROR_BUFFER_OVERFLOW)
{
cellNetCtl.Error("cellNetCtlGetInfo(IP_ADDRESS): GetAdaptersAddresses buffer overflow.");
cellNetCtl.Error("cellNetCtlGetInfo(IP_ADDRESS): GetAdaptersInfo buffer overflow.");
free(pAdapterInfo);
pAdapterInfo = (IP_ADAPTER_INFO*)malloc(bufLen);
@ -202,8 +216,6 @@ s32 cellNetCtlGetInfo(s32 code, vm::ptr<CellNetCtlInfo> info)
else
{
cellNetCtl.Error("cellNetCtlGetInfo(IP_ADDRESS): Call to GetAdaptersInfo failed. (%d)", ret);
// 0.0.0.0 seems to be the default address when no ethernet cables are connected to the PS3
strcpy_trunc(info->ip_address, "0.0.0.0");
}
free(pAdapterInfo);
@ -250,7 +262,7 @@ s32 cellNetCtlGetInfo(s32 code, vm::ptr<CellNetCtlInfo> info)
if (ret == ERROR_BUFFER_OVERFLOW)
{
cellNetCtl.Error("cellNetCtlGetInfo(INFO_NETMASK): GetAdaptersAddresses buffer overflow.");
cellNetCtl.Error("cellNetCtlGetInfo(INFO_NETMASK): GetAdaptersInfo buffer overflow.");
free(pAdapterInfo);
pAdapterInfo = (IP_ADAPTER_INFO*)malloc(bufLen);

View File

@ -276,16 +276,22 @@ namespace sys_net
return CELL_OK;
}
s32 inet_ntop()
vm::cptr<char> inet_ntop(s32 af, vm::ptr<void> src, vm::ptr<char> dst, u32 size)
{
UNIMPLEMENTED_FUNC(libnet);
return CELL_OK;
libnet.Warning("inet_ntop(af=%d, src=*0x%x, dst=*0x%x, size=%d)", af, src, dst, size);
const char* result = ::inet_ntop(af, src.get_ptr(), dst.get_ptr(), size);
if (result == nullptr)
{
return vm::null;
}
return dst;
}
s32 inet_pton(s32 af, vm::cptr<char> src, vm::ptr<char> dst)
{
libnet.Warning("inet_pton(af=%d, src=*0x%x, dst=*0x%x)", af, src, dst);
return ::inet_pton(af, src.get_ptr(), dst.get_ptr());
}