From dfac4eeba635e78ad6ac5a15437192e788ace612 Mon Sep 17 00:00:00 2001 From: Matthew Date: Thu, 16 Jan 2025 19:58:22 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A6=82=E6=9E=9CIP=E5=B7=B2=E7=BB=8F=E6=98=AF?= =?UTF-8?q?=E8=AE=BE=E7=BD=AE=E7=9A=84IP=EF=BC=8C=E5=88=99=E8=B7=B3?= =?UTF-8?q?=E8=BF=87?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/src/main/cpp/PhoneDevice.cpp | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/app/src/main/cpp/PhoneDevice.cpp b/app/src/main/cpp/PhoneDevice.cpp index 318df2ea..942f0d1a 100644 --- a/app/src/main/cpp/PhoneDevice.cpp +++ b/app/src/main/cpp/PhoneDevice.cpp @@ -4511,7 +4511,23 @@ void CPhoneDevice::SetStaticIp() { if (m_network != NULL) { - SetStaticIp(m_network->iface, m_network->ip, m_network->netmask, m_network->gateway); + unsigned int ip = 0; + unsigned int netMask = 0; + unsigned int gateway = 0; + std::string ipStr = m_network->ip; + if (GetNetInfo("eth0", ip, netMask, gateway)) + { + // const + sockaddr_in addrIn = { AF_INET, 0, ip}; + char buf[32] = { 0 }; + inet_ntop(AF_INET, &addrIn.sin_addr, buf, sizeof(buf));//其中recvAddr为SOCKADDR_IN类型 + if (strcmp(ipStr.c_str(), buf) == 0) + { + ipStr = "0.0.0.0"; + } + } + + SetStaticIp(m_network->iface, ipStr, m_network->netmask, m_network->gateway); XYLOG(XYLOG_SEVERITY_INFO, "Set Static IP on %s: %s", m_network->iface.c_str(), m_network->ip.c_str()); }