summaryrefslogtreecommitdiff
path: root/net
diff options
context:
space:
mode:
authorJerome Forissier <[email protected]>2025-09-22 11:35:43 +0200
committerJerome Forissier <[email protected]>2025-09-30 12:01:36 +0200
commit61a6f5ab99197c8b1233de0ac9861bcae3d9df05 (patch)
treeaba1319233b3931064f79c194da97fef42750adc /net
parent57a623230eaadc836c548a1e7effae34ec11eb0f (diff)
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]>
Diffstat (limited to 'net')
-rw-r--r--net/lwip/dhcp.c6
1 files changed, 6 insertions, 0 deletions
diff --git a/net/lwip/dhcp.c b/net/lwip/dhcp.c
index cbdfea3ba82..531bf2c6705 100644
--- a/net/lwip/dhcp.c
+++ b/net/lwip/dhcp.c
@@ -33,6 +33,7 @@ static int dhcp_loop(struct udevice *udev)
char ipstr[] = "ipaddr\0\0";
char maskstr[] = "netmask\0\0";
char gwstr[] = "gatewayip\0\0";
+ const ip_addr_t *ntpserverip;
unsigned long start;
struct netif *netif;
struct dhcp *dhcp;
@@ -110,6 +111,11 @@ static int dhcp_loop(struct udevice *udev)
strncpy(boot_file_name, dhcp->boot_file_name,
sizeof(boot_file_name));
#endif
+ if (CONFIG_IS_ENABLED(CMD_SNTP)) {
+ ntpserverip = sntp_getserver(1);
+ if (ntpserverip != IP_ADDR_ANY)
+ env_set("ntpserverip", ip4addr_ntoa(ntpserverip));
+ }
printf("DHCP client bound to address %pI4 (%lu ms)\n",
&dhcp->offered_ip_addr, get_timer(start));