Skip to content

Commit 49aeb79

Browse files
committed
Add API to set the beginning of local ports range for WiFiClient
1 parent 703cad3 commit 49aeb79

File tree

2 files changed

+8
-0
lines changed

2 files changed

+8
-0
lines changed

libraries/ESP8266WiFi/src/WiFiClient.cpp

+6
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,8 @@ extern "C"
4040
#include "include/ClientContext.h"
4141
#include "c_types.h"
4242

43+
uint16_t WiFiClient::_localPort = 0;
44+
4345
ICACHE_FLASH_ATTR WiFiClient::WiFiClient()
4446
: _client(0)
4547
{
@@ -93,6 +95,10 @@ int ICACHE_FLASH_ATTR WiFiClient::connect(IPAddress ip, uint16_t port)
9395
if (!pcb)
9496
return 0;
9597

98+
if (_localPort > 0) {
99+
pcb->local_port = _localPort++;
100+
}
101+
96102
ip_addr_t addr;
97103
addr.addr = ip;
98104
tcp_arg(pcb, this);

libraries/ESP8266WiFi/src/WiFiClient.h

+2
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ class WiFiClient : public Client {
6161
uint16_t remotePort();
6262
bool getNoDelay();
6363
void setNoDelay(bool nodelay);
64+
static void setLocalPortStart(uint16_t port) { _localPort = port; }
6465

6566
template<typename T> size_t write(T &src){
6667
uint8_t obuf[1460];
@@ -97,6 +98,7 @@ class WiFiClient : public Client {
9798
void _err(int8_t err);
9899

99100
ClientContext* _client;
101+
static uint16_t _localPort;
100102

101103
};
102104

0 commit comments

Comments
 (0)