Skip to content

Commit

Permalink
fix #31
Browse files Browse the repository at this point in the history
  • Loading branch information
d-a-v committed Mar 22, 2019
1 parent 2f481dc commit 25d5e81
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
6 changes: 6 additions & 0 deletions glue-lwip/arduino/lwipopts.h
Original file line number Diff line number Diff line change
Expand Up @@ -3529,6 +3529,12 @@
#error LWIP_FEATURES must be defined
#endif


/**
* TCP_RANDOM_PORT: randomize port instead of simply increasing
*/
#define TCP_RANDOM_PORT 1

/*
--------------------------------------------------
------------------ SNTP options ------------------
Expand Down
19 changes: 19 additions & 0 deletions patches/tcp-random-port.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
diff --git a/src/core/tcp.c b/src/core/tcp.c
index bd7d64ec..402fbd19 100644
--- a/src/core/tcp.c
+++ b/src/core/tcp.c
@@ -1015,9 +1015,14 @@ tcp_new_port(void)
struct tcp_pcb *pcb;

again:
+#if TCP_RANDOM_PORT && defined(LWIP_RAND)
+ tcp_port = (u16_t)(LWIP_RAND() % (TCP_LOCAL_PORT_RANGE_END - TCP_LOCAL_PORT_RANGE_START))
+ + TCP_LOCAL_PORT_RANGE_START;
+#else
tcp_port++;
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++) {

0 comments on commit 25d5e81

Please sign in to comment.