Skip to content

Commit

Permalink
feat: make lwip allocate a new local TCP port is random
Browse files Browse the repository at this point in the history
  • Loading branch information
cwespressif committed Dec 20, 2018
1 parent fc6c39e commit a66d130
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions components/lwip/lwip/src/core/tcp.c
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,10 @@

#include <string.h>

#if ESP_LWIP
#include "arch/sys_arch.h"
#endif

#ifdef LWIP_HOOK_FILENAME
#include LWIP_HOOK_FILENAME
#endif
Expand Down Expand Up @@ -847,9 +851,13 @@ tcp_new_port(void)
struct tcp_pcb *pcb;

again:
#if ESP_LWIP
tcp_port = (u16_t)(esp_random() % (TCP_LOCAL_PORT_RANGE_END - TCP_LOCAL_PORT_RANGE_START)) + TCP_LOCAL_PORT_RANGE_START;
#else
if (tcp_port++ == TCP_LOCAL_PORT_RANGE_END) {
tcp_port = TCP_LOCAL_PORT_RANGE_START;
}
#endif
/* Check all PCB lists. */
for (i = 0; i < NUM_TCP_PCB_LISTS; i++) {
for (pcb = *tcp_pcb_lists[i]; pcb != NULL; pcb = pcb->next) {
Expand Down

0 comments on commit a66d130

Please sign in to comment.