1
0
mirror of https://github.com/esp8266/Arduino.git synced 2025-04-19 23:22:16 +03:00

Add remoteIP and remotePort methods to WiFiClient

This commit is contained in:
Ivan Grokhotkov 2015-01-16 17:56:11 +03:00
parent e40d18e107
commit b09e8e593a
3 changed files with 37 additions and 4 deletions

View File

@ -43,11 +43,10 @@ extern "C"
#define MIN_LOCAL_PORT 1024
#define MAX_LOCAL_PORT 1124
static int g_localPort = MIN_LOCAL_PORT;
static int g_localPort = MIN_LOCAL_PORT;
ICACHE_FLASH_ATTR WiFiClient::WiFiClient()
: _client(0)
, _lastPollTime(0)
{
}
@ -229,6 +228,22 @@ ICACHE_FLASH_ATTR WiFiClient::operator bool()
return _client != 0;
}
IPAddress WiFiClient::remoteIP()
{
if (!_client)
return IPAddress(0U);
return IPAddress(_client->getRemoteAddress());
}
uint16_t WiFiClient::remotePort()
{
if (!_client)
return 0;
return _client->getRemotePort();
}
int8_t ICACHE_FLASH_ATTR WiFiClient::_s_connected(void* arg, void* tpcb, int8_t err)
{
return reinterpret_cast<WiFiClient*>(arg)->_connected(tpcb, err);

View File

@ -53,6 +53,9 @@ public:
virtual uint8_t connected();
virtual operator bool();
IPAddress remoteIP();
uint16_t remotePort();
friend class WiFiServer;
using Print::write;
@ -66,8 +69,7 @@ private:
void _err(int8_t err);
ClientContext* _client;
uint32_t _lastPollTime;
};
#endif

View File

@ -88,6 +88,22 @@ public:
}
}
uint32_t getRemoteAddress()
{
if (!_pcb)
return 0;
return _pcb->remote_ip.addr;
}
uint16_t getRemotePort()
{
if (!_pcb)
return 0;
return _pcb->remote_port;
}
size_t getSize() const
{
if (!_rx_buf)