@@ -285,6 +285,12 @@ AsyncUDPPacket::AsyncUDPPacket(AsyncUDPPacket &packet){
285
285
_len = packet._len ;
286
286
_index = 0 ;
287
287
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
+
288
294
pbuf_ref (_pb);
289
295
}
290
296
@@ -304,18 +310,18 @@ AsyncUDPPacket::AsyncUDPPacket(AsyncUDP *udp, pbuf *pb, const ip_addr_t *raddr,
304
310
_localIp.type = _remoteIp.type ;
305
311
306
312
eth_hdr* eth = NULL ;
307
- udp_hdr* udphdr = reinterpret_cast < udp_hdr*> (_data - UDP_HLEN);
313
+ udp_hdr* udphdr = ( udp_hdr *) (_data - UDP_HLEN);
308
314
_localPort = ntohs (udphdr->dest );
309
315
_remotePort = ntohs (udphdr->src );
310
316
311
317
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);
314
320
_localIp.u_addr .ip4 .addr = iphdr->dest .addr ;
315
321
_remoteIp.u_addr .ip4 .addr = iphdr->src .addr ;
316
322
} 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);
319
325
memcpy (&_localIp.u_addr .ip6 .addr , (uint8_t *)ip6hdr->dest .addr , 16 );
320
326
memcpy (&_remoteIp.u_addr .ip6 .addr , (uint8_t *)ip6hdr->src .addr , 16 );
321
327
}
0 commit comments