xiaoxiang781216 commented on code in PR #3451:
URL: https://github.com/apache/nuttx-apps/pull/3451#discussion_r3069736591


##########
include/netutils/dhcpc.h:
##########
@@ -55,6 +55,10 @@
 #  define CONFIG_NETDB_DNSSERVER_NAMESERVERS 1
 #endif
 
+#if !defined(CONFIG_NETUTILS_DHCPC_NTP_SERVER_NUM)
+#  define CONFIG_NETUTILS_DHCPC_NTP_SERVER_NUM 1

Review Comment:
   CONFIG_NETUTILS_DHCPC_NTP_SERVERS



##########
netutils/netlib/netlib_obtainipv4addr.c:
##########
@@ -105,6 +112,57 @@ static int dhcp_setup_result(FAR const char *ifname,
   return OK;
 }
 
+#ifdef CONFIG_NETUTILS_NTPCLIENT
+static int dhcp_set_ntp_servers(FAR const struct dhcpc_state *ds)
+{
+  char ntp_server_list[CONFIG_NETUTILS_DHCPC_NTP_SERVER_NUM *
+                       (INET_ADDRSTRLEN + 1)];
+  size_t offset = 0;
+  uint8_t i;
+
+  if (ds->num_ntpaddr == 0)
+    {
+      return ntpc_set_dhcp_servers(NULL);
+    }
+
+  ntp_server_list[0] = '\0';
+
+  for (i = 0; i < ds->num_ntpaddr; i++)
+    {
+      char addrbuf[INET_ADDRSTRLEN];
+      int ret;
+
+      if (ds->ntpaddr[i].s_addr == 0)
+        {
+          continue;
+        }
+
+      if (inet_ntop(AF_INET, &ds->ntpaddr[i], addrbuf, sizeof(addrbuf)) ==

Review Comment:
   why not pass ntpaddr array directly, but convert to string array



##########
netutils/ntpclient/ntpclient.c:
##########
@@ -126,18 +126,31 @@ enum ntpc_daemon_e
   NTP_STOPPED
 };
 
+enum ntpc_server_source_e
+{
+  NTP_SERVER_SOURCE_NONE = 0,
+  NTP_SERVER_SOURCE_CONFIG,
+  NTP_SERVER_SOURCE_DHCP,
+  NTP_SERVER_SOURCE_EXPLICIT
+};
+
 /* This type describes the state of the NTP client daemon.  Only one
  * instance of the NTP daemon is permitted in this implementation.
  */
 
 struct ntpc_daemon_s
 {
-  uint8_t state;       /* See enum ntpc_daemon_e */
-  sem_t lock;          /* Used to protect the whole structure */
-  sem_t sync;          /* Used to synchronize start and stop events */
-  pid_t pid;           /* Task ID of the NTP daemon */
-  sq_queue_t kod_list; /* KoD excluded server addresses */
-  int family;          /* Allowed address family */
+  uint8_t state;         /* See enum ntpc_daemon_e */
+  uint8_t source;        /* See enum ntpc_server_source_e */
+  sem_t lock;            /* Used to protect the whole structure */
+  sem_t sync;            /* Used to synchronize start and stop events */
+  pid_t pid;             /* Task ID of the NTP daemon */
+  sq_queue_t kod_list;   /* KoD excluded server addresses */

Review Comment:
   remove the extra spaces before `/*`



##########
netutils/netlib/netlib_obtainipv4addr.c:
##########
@@ -156,6 +214,18 @@ static int dhcp_obtain_statefuladdr(FAR const char *ifname)
   if (ret == OK)
     {
       ret = dhcp_setup_result(ifname, &ds);
+#ifdef CONFIG_NETUTILS_NTPCLIENT
+      if (ret == OK)
+        {
+          ret = dhcp_set_ntp_servers(&ds);

Review Comment:
   why not call ntpc_start_with_list directly



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to