Skip to content

Commit a66d130

Browse files
committed
feat: make lwip allocate a new local TCP port is random
1 parent fc6c39e commit a66d130

File tree

1 file changed

+8
-0
lines changed
  • components/lwip/lwip/src/core

1 file changed

+8
-0
lines changed

components/lwip/lwip/src/core/tcp.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,10 @@
6262

6363
#include <string.h>
6464

65+
#if ESP_LWIP
66+
#include "arch/sys_arch.h"
67+
#endif
68+
6569
#ifdef LWIP_HOOK_FILENAME
6670
#include LWIP_HOOK_FILENAME
6771
#endif
@@ -847,9 +851,13 @@ tcp_new_port(void)
847851
struct tcp_pcb *pcb;
848852

849853
again:
854+
#if ESP_LWIP
855+
tcp_port = (u16_t)(esp_random() % (TCP_LOCAL_PORT_RANGE_END - TCP_LOCAL_PORT_RANGE_START)) + TCP_LOCAL_PORT_RANGE_START;
856+
#else
850857
if (tcp_port++ == TCP_LOCAL_PORT_RANGE_END) {
851858
tcp_port = TCP_LOCAL_PORT_RANGE_START;
852859
}
860+
#endif
853861
/* Check all PCB lists. */
854862
for (i = 0; i < NUM_TCP_PCB_LISTS; i++) {
855863
for (pcb = *tcp_pcb_lists[i]; pcb != NULL; pcb = pcb->next) {

0 commit comments

Comments
 (0)