This is an automated email from the ASF dual-hosted git repository.

xiaoxiang781216 pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/nuttx-apps.git

commit d6b269eeab9cfebc10988459803a458c46c1a580
Author: Marco Casaroli <[email protected]>
AuthorDate: Fri Oct 23 10:51:03 2026 +0200

    netutils/dhcpc, netutils/ping: Convert clock() values with CLOCK2MSEC().
    
    dhcpc and ping converted a difference of clock() values with TICK2MSEC()
    and TICK2USEC(): they took clock() as a number of system ticks.  clock()
    counts in CLOCKS_PER_SEC units, which is the tick rate in NuttX today.
    
    Use CLOCK2MSEC() and CLOCK2USEC() of <nuttx/clock.h>, which convert a
    value in CLOCKS_PER_SEC units.  The results do not change while
    CLOCKS_PER_SEC is the tick rate, and stay correct if CLOCKS_PER_SEC
    changes.
    
    Assisted-by: Claude Code:claude-opus-5-5
    Signed-off-by: Marco Casaroli <[email protected]>
---
 netutils/dhcpc/dhcpc.c      | 4 ++--
 netutils/ping/icmp_ping.c   | 6 +++---
 netutils/ping/icmpv6_ping.c | 6 +++---
 3 files changed, 8 insertions(+), 8 deletions(-)

diff --git a/netutils/dhcpc/dhcpc.c b/netutils/dhcpc/dhcpc.c
index c882e213d..7d3026412 100644
--- a/netutils/dhcpc/dhcpc.c
+++ b/netutils/dhcpc/dhcpc.c
@@ -899,7 +899,7 @@ int dhcpc_request(FAR void *handle, FAR struct dhcpc_state 
*presult)
               return ERROR;
             }
         }
-      while (state == STATE_INITIAL && TICK2MSEC(clock() - start) <
+      while (state == STATE_INITIAL && CLOCK2MSEC(clock() - start) <
              CONFIG_NETUTILS_DHCPC_RECV_TIMEOUT_MS);
     }
   while (state == STATE_INITIAL &&
@@ -1015,7 +1015,7 @@ int dhcpc_request(FAR void *handle, FAR struct 
dhcpc_state *presult)
               return ERROR;
             }
         }
-      while (state == STATE_HAVE_OFFER && TICK2MSEC(clock() - start) <
+      while (state == STATE_HAVE_OFFER && CLOCK2MSEC(clock() - start) <
              CONFIG_NETUTILS_DHCPC_RECV_TIMEOUT_MS);
     }
   while (state == STATE_HAVE_OFFER &&
diff --git a/netutils/ping/icmp_ping.c b/netutils/ping/icmp_ping.c
index 0091d9037..1c89dabf0 100644
--- a/netutils/ping/icmp_ping.c
+++ b/netutils/ping/icmp_ping.c
@@ -398,7 +398,7 @@ void icmp_ping(FAR const struct ping_info_s *info)
 
           /* Skip IP header, IP header length including options */
 
-          priv->elapsed = TICK2USEC(clock() - priv->start);
+          priv->elapsed = CLOCK2USEC(clock() - priv->start);
           inhdr         = (FAR struct icmp_hdr_s *)
                           (iobuffer + sizeof(struct ipv4_hdr_s));
 
@@ -478,7 +478,7 @@ void icmp_ping(FAR const struct ping_info_s *info)
       /* Wait if necessary to preserved the requested ping rate */
 
 wait:
-      priv->elapsed = TICK2MSEC(clock() - priv->start);
+      priv->elapsed = CLOCK2MSEC(clock() - priv->start);
       if (priv->elapsed < info->delay)
         {
           struct timespec rqt;
@@ -499,7 +499,7 @@ wait:
       priv->outhdr.seqno = htons(++result.seqno);
     }
 
-  icmp_callback(&result, ICMP_I_FINISH, TICK2USEC(clock() - priv->kickoff));
+  icmp_callback(&result, ICMP_I_FINISH, CLOCK2USEC(clock() - priv->kickoff));
   close(priv->sockfd);
   free(priv);
 }
diff --git a/netutils/ping/icmpv6_ping.c b/netutils/ping/icmpv6_ping.c
index c62c329d6..bf1e4982e 100644
--- a/netutils/ping/icmpv6_ping.c
+++ b/netutils/ping/icmpv6_ping.c
@@ -341,7 +341,7 @@ void icmp6_ping(FAR const struct ping6_info_s *info)
               goto done;
             }
 
-          elapsed = TICK2USEC(clock() - start);
+          elapsed = CLOCK2USEC(clock() - start);
           inhdr   = (FAR struct icmpv6_echo_reply_s *)iobuffer;
 
           if (inhdr->type == ICMPv6_ECHO_REPLY)
@@ -419,7 +419,7 @@ void icmp6_ping(FAR const struct ping6_info_s *info)
 
       /* Wait if necessary to preserved the requested ping rate */
 
-      elapsed = TICK2MSEC(clock() - start);
+      elapsed = CLOCK2MSEC(clock() - start);
       if (elapsed < info->delay)
         {
           struct timespec rqt;
@@ -441,7 +441,7 @@ void icmp6_ping(FAR const struct ping6_info_s *info)
     }
 
 done:
-  icmp6_callback(&result, ICMPv6_I_FINISH, TICK2USEC(clock() - kickoff));
+  icmp6_callback(&result, ICMPv6_I_FINISH, CLOCK2USEC(clock() - kickoff));
   close(sockfd);
   free(iobuffer);
 }

Reply via email to