Skip to content

Commit 61a6f5a

Browse files
committed
net: lwip: dhcp: set ntpserverip environment variable
Once the DHCP exchange is complete, if we have an IP address for an NTP server, set the ntpserverip environment variable accordingly. Although not necessary to make the sntp command use that server (since it is known internally to the lwIP stack), this makes the behavior in line with the legacy NET stack. This is also consistent with exporting the DNS servers etc. Signed-off-by: Jerome Forissier <[email protected]> Suggested-by: Michal Simek <[email protected]>
1 parent 57a6232 commit 61a6f5a

1 file changed

Lines changed: 6 additions & 0 deletions

File tree

net/lwip/dhcp.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ static int dhcp_loop(struct udevice *udev)
3333
char ipstr[] = "ipaddr\0\0";
3434
char maskstr[] = "netmask\0\0";
3535
char gwstr[] = "gatewayip\0\0";
36+
const ip_addr_t *ntpserverip;
3637
unsigned long start;
3738
struct netif *netif;
3839
struct dhcp *dhcp;
@@ -110,6 +111,11 @@ static int dhcp_loop(struct udevice *udev)
110111
strncpy(boot_file_name, dhcp->boot_file_name,
111112
sizeof(boot_file_name));
112113
#endif
114+
if (CONFIG_IS_ENABLED(CMD_SNTP)) {
115+
ntpserverip = sntp_getserver(1);
116+
if (ntpserverip != IP_ADDR_ANY)
117+
env_set("ntpserverip", ip4addr_ntoa(ntpserverip));
118+
}
113119

114120
printf("DHCP client bound to address %pI4 (%lu ms)\n",
115121
&dhcp->offered_ip_addr, get_timer(start));

0 commit comments

Comments
 (0)