mirror of
https://github.com/dolphin-emu/dolphin.git
synced 2025-01-09 23:59:27 +01:00
make IOCTL_SO_GETHOSTID more accurate on Windows
This commit is contained in:
parent
36720e6822
commit
ce64885a66
@ -854,7 +854,55 @@ bool CWII_IPC_HLE_Device_net_ip_top::IOCtl(u32 _CommandAddress)
|
||||
INFO_LOG(WII_IPC_NET, "IOCTL_SO_GETHOSTID "
|
||||
"(BufferIn: (%08x, %i), BufferOut: (%08x, %i)",
|
||||
BufferIn, BufferInSize, BufferOut, BufferOutSize);
|
||||
// default placeholder, in case of failure
|
||||
ReturnValue = 192 << 24 | 168 << 16 | 1 << 8 | 150;
|
||||
|
||||
#ifdef _WIN32
|
||||
DWORD forwardTableSize, ipTableSize;
|
||||
PMIB_IPFORWARDTABLE forwardTable = (PMIB_IPFORWARDTABLE)malloc(sizeof(MIB_IPFORWARDTABLE));
|
||||
PMIB_IPADDRTABLE ipTable = (PMIB_IPADDRTABLE)malloc(sizeof(MIB_IPADDRTABLE));
|
||||
|
||||
forwardTableSize = sizeof(MIB_IPFORWARDTABLE);
|
||||
if (GetIpForwardTable(forwardTable, &forwardTableSize, 0) == ERROR_INSUFFICIENT_BUFFER)
|
||||
{
|
||||
free(forwardTable);
|
||||
forwardTable = (PMIB_IPFORWARDTABLE)malloc(forwardTableSize);
|
||||
}
|
||||
|
||||
ipTableSize = sizeof(MIB_IPADDRTABLE);
|
||||
if (GetIpAddrTable(ipTable, &ipTableSize, 0) == ERROR_INSUFFICIENT_BUFFER)
|
||||
{
|
||||
free(ipTable);
|
||||
ipTable = (PMIB_IPADDRTABLE)malloc(ipTableSize);
|
||||
}
|
||||
|
||||
// find the interface IP used for the default route and use that
|
||||
if (!GetIpForwardTable(forwardTable, &forwardTableSize, 0) && !GetIpAddrTable(ipTable, &ipTableSize, 0))
|
||||
{
|
||||
for (DWORD i = 0; i < forwardTable->dwNumEntries; i++)
|
||||
{
|
||||
MIB_IPFORWARDROW forwardRow = forwardTable->table[i];
|
||||
if (forwardRow.dwForwardDest == 0)
|
||||
{
|
||||
for (DWORD j = 0; j < ipTable->dwNumEntries; j++)
|
||||
{
|
||||
MIB_IPADDRROW ipRow = ipTable->table[j];
|
||||
if (ipRow.dwIndex == forwardRow.dwForwardIfIndex)
|
||||
{
|
||||
ReturnValue = Common::swap32(ipRow.dwAddr);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
free(forwardTable);
|
||||
free(ipTable);
|
||||
#endif
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user