From 15a50db0a73b2d57f09520e1854a143dd0338f8f Mon Sep 17 00:00:00 2001 From: yuanyuanxiang <962914132@qq.com> Date: Tue, 20 Oct 2026 21:15:45 +0200 Subject: [PATCH] Fix: Keep IPv4 address bytes in network order for connection list iphlpapi stores the address in network byte order inside the memory of the DWORD, it is not a host-order integer. For 192.168.0.55 the DWORD value on x86 is 0x3700A8C0 while its bytes are C0 A8 00 37, so shifting the value by 24/16/8/0 produced 37 00 A8 C0 and the dialog rendered "55.0.168.192" for both the local and remote address. Copy the DWORD with memcpy instead, which preserves the memory layout that inet_ntop and SetTcpEntry both expect. GetAddr4 is changed the same way, otherwise a forced disconnect would rebuild a wrong address and miss the target connection. Co-Authored-By: deepseek-flash --- client/ConnectionsManager.cpp | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/client/ConnectionsManager.cpp b/client/ConnectionsManager.cpp index 1434c92..fb52c3d 100644 --- a/client/ConnectionsManager.cpp +++ b/client/ConnectionsManager.cpp @@ -60,19 +60,20 @@ static void ResolveProcName(DWORD pid, char* out, int outLen) out[outLen - 1] = 0; } -// IPv4 地址:iphlpapi 的 dwLocalAddr/dwRemoteAddr 是网络序 DWORD(值 0xC0A80101 即 192.168.1.1), -// 转成 16 字节字段前 4 字节的网络序字节后 inet_ntop 可直接展示、断连时再拼回 DWORD。 +// IPv4 地址:iphlpapi 的 dwLocalAddr/dwRemoteAddr 是把网络序地址直接放在 DWORD 的**内存**里, +// 不是主机序数值(192.168.0.55 在 x86 上 DWORD 数值是 0x3700A8C0、内存字节是 C0 A8 00 37)。 +// 所以只能按内存拷贝:这样得到的正是 inet_ntop 需要的网络序字节,也能原样拼回 SetTcpEntry 的 DWORD。 +// 按数值移位会把字节序弄反(显示成 55.0.168.192)。 static void PutAddr4(uint8_t* out, DWORD addrNet) { - out[0] = (uint8_t)(addrNet >> 24); - out[1] = (uint8_t)(addrNet >> 16); - out[2] = (uint8_t)(addrNet >> 8); - out[3] = (uint8_t)(addrNet); + memcpy(out, &addrNet, 4); } static DWORD GetAddr4(const uint8_t* addr) { - return ((DWORD)addr[0] << 24) | ((DWORD)addr[1] << 16) | ((DWORD)addr[2] << 8) | (DWORD)addr[3]; + DWORD addrNet = 0; + memcpy(&addrNet, addr, 4); + return addrNet; } static void AppendTcp4(std::vector& rows)