You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@nuttx.apache.org by GitBox <gi...@apache.org> on 2020/05/15 12:55:53 UTC

[GitHub] [incubator-nuttx] patacongo commented on a change in pull request #1054: net/conn: generate port base dynamically

patacongo commented on a change in pull request #1054:
URL: https://github.com/apache/incubator-nuttx/pull/1054#discussion_r425781926



##########
File path: net/tcp/tcp_conn.c
##########
@@ -263,6 +260,20 @@ static FAR struct tcp_conn_s *
 static int tcp_selectport(uint8_t domain, FAR const union ip_addr_u *ipaddr,
                           uint16_t portno)
 {
+  static uint16_t g_last_tcp_port;
+
+  /* Generate port base dynamically */
+
+  if (g_last_tcp_port == 0)
+    {
+      g_last_tcp_port = clock_systime_ticks() % 32000;
+
+      if (g_last_tcp_port < 4096)
+        {
+          g_last_tcp_port += 4096;
+        }
+    }
+

Review comment:
       You still verify that this port number is unique, right?  With this change there is the real possibility that you could generate duplicate port numbers.  Logic must be included to avoid that.
   
   




----------------------------------------------------------------
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:
users@infra.apache.org