1
0
mirror of https://github.com/esp8266/Arduino.git synced 2025-07-26 07:02:15 +03:00

Add destinationIP method to WiFiUDP

Might be useful to distinguish between normal and multicast packets arriving at the same port (#105)
This commit is contained in:
Ivan Grokhotkov
2015-04-28 00:03:29 +08:00
parent 727c61efe2
commit 5354464a01
4 changed files with 25 additions and 3 deletions

View File

@ -26,7 +26,8 @@ class UdpContext;
extern "C" void esp_yield();
extern "C" void esp_schedule();
#define GET_IP_HDR(pb) reinterpret_cast<ip_hdr*>(((uint8_t*)((pb)->payload)) - UDP_HLEN - IP_HLEN);
#define GET_UDP_HDR(pb) reinterpret_cast<udp_hdr*>(((uint8_t*)((pb)->payload)) - UDP_HLEN);
class UdpContext
{
public:
@ -122,7 +123,7 @@ public:
if (!_rx_buf)
return 0;
struct ip_hdr* iphdr = (struct ip_hdr*) (((uint8_t*)_rx_buf->payload) - UDP_HLEN - IP_HLEN);
ip_hdr* iphdr = GET_IP_HDR(_rx_buf);
return iphdr->src.addr;
}
@ -131,10 +132,16 @@ public:
if (!_rx_buf)
return 0;
struct udp_hdr* udphdr = (struct udp_hdr*) (((uint8_t*)_rx_buf->payload) - UDP_HLEN);
udp_hdr* udphdr = GET_UDP_HDR(_rx_buf);
return ntohs(udphdr->src);
}
uint32_t getDestAddress()
{
ip_hdr* iphdr = GET_IP_HDR(_rx_buf);
return iphdr->dest.addr;
}
uint16_t getLocalPort()
{
if (!_pcb)