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
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); freeifaddrs(ifaddr);
#endif #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) 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 #ifdef _WIN32
ULONG bufLen = sizeof(IP_ADAPTER_INFO) + 1; ULONG bufLen = sizeof(IP_ADAPTER_INFO);
PIP_ADAPTER_INFO pAdapterInfo = (PIP_ADAPTER_INFO)malloc(bufLen); PIP_ADAPTER_INFO pAdapterInfo = (IP_ADAPTER_INFO*)malloc(bufLen);
DWORD ret; DWORD ret;
ret = GetAdaptersInfo(pAdapterInfo, &bufLen); ret = GetAdaptersInfo(pAdapterInfo, &bufLen);
if (ret == ERROR_BUFFER_OVERFLOW) if (ret == ERROR_BUFFER_OVERFLOW)
{ {
cellNetCtl.Error("cellNetCtlGetInfo(IP_ADDRESS): GetAdaptersAddresses buffer overflow."); cellNetCtl.Error("cellNetCtlGetInfo(IP_ADDRESS): GetAdaptersInfo buffer overflow.");
free(pAdapterInfo); free(pAdapterInfo);
pAdapterInfo = (IP_ADAPTER_INFO*)malloc(bufLen); pAdapterInfo = (IP_ADAPTER_INFO*)malloc(bufLen);
@ -202,8 +216,6 @@ s32 cellNetCtlGetInfo(s32 code, vm::ptr<CellNetCtlInfo> info)
else else
{ {
cellNetCtl.Error("cellNetCtlGetInfo(IP_ADDRESS): Call to GetAdaptersInfo failed. (%d)", ret); 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); free(pAdapterInfo);
@ -250,7 +262,7 @@ s32 cellNetCtlGetInfo(s32 code, vm::ptr<CellNetCtlInfo> info)
if (ret == ERROR_BUFFER_OVERFLOW) if (ret == ERROR_BUFFER_OVERFLOW)
{ {
cellNetCtl.Error("cellNetCtlGetInfo(INFO_NETMASK): GetAdaptersAddresses buffer overflow."); cellNetCtl.Error("cellNetCtlGetInfo(INFO_NETMASK): GetAdaptersInfo buffer overflow.");
free(pAdapterInfo); free(pAdapterInfo);
pAdapterInfo = (IP_ADAPTER_INFO*)malloc(bufLen); pAdapterInfo = (IP_ADAPTER_INFO*)malloc(bufLen);

View file

@ -276,16 +276,22 @@ namespace sys_net
return CELL_OK; 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); libnet.Warning("inet_ntop(af=%d, src=*0x%x, dst=*0x%x, size=%d)", af, src, dst, size);
return CELL_OK; 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) 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); 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()); return ::inet_pton(af, src.get_ptr(), dst.get_ptr());
} }