diff --git a/Source/Core/Core/IPC_HLE/WII_IPC_HLE_Device_net.cpp b/Source/Core/Core/IPC_HLE/WII_IPC_HLE_Device_net.cpp index 6204248546..e3d6d31811 100644 --- a/Source/Core/Core/IPC_HLE/WII_IPC_HLE_Device_net.cpp +++ b/Source/Core/Core/IPC_HLE/WII_IPC_HLE_Device_net.cpp @@ -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; }