File tree 4 files changed +25
-3
lines changed
hardware/esp8266com/esp8266/libraries/ESP8266WiFi
4 files changed +25
-3
lines changed Original file line number Diff line number Diff line change @@ -47,6 +47,7 @@ beginPacket KEYWORD2
47
47
beginPacketMulticast KEYWORD2
48
48
endPacket KEYWORD2
49
49
parsePacket KEYWORD2
50
+ destinationIP KEYWORD2
50
51
remoteIP KEYWORD2
51
52
remotePort KEYWORD2
52
53
softAP KEYWORD2
Original file line number Diff line number Diff line change @@ -240,6 +240,17 @@ uint16_t WiFiUDP::remotePort()
240
240
return _ctx->getRemotePort ();
241
241
}
242
242
243
+ IPAddress WiFiUDP::destinationIP ()
244
+ {
245
+ IPAddress addr;
246
+
247
+ if (!_ctx)
248
+ return addr;
249
+
250
+ addr = _ctx->getDestAddress ();
251
+ return addr;
252
+ }
253
+
243
254
uint16_t WiFiUDP::localPort ()
244
255
{
245
256
if (!_ctx)
Original file line number Diff line number Diff line change @@ -97,6 +97,9 @@ class WiFiUDP : public UDP {
97
97
virtual IPAddress remoteIP ();
98
98
// Return the port of the host who sent the current incoming packet
99
99
virtual uint16_t remotePort ();
100
+ // Return the destination address for incoming packets,
101
+ // useful to distinguish multicast and ordinary packets
102
+ IPAddress destinationIP ();
100
103
// Return the local port for outgoing packets
101
104
uint16_t localPort ();
102
105
Original file line number Diff line number Diff line change @@ -26,7 +26,8 @@ class UdpContext;
26
26
extern " C" void esp_yield ();
27
27
extern " C" void esp_schedule ();
28
28
29
-
29
+ #define GET_IP_HDR (pb ) reinterpret_cast <ip_hdr*>(((uint8_t *)((pb)->payload)) - UDP_HLEN - IP_HLEN);
30
+ #define GET_UDP_HDR (pb ) reinterpret_cast <udp_hdr*>(((uint8_t *)((pb)->payload)) - UDP_HLEN);
30
31
class UdpContext
31
32
{
32
33
public:
@@ -122,7 +123,7 @@ class UdpContext
122
123
if (!_rx_buf)
123
124
return 0 ;
124
125
125
- struct ip_hdr * iphdr = ( struct ip_hdr *) ((( uint8_t *) _rx_buf-> payload ) - UDP_HLEN - IP_HLEN );
126
+ ip_hdr* iphdr = GET_IP_HDR ( _rx_buf);
126
127
return iphdr->src .addr ;
127
128
}
128
129
@@ -131,10 +132,16 @@ class UdpContext
131
132
if (!_rx_buf)
132
133
return 0 ;
133
134
134
- struct udp_hdr * udphdr = ( struct udp_hdr *) ((( uint8_t *) _rx_buf-> payload ) - UDP_HLEN );
135
+ udp_hdr* udphdr = GET_UDP_HDR ( _rx_buf);
135
136
return ntohs (udphdr->src );
136
137
}
137
138
139
+ uint32_t getDestAddress ()
140
+ {
141
+ ip_hdr* iphdr = GET_IP_HDR (_rx_buf);
142
+ return iphdr->dest .addr ;
143
+ }
144
+
138
145
uint16_t getLocalPort ()
139
146
{
140
147
if (!_pcb)
You can’t perform that action at this time.
0 commit comments