xiaoxiang781216 commented on a change in pull request #594:
URL: 
https://github.com/apache/incubator-nuttx-apps/pull/594#discussion_r578937658



##########
File path: netutils/ntpclient/ntpclient.c
##########
@@ -625,14 +699,15 @@ static void ntpc_settime(int64_t offset, FAR struct 
timespec *start_realtime,
  *
  ****************************************************************************/
 
-static bool ntp_address_in_kod_list(FAR const union ntp_addr_u *server_addr)
+static bool ntp_address_in_kod_list(FAR const struct sockaddr *server_addr)

Review comment:
       Why? here is sockaddr_cmp with ntp_addr_u:
   ```
   static int sockaddr_cmp(FAR const union ntp_addr_u*sa1,
                           FAR const union ntp_addr_u*sa2)
   {
     if (sa1->sa.sa_family != sa2->sa.sa_family)
       {
         return 1;
       }
   
     switch (sa1->sa.sa_family)
       {
   #ifdef CONFIG_NET_IPv4
       case AF_INET:
         {
           FAR const struct sockaddr_in *sin1 = &sa1->in4;
           FAR const struct sockaddr_in *sin2 = &sa2->in4;
   
           if (sin1->sin_addr.s_addr != sin2->sin_addr.s_addr)
             {
               return 1;
             }
   
           if (sin1->sin_port != sin2->sin_port)
             {
               return 1;
             }
   
           break;
         }
   #endif
   
   #ifdef CONFIG_NET_IPv6
       case AF_INET6:
         {
           FAR const struct sockaddr_in6 *sin1 = &sa1->in6;
           FAR const struct sockaddr_in6 *sin2 = &sa2->in6;
   
           if (!memcmp(sin1->sin6_addr.s6_addr,
                       sin2->sin6_addr.s6_addr, 16))
             {
               return 1;
             }
   
           if (sin1->sin6_port != sin2->sin6_port)
             {
               return 1;
             }
   
           break;
         }
   #endif
   
       default:
         DEBUGASSERT(0);
         break;
       }
   
     return 0
   }
   ```
   No much different compared with sockaddr version(actually, both have the 
same number of line). But, we avoid the cast both in the implementation and the 
caller. The cast break c strong type system,  we should avoid it as much as 
possible by the good desgin.




----------------------------------------------------------------
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.

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


Reply via email to