From 51b0814ff2f1fa623be5f174e55dc200afe971c4 Mon Sep 17 00:00:00 2001 From: wangchen Date: Thu, 10 Jul 2025 19:19:53 +0800 Subject: [PATCH] dhcpc.c: Avoid setting IP to stack when oldaddr matches presult->ipaddr when processing DHCP offer messages in dhcp_dequest, netlib_set_ipv4addr is used to set the IP regardless of whether the IP has changed, resulting in disconnection between the two communication devices Signed-off-by: wangchen --- netutils/dhcpc/dhcpc.c | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/netutils/dhcpc/dhcpc.c b/netutils/dhcpc/dhcpc.c index dc6b46230b3..4c74fa2b0d9 100644 --- a/netutils/dhcpc/dhcpc.c +++ b/netutils/dhcpc/dhcpc.c @@ -817,11 +817,16 @@ int dhcpc_request(FAR void *handle, FAR struct dhcpc_state *presult) pdhcpc->serverid.s_addr = presult->serverid.s_addr; /* Temporarily use the address offered by the server - * and break out of the loop. + * if it differs from the current address, then break + * out of the loop. */ - netlib_set_ipv4addr(pdhcpc->interface, - &presult->ipaddr); + if (oldaddr.s_addr != presult->ipaddr.s_addr) + { + netlib_set_ipv4addr(pdhcpc->interface, + &presult->ipaddr); + } + state = STATE_HAVE_OFFER; } }