Skip to content

Commit 51b0814

Browse files
committed
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 <wangchen41@xiaomi.com>
1 parent 0045d8b commit 51b0814

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

netutils/dhcpc/dhcpc.c

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -817,11 +817,16 @@ int dhcpc_request(FAR void *handle, FAR struct dhcpc_state *presult)
817817
pdhcpc->serverid.s_addr = presult->serverid.s_addr;
818818

819819
/* Temporarily use the address offered by the server
820-
* and break out of the loop.
820+
* if it differs from the current address, then break
821+
* out of the loop.
821822
*/
822823

823-
netlib_set_ipv4addr(pdhcpc->interface,
824-
&presult->ipaddr);
824+
if (oldaddr.s_addr != presult->ipaddr.s_addr)
825+
{
826+
netlib_set_ipv4addr(pdhcpc->interface,
827+
&presult->ipaddr);
828+
}
829+
825830
state = STATE_HAVE_OFFER;
826831
}
827832
}

0 commit comments

Comments
 (0)