Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 23f6e81

Browse filesBrowse files
committed
Fix AsyncUDP reporting bad address and port
Fixes: espressif#4923
1 parent e8311b0 commit 23f6e81
Copy full SHA for 23f6e81

File tree

Expand file treeCollapse file tree

1 file changed

+11
-5
lines changed
Filter options
Expand file treeCollapse file tree

1 file changed

+11
-5
lines changed

‎libraries/AsyncUDP/src/AsyncUDP.cpp

Copy file name to clipboardExpand all lines: libraries/AsyncUDP/src/AsyncUDP.cpp
+11-5Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -285,6 +285,12 @@ AsyncUDPPacket::AsyncUDPPacket(AsyncUDPPacket &packet){
285285
_len = packet._len;
286286
_index = 0;
287287

288+
memcpy(&_remoteIp, &packet._remoteIp, sizeof(ip_addr_t));
289+
memcpy(&_localIp, &packet._localIp, sizeof(ip_addr_t));
290+
_localPort = packet._localPort;
291+
_remotePort = packet._remotePort;
292+
memcpy(_remoteMac, packet._remoteMac, 6);
293+
288294
pbuf_ref(_pb);
289295
}
290296

@@ -304,18 +310,18 @@ AsyncUDPPacket::AsyncUDPPacket(AsyncUDP *udp, pbuf *pb, const ip_addr_t *raddr,
304310
_localIp.type = _remoteIp.type;
305311

306312
eth_hdr* eth = NULL;
307-
udp_hdr* udphdr = reinterpret_cast<udp_hdr*>(_data - UDP_HLEN);
313+
udp_hdr* udphdr = (udp_hdr *)(_data - UDP_HLEN);
308314
_localPort = ntohs(udphdr->dest);
309315
_remotePort = ntohs(udphdr->src);
310316

311317
if (_remoteIp.type == IPADDR_TYPE_V4) {
312-
eth = (eth_hdr *)(((uint8_t *)(pb->payload)) - UDP_HLEN - IP_HLEN - SIZEOF_ETH_HDR);
313-
struct ip_hdr * iphdr = (struct ip_hdr *)(((uint8_t *)(pb->payload)) - UDP_HLEN - IP_HLEN);
318+
eth = (eth_hdr *)(_data - UDP_HLEN - IP_HLEN - SIZEOF_ETH_HDR);
319+
struct ip_hdr * iphdr = (struct ip_hdr *)(_data - UDP_HLEN - IP_HLEN);
314320
_localIp.u_addr.ip4.addr = iphdr->dest.addr;
315321
_remoteIp.u_addr.ip4.addr = iphdr->src.addr;
316322
} else {
317-
eth = (eth_hdr *)(((uint8_t *)(pb->payload)) - UDP_HLEN - IP6_HLEN - SIZEOF_ETH_HDR);
318-
struct ip6_hdr * ip6hdr = (struct ip6_hdr *)(((uint8_t *)(pb->payload)) - UDP_HLEN - IP6_HLEN);
323+
eth = (eth_hdr *)(_data - UDP_HLEN - IP6_HLEN - SIZEOF_ETH_HDR);
324+
struct ip6_hdr * ip6hdr = (struct ip6_hdr *)(_data - UDP_HLEN - IP6_HLEN);
319325
memcpy(&_localIp.u_addr.ip6.addr, (uint8_t *)ip6hdr->dest.addr, 16);
320326
memcpy(&_remoteIp.u_addr.ip6.addr, (uint8_t *)ip6hdr->src.addr, 16);
321327
}

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.