@@ -328,25 +328,36 @@ AsyncUDPPacket::AsyncUDPPacket(AsyncUDP *udp, pbuf *pb, const ip_addr_t *raddr,
328
328
pbuf_ref (_pb);
329
329
330
330
// memcpy(&_remoteIp, raddr, sizeof(ip_addr_t));
331
+ #if CONFIG_LWIP_IPV6
331
332
_remoteIp.type = raddr->type ;
332
333
_localIp.type = _remoteIp.type ;
334
+ #endif
333
335
334
336
eth_hdr *eth = NULL ;
335
337
udp_hdr *udphdr = (udp_hdr *)(_data - UDP_HLEN);
336
338
_localPort = ntohs (udphdr->dest );
337
339
_remotePort = ntohs (udphdr->src );
338
340
341
+ #if CONFIG_LWIP_IPV6
339
342
if (_remoteIp.type == IPADDR_TYPE_V4) {
343
+ #endif
340
344
eth = (eth_hdr *)(_data - UDP_HLEN - IP_HLEN - SIZEOF_ETH_HDR);
341
345
struct ip_hdr *iphdr = (struct ip_hdr *)(_data - UDP_HLEN - IP_HLEN);
346
+ #if CONFIG_LWIP_IPV6
342
347
_localIp.u_addr .ip4 .addr = iphdr->dest .addr ;
343
348
_remoteIp.u_addr .ip4 .addr = iphdr->src .addr ;
349
+ #else
350
+ _localIp.addr = iphdr->dest .addr ;
351
+ _remoteIp.addr = iphdr->src .addr ;
352
+ #endif
353
+ #if CONFIG_LWIP_IPV6
344
354
} else {
345
355
eth = (eth_hdr *)(_data - UDP_HLEN - IP6_HLEN - SIZEOF_ETH_HDR);
346
356
struct ip6_hdr *ip6hdr = (struct ip6_hdr *)(_data - UDP_HLEN - IP6_HLEN);
347
357
memcpy (&_localIp.u_addr .ip6 .addr , (uint8_t *)ip6hdr->dest .addr , 16 );
348
358
memcpy (&_remoteIp.u_addr .ip6 .addr , (uint8_t *)ip6hdr->src .addr , 16 );
349
359
}
360
+ #endif
350
361
memcpy (_remoteMac, eth->src .addr , 6 );
351
362
352
363
struct netif *netif = NULL ;
@@ -413,36 +424,48 @@ tcpip_adapter_if_t AsyncUDPPacket::interface() {
413
424
}
414
425
415
426
IPAddress AsyncUDPPacket::localIP () {
427
+ #if CONFIG_LWIP_IPV6
416
428
if (_localIp.type != IPADDR_TYPE_V4) {
417
429
return IPAddress ();
418
430
}
419
431
return IPAddress (_localIp.u_addr .ip4 .addr );
432
+ #else
433
+ return IPAddress (_localIp.addr );
434
+ #endif
420
435
}
421
436
437
+ #if CONFIG_LWIP_IPV6
422
438
IPAddress AsyncUDPPacket::localIPv6 () {
423
439
if (_localIp.type != IPADDR_TYPE_V6) {
424
440
return IPAddress (IPv6);
425
441
}
426
442
return IPAddress (IPv6, (const uint8_t *)_localIp.u_addr .ip6 .addr , _localIp.u_addr .ip6 .zone );
427
443
}
444
+ #endif
428
445
429
446
uint16_t AsyncUDPPacket::localPort () {
430
447
return _localPort;
431
448
}
432
449
433
450
IPAddress AsyncUDPPacket::remoteIP () {
451
+ #if CONFIG_LWIP_IPV6
434
452
if (_remoteIp.type != IPADDR_TYPE_V4) {
435
453
return IPAddress ();
436
454
}
437
455
return IPAddress (_remoteIp.u_addr .ip4 .addr );
456
+ #else
457
+ return IPAddress (_remoteIp.addr );
458
+ #endif
438
459
}
439
460
461
+ #if CONFIG_LWIP_IPV6
440
462
IPAddress AsyncUDPPacket::remoteIPv6 () {
441
463
if (_remoteIp.type != IPADDR_TYPE_V6) {
442
464
return IPAddress (IPv6);
443
465
}
444
466
return IPAddress (IPv6, (const uint8_t *)_remoteIp.u_addr .ip6 .addr , _remoteIp.u_addr .ip6 .zone );
445
467
}
468
+ #endif
446
469
447
470
uint16_t AsyncUDPPacket::remotePort () {
448
471
return _remotePort;
@@ -453,14 +476,22 @@ void AsyncUDPPacket::remoteMac(uint8_t *mac) {
453
476
}
454
477
455
478
bool AsyncUDPPacket::isIPv6 () {
479
+ #if CONFIG_LWIP_IPV6
456
480
return _localIp.type == IPADDR_TYPE_V6;
481
+ #else
482
+ return false ;
483
+ #endif
457
484
}
458
485
459
486
bool AsyncUDPPacket::isBroadcast () {
487
+ #if CONFIG_LWIP_IPV6
460
488
if (_localIp.type == IPADDR_TYPE_V6) {
461
489
return false ;
462
490
}
463
491
uint32_t ip = _localIp.u_addr .ip4 .addr ;
492
+ #else
493
+ uint32_t ip = _localIp.addr ;
494
+ #endif
464
495
return ip == 0xFFFFFFFF || ip == 0 || (ip & 0xFF000000 ) == 0xFF000000 ;
465
496
}
466
497
@@ -571,6 +602,7 @@ static esp_err_t joinMulticastGroup(const ip_addr_t *addr, bool join, tcpip_adap
571
602
}
572
603
netif = (struct netif *)nif;
573
604
605
+ #if CONFIG_LWIP_IPV6
574
606
if (addr->type == IPADDR_TYPE_V4) {
575
607
if (join) {
576
608
if (igmp_joingroup_netif (netif, (const ip4_addr *)&(addr->u_addr .ip4 ))) {
@@ -592,7 +624,19 @@ static esp_err_t joinMulticastGroup(const ip_addr_t *addr, bool join, tcpip_adap
592
624
}
593
625
}
594
626
}
627
+ #else
628
+ if (join) {
629
+ if (igmp_joingroup_netif (netif, (const ip4_addr *)(addr))) {
630
+ return ESP_ERR_INVALID_STATE;
631
+ }
632
+ } else {
633
+ if (igmp_leavegroup_netif (netif, (const ip4_addr *)(addr))) {
634
+ return ESP_ERR_INVALID_STATE;
635
+ }
636
+ }
637
+ #endif
595
638
} else {
639
+ #if CONFIG_LWIP_IPV6
596
640
if (addr->type == IPADDR_TYPE_V4) {
597
641
if (join) {
598
642
if (igmp_joingroup ((const ip4_addr *)IP4_ADDR_ANY, (const ip4_addr *)&(addr->u_addr .ip4 ))) {
@@ -614,6 +658,17 @@ static esp_err_t joinMulticastGroup(const ip_addr_t *addr, bool join, tcpip_adap
614
658
}
615
659
}
616
660
}
661
+ #else
662
+ if (join) {
663
+ if (igmp_joingroup ((const ip4_addr *)IP4_ADDR_ANY, (const ip4_addr *)(addr))) {
664
+ return ESP_ERR_INVALID_STATE;
665
+ }
666
+ } else {
667
+ if (igmp_leavegroup ((const ip4_addr *)IP4_ADDR_ANY, (const ip4_addr *)(addr))) {
668
+ return ESP_ERR_INVALID_STATE;
669
+ }
670
+ }
671
+ #endif
617
672
}
618
673
return ESP_OK;
619
674
}
@@ -722,18 +777,24 @@ size_t AsyncUDP::writeTo(const uint8_t *data, size_t len, const IPAddress addr,
722
777
}
723
778
724
779
IPAddress AsyncUDP::listenIP () {
780
+ #if CONFIG_LWIP_IPV6
725
781
if (!_pcb || _pcb->remote_ip .type != IPADDR_TYPE_V4) {
726
782
return IPAddress ();
727
783
}
728
784
return IPAddress (_pcb->remote_ip .u_addr .ip4 .addr );
785
+ #else
786
+ return IPAddress (_pcb->remote_ip .addr );
787
+ #endif
729
788
}
730
789
790
+ #if CONFIG_LWIP_IPV6
731
791
IPAddress AsyncUDP::listenIPv6 () {
732
792
if (!_pcb || _pcb->remote_ip .type != IPADDR_TYPE_V6) {
733
793
return IPAddress (IPv6);
734
794
}
735
795
return IPAddress (IPv6, (const uint8_t *)_pcb->remote_ip .u_addr .ip6 .addr , _pcb->remote_ip .u_addr .ip6 .zone );
736
796
}
797
+ #endif
737
798
738
799
size_t AsyncUDP::write (const uint8_t *data, size_t len) {
739
800
return writeTo (data, len, &(_pcb->remote_ip ), _pcb->remote_port );
0 commit comments