yamt commented on code in PR #10925:
URL: https://github.com/apache/nuttx/pull/10925#discussion_r1366500404


##########
net/tcp/tcp_conn.c:
##########
@@ -579,27 +579,26 @@ int tcp_selectport(uint8_t domain,
                    uint16_t portno)
 {
   static uint16_t g_last_tcp_port;
-  ssize_t ret;
 
   /* Generate port base dynamically */
 
   if (g_last_tcp_port == 0)
     {
-      ret = getrandom(&g_last_tcp_port, sizeof(uint16_t), 0);
+#if defined(CONFIG_DEV_URANDOM) || defined(CONFIG_DEV_RANDOM)
+      ssize_t ret = getrandom(&g_last_tcp_port, sizeof(uint16_t), 0);
       if (ret < 0)
         {
           ret = getrandom(&g_last_tcp_port, sizeof(uint16_t), GRND_RANDOM);
         }
 
       if (ret != sizeof(uint16_t))
+#endif
         {
-          g_last_tcp_port = clock_systime_ticks() % 32000;
-        }
-      else
-        {
-          g_last_tcp_port = g_last_tcp_port % 32000;
+          g_last_tcp_port = (uint16_t)clock_systime_ticks();
         }
 
+      g_last_tcp_port = g_last_tcp_port % 32000;

Review Comment:
   > Yes, they're different in distribution, but it's intentional because we 
only use it once per boot and don't need to use an exactly uniform distribution.
   
   still, it isn't a great idea to make it more predictable, is it?



-- 
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: commits-unsubscr...@nuttx.apache.org

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

Reply via email to