1
0
mirror of https://github.com/esp8266/Arduino.git synced 2025-04-25 20:02:37 +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/inet.h"
#include "lwip/igmp.h"
#include "lwip/mem.h"
#include "include/UdpContext.h"
/* Constructor */
@ -209,23 +210,19 @@ void WiFiUDP::flush()
_ctx->flush();
}
IPAddress WiFiUDP::remoteIP()
IPAddress WiFiUDP::remoteIP()
{
uint8_t _remoteIp[4] = {0};
uint8_t _remotePort[2] = {0};
if (!_ctx)
return IPAddress(0U);
// WiFiDrv::getRemoteData(_sock, _remoteIp, _remotePort);
IPAddress ip(_remoteIp);
return ip;
return IPAddress(_ctx->getRemoteAddress());
}
uint16_t WiFiUDP::remotePort()
uint16_t WiFiUDP::remotePort()
{
uint8_t _remoteIp[4] = {0};
uint8_t _remotePort[2] = {0};
if (!_ctx)
return 0;
// WiFiDrv::getRemoteData(_sock, _remoteIp, _remotePort);
uint16_t port = (_remotePort[0]<<8)+_remotePort[1];
return port;
return _ctx->getRemotePort();
}

View File

@ -102,6 +102,24 @@ public:
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()
{
if (!_rx_buf)

View File

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