Skip to content

Commit fe8c86a

Browse files
committed
LocalIP/LocalPort support
1 parent d6488f9 commit fe8c86a

File tree

3 files changed

+30
-0
lines changed

3 files changed

+30
-0
lines changed

hardware/esp8266com/esp8266/libraries/ESP8266WiFi/src/WiFiClient.cpp

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -263,6 +263,22 @@ uint16_t WiFiClient::remotePort()
263263
return _client->getRemotePort();
264264
}
265265

266+
IPAddress WiFiClient::localIP()
267+
{
268+
if (!_client)
269+
return IPAddress(0U);
270+
271+
return IPAddress(_client->getLocalAddress());
272+
}
273+
274+
uint16_t WiFiClient::localPort()
275+
{
276+
if (!_client)
277+
return 0;
278+
279+
return _client->getLocalPort();
280+
}
281+
266282
int8_t WiFiClient::_s_connected(void* arg, void* tpcb, int8_t err)
267283
{
268284
return reinterpret_cast<WiFiClient*>(arg)->_connected(tpcb, err);

hardware/esp8266com/esp8266/libraries/ESP8266WiFi/src/WiFiClient.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,8 @@ class WiFiClient : public Client, public SList<WiFiClient> {
6060

6161
IPAddress remoteIP();
6262
uint16_t remotePort();
63+
IPAddress localIP();
64+
uint16_t localPort();
6365
bool getNoDelay();
6466
void setNoDelay(bool nodelay);
6567
static void setLocalPortStart(uint16_t port) { _localPort = port; }

hardware/esp8266com/esp8266/libraries/ESP8266WiFi/src/include/ClientContext.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,18 @@ class ClientContext {
125125
return _pcb->remote_port;
126126
}
127127

128+
uint32_t getLocalAddress() {
129+
if(!_pcb) return 0;
130+
131+
return _pcb->local_ip.addr;
132+
}
133+
134+
uint16_t getLocalPort() {
135+
if(!_pcb) return 0;
136+
137+
return _pcb->local_port;
138+
}
139+
128140
size_t getSize() const {
129141
if(!_rx_buf) return 0;
130142

0 commit comments

Comments
 (0)