summaryrefslogtreecommitdiff
path: root/shared-module/network
diff options
context:
space:
mode:
authorNick Moore <nick@zoic.org>2019-05-10 13:56:33 +1000
committerNick Moore <nick@zoic.org>2019-05-10 13:56:33 +1000
commit0d08dde62e79e293a56b3d64f4e73a25beb75d76 (patch)
treeb7546674cab93aab253818a7371447707981d432 /shared-module/network
parentaf0bba062275cd06577018e276ebe6c5ee0428ce (diff)
randomize tcp source port for adafruit/circuitpython#1800
Diffstat (limited to 'shared-module/network')
-rw-r--r--shared-module/network/__init__.c4
-rw-r--r--shared-module/network/__init__.h5
2 files changed, 7 insertions, 2 deletions
diff --git a/shared-module/network/__init__.c b/shared-module/network/__init__.c
index bf33fef7a..96648b260 100644
--- a/shared-module/network/__init__.c
+++ b/shared-module/network/__init__.c
@@ -99,3 +99,7 @@ void network_module_create_random_mac_address(uint8_t *mac) {
mac[4] = (uint8_t)(rb2 >> 8);
mac[5] = (uint8_t)(rb2);
}
+
+uint16_t network_module_create_random_source_tcp_port(void) {
+ return 0xc000 | shared_modules_random_getrandbits(14);
+}
diff --git a/shared-module/network/__init__.h b/shared-module/network/__init__.h
index 504065979..f4eb05bb5 100644
--- a/shared-module/network/__init__.h
+++ b/shared-module/network/__init__.h
@@ -25,11 +25,12 @@
* THE SOFTWARE.
*/
-void network_module_create_random_mac_address(uint8_t *mac);
-
#ifndef MICROPY_INCLUDED_SHARED_MODULE_NETWORK___INIT___H
#define MICROPY_INCLUDED_SHARED_MODULE_NETWORK___INIT___H
+void network_module_create_random_mac_address(uint8_t *mac);
+uint16_t network_module_create_random_source_tcp_port(void);
+
#define MOD_NETWORK_IPADDR_BUF_SIZE (4)
#define MOD_NETWORK_AF_INET (2)