1
0
mirror of https://github.com/esp8266/Arduino.git synced 2025-04-21 10:26:06 +03:00

Implement remoteIP and remotePort in WiFiUDP

This commit is contained in:
Ivan Grokhotkov 2015-02-17 01:38:35 +03:00
parent ea90d3ce92
commit 71c705a187
3 changed files with 31 additions and 13 deletions

View File

@ -36,6 +36,7 @@ extern "C"
#include "lwip/udp.h" #include "lwip/udp.h"
#include "lwip/inet.h" #include "lwip/inet.h"
#include "lwip/igmp.h" #include "lwip/igmp.h"
#include "lwip/mem.h"
#include "include/UdpContext.h" #include "include/UdpContext.h"
/* Constructor */ /* Constructor */
@ -211,21 +212,17 @@ void WiFiUDP::flush()
IPAddress WiFiUDP::remoteIP() IPAddress WiFiUDP::remoteIP()
{ {
uint8_t _remoteIp[4] = {0}; if (!_ctx)
uint8_t _remotePort[2] = {0}; return IPAddress(0U);
// WiFiDrv::getRemoteData(_sock, _remoteIp, _remotePort); return IPAddress(_ctx->getRemoteAddress());
IPAddress ip(_remoteIp);
return ip;
} }
uint16_t WiFiUDP::remotePort() uint16_t WiFiUDP::remotePort()
{ {
uint8_t _remoteIp[4] = {0}; if (!_ctx)
uint8_t _remotePort[2] = {0}; return 0;
// WiFiDrv::getRemoteData(_sock, _remoteIp, _remotePort); return _ctx->getRemotePort();
uint16_t port = (_remotePort[0]<<8)+_remotePort[1];
return port;
} }

View File

@ -102,6 +102,24 @@ public:
return _rx_buf->len - _rx_buf_offset; return _rx_buf->len - _rx_buf_offset;
} }
uint32_t getRemoteAddress()
{
if (!_rx_buf)
return 0;
struct ip_hdr* iphdr = (struct ip_hdr*) (((uint8_t*)_rx_buf->payload) - UDP_HLEN - IP_HLEN);
return iphdr->src.addr;
}
uint16_t getRemotePort()
{
if (!_rx_buf)
return 0;
struct udp_hdr* udphdr = (struct udp_hdr*) (((uint8_t*)_rx_buf->payload) - UDP_HLEN);
return ntohs(udphdr->src);
}
bool next() bool next()
{ {
if (!_rx_buf) if (!_rx_buf)

View File

@ -39,6 +39,9 @@
#define __LWIPOPTS_H__ #define __LWIPOPTS_H__
#define EBUF_LWIP 1
#define LWIP_ESP 1
#define EP_OFFSET 36
/* /*
----------------------------------------------- -----------------------------------------------
---------- Platform specific locking ---------- ---------- Platform specific locking ----------
@ -242,7 +245,7 @@
* (requires the LWIP_TCP option) * (requires the LWIP_TCP option)
*/ */
#ifndef MEMP_NUM_TCP_PCB #ifndef MEMP_NUM_TCP_PCB
#define MEMP_NUM_TCP_PCB 5 #define MEMP_NUM_TCP_PCB (*((volatile uint32*)0x600011FC))
#endif #endif
/** /**