mirror of
https://github.com/esp8266/Arduino.git
synced 2025-04-27 21:16:50 +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:
parent
727c61efe2
commit
5354464a01
@ -47,6 +47,7 @@ beginPacket KEYWORD2
|
|||||||
beginPacketMulticast KEYWORD2
|
beginPacketMulticast KEYWORD2
|
||||||
endPacket KEYWORD2
|
endPacket KEYWORD2
|
||||||
parsePacket KEYWORD2
|
parsePacket KEYWORD2
|
||||||
|
destinationIP KEYWORD2
|
||||||
remoteIP KEYWORD2
|
remoteIP KEYWORD2
|
||||||
remotePort KEYWORD2
|
remotePort KEYWORD2
|
||||||
softAP KEYWORD2
|
softAP KEYWORD2
|
||||||
|
@ -240,6 +240,17 @@ uint16_t WiFiUDP::remotePort()
|
|||||||
return _ctx->getRemotePort();
|
return _ctx->getRemotePort();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
IPAddress WiFiUDP::destinationIP()
|
||||||
|
{
|
||||||
|
IPAddress addr;
|
||||||
|
|
||||||
|
if (!_ctx)
|
||||||
|
return addr;
|
||||||
|
|
||||||
|
addr = _ctx->getDestAddress();
|
||||||
|
return addr;
|
||||||
|
}
|
||||||
|
|
||||||
uint16_t WiFiUDP::localPort()
|
uint16_t WiFiUDP::localPort()
|
||||||
{
|
{
|
||||||
if (!_ctx)
|
if (!_ctx)
|
||||||
|
@ -97,6 +97,9 @@ public:
|
|||||||
virtual IPAddress remoteIP();
|
virtual IPAddress remoteIP();
|
||||||
// Return the port of the host who sent the current incoming packet
|
// Return the port of the host who sent the current incoming packet
|
||||||
virtual uint16_t remotePort();
|
virtual uint16_t remotePort();
|
||||||
|
// Return the destination address for incoming packets,
|
||||||
|
// useful to distinguish multicast and ordinary packets
|
||||||
|
IPAddress destinationIP();
|
||||||
// Return the local port for outgoing packets
|
// Return the local port for outgoing packets
|
||||||
uint16_t localPort();
|
uint16_t localPort();
|
||||||
|
|
||||||
|
@ -26,7 +26,8 @@ class UdpContext;
|
|||||||
extern "C" void esp_yield();
|
extern "C" void esp_yield();
|
||||||
extern "C" void esp_schedule();
|
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
|
class UdpContext
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
@ -122,7 +123,7 @@ public:
|
|||||||
if (!_rx_buf)
|
if (!_rx_buf)
|
||||||
return 0;
|
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;
|
return iphdr->src.addr;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -131,10 +132,16 @@ public:
|
|||||||
if (!_rx_buf)
|
if (!_rx_buf)
|
||||||
return 0;
|
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);
|
return ntohs(udphdr->src);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
uint32_t getDestAddress()
|
||||||
|
{
|
||||||
|
ip_hdr* iphdr = GET_IP_HDR(_rx_buf);
|
||||||
|
return iphdr->dest.addr;
|
||||||
|
}
|
||||||
|
|
||||||
uint16_t getLocalPort()
|
uint16_t getLocalPort()
|
||||||
{
|
{
|
||||||
if (!_pcb)
|
if (!_pcb)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user