Skip to content

Commit f8d9ffb

Browse files
me-no-devpre-commit-ci-lite[bot]
andauthoredNov 12, 2024··
fix(net): Allow to compile without IPv6 enabled (#10582)
* fix(net): Allow to compile without IPv6 enabled cc: @Jason2866 * ci(pre-commit): Apply automatic fixes --------- Co-authored-by: pre-commit-ci-lite[bot] <117423508+pre-commit-ci-lite[bot]@users.noreply.github.com>
1 parent d561685 commit f8d9ffb

27 files changed

+192
-5
lines changed
 

‎cores/esp32/IPAddress.cpp

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,10 @@
2222
#include "lwip/netif.h"
2323
#include "StreamString.h"
2424

25+
#ifndef CONFIG_LWIP_IPV6
26+
#define IP6_NO_ZONE 0
27+
#endif
28+
2529
IPAddress::IPAddress() : IPAddress(IPv4) {}
2630

2731
IPAddress::IPAddress(IPType ip_type) {
@@ -387,6 +391,7 @@ IPAddress::IPAddress(const ip_addr_t *addr) {
387391
}
388392

389393
void IPAddress::to_ip_addr_t(ip_addr_t *addr) const {
394+
#if CONFIG_LWIP_IPV6
390395
if (_type == IPv6) {
391396
addr->type = IPADDR_TYPE_V6;
392397
addr->u_addr.ip6.addr[0] = _address.dword[0];
@@ -400,9 +405,13 @@ void IPAddress::to_ip_addr_t(ip_addr_t *addr) const {
400405
addr->type = IPADDR_TYPE_V4;
401406
addr->u_addr.ip4.addr = _address.dword[IPADDRESS_V4_DWORD_INDEX];
402407
}
408+
#else
409+
addr->addr = _address.dword[IPADDRESS_V4_DWORD_INDEX];
410+
#endif
403411
}
404412

405413
IPAddress &IPAddress::from_ip_addr_t(const ip_addr_t *addr) {
414+
#if CONFIG_LWIP_IPV6
406415
if (addr->type == IPADDR_TYPE_V6) {
407416
_type = IPv6;
408417
_address.dword[0] = addr->u_addr.ip6.addr[0];
@@ -413,13 +422,21 @@ IPAddress &IPAddress::from_ip_addr_t(const ip_addr_t *addr) {
413422
_zone = addr->u_addr.ip6.zone;
414423
#endif /* LWIP_IPV6_SCOPES */
415424
} else {
425+
#endif
416426
_type = IPv4;
417427
memset(_address.bytes, 0, sizeof(_address.bytes));
428+
#if CONFIG_LWIP_IPV6
418429
_address.dword[IPADDRESS_V4_DWORD_INDEX] = addr->u_addr.ip4.addr;
430+
#else
431+
_address.dword[IPADDRESS_V4_DWORD_INDEX] = addr->addr;
432+
#endif
433+
#if CONFIG_LWIP_IPV6
419434
}
435+
#endif
420436
return *this;
421437
}
422438

439+
#if CONFIG_LWIP_IPV6
423440
esp_ip6_addr_type_t IPAddress::addr_type() const {
424441
if (_type != IPv6) {
425442
return ESP_IP6_ADDR_IS_UNKNOWN;
@@ -428,6 +445,9 @@ esp_ip6_addr_type_t IPAddress::addr_type() const {
428445
to_ip_addr_t(&addr);
429446
return esp_netif_ip6_get_addr_type((esp_ip6_addr_t *)(&(addr.u_addr.ip6)));
430447
}
448+
#endif
431449

450+
#if CONFIG_LWIP_IPV6
432451
const IPAddress IN6ADDR_ANY(IPv6);
452+
#endif
433453
const IPAddress INADDR_NONE(0, 0, 0, 0);

‎cores/esp32/IPAddress.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
#include "WString.h"
2525
#include "lwip/ip_addr.h"
2626
#include "esp_netif_ip_addr.h"
27+
#include "sdkconfig.h"
2728

2829
#define IPADDRESS_V4_BYTES_INDEX 12
2930
#define IPADDRESS_V4_DWORD_INDEX 3
@@ -115,7 +116,9 @@ class IPAddress : public Printable {
115116
IPAddress(const ip_addr_t *addr);
116117
void to_ip_addr_t(ip_addr_t *addr) const;
117118
IPAddress &from_ip_addr_t(const ip_addr_t *addr);
119+
#if CONFIG_LWIP_IPV6
118120
esp_ip6_addr_type_t addr_type() const;
121+
#endif
119122
uint8_t zone() const {
120123
return (type() == IPv6) ? _zone : 0;
121124
}

‎libraries/AsyncUDP/src/AsyncUDP.cpp

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -328,25 +328,36 @@ AsyncUDPPacket::AsyncUDPPacket(AsyncUDP *udp, pbuf *pb, const ip_addr_t *raddr,
328328
pbuf_ref(_pb);
329329

330330
//memcpy(&_remoteIp, raddr, sizeof(ip_addr_t));
331+
#if CONFIG_LWIP_IPV6
331332
_remoteIp.type = raddr->type;
332333
_localIp.type = _remoteIp.type;
334+
#endif
333335

334336
eth_hdr *eth = NULL;
335337
udp_hdr *udphdr = (udp_hdr *)(_data - UDP_HLEN);
336338
_localPort = ntohs(udphdr->dest);
337339
_remotePort = ntohs(udphdr->src);
338340

341+
#if CONFIG_LWIP_IPV6
339342
if (_remoteIp.type == IPADDR_TYPE_V4) {
343+
#endif
340344
eth = (eth_hdr *)(_data - UDP_HLEN - IP_HLEN - SIZEOF_ETH_HDR);
341345
struct ip_hdr *iphdr = (struct ip_hdr *)(_data - UDP_HLEN - IP_HLEN);
346+
#if CONFIG_LWIP_IPV6
342347
_localIp.u_addr.ip4.addr = iphdr->dest.addr;
343348
_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
344354
} else {
345355
eth = (eth_hdr *)(_data - UDP_HLEN - IP6_HLEN - SIZEOF_ETH_HDR);
346356
struct ip6_hdr *ip6hdr = (struct ip6_hdr *)(_data - UDP_HLEN - IP6_HLEN);
347357
memcpy(&_localIp.u_addr.ip6.addr, (uint8_t *)ip6hdr->dest.addr, 16);
348358
memcpy(&_remoteIp.u_addr.ip6.addr, (uint8_t *)ip6hdr->src.addr, 16);
349359
}
360+
#endif
350361
memcpy(_remoteMac, eth->src.addr, 6);
351362

352363
struct netif *netif = NULL;
@@ -413,36 +424,48 @@ tcpip_adapter_if_t AsyncUDPPacket::interface() {
413424
}
414425

415426
IPAddress AsyncUDPPacket::localIP() {
427+
#if CONFIG_LWIP_IPV6
416428
if (_localIp.type != IPADDR_TYPE_V4) {
417429
return IPAddress();
418430
}
419431
return IPAddress(_localIp.u_addr.ip4.addr);
432+
#else
433+
return IPAddress(_localIp.addr);
434+
#endif
420435
}
421436

437+
#if CONFIG_LWIP_IPV6
422438
IPAddress AsyncUDPPacket::localIPv6() {
423439
if (_localIp.type != IPADDR_TYPE_V6) {
424440
return IPAddress(IPv6);
425441
}
426442
return IPAddress(IPv6, (const uint8_t *)_localIp.u_addr.ip6.addr, _localIp.u_addr.ip6.zone);
427443
}
444+
#endif
428445

429446
uint16_t AsyncUDPPacket::localPort() {
430447
return _localPort;
431448
}
432449

433450
IPAddress AsyncUDPPacket::remoteIP() {
451+
#if CONFIG_LWIP_IPV6
434452
if (_remoteIp.type != IPADDR_TYPE_V4) {
435453
return IPAddress();
436454
}
437455
return IPAddress(_remoteIp.u_addr.ip4.addr);
456+
#else
457+
return IPAddress(_remoteIp.addr);
458+
#endif
438459
}
439460

461+
#if CONFIG_LWIP_IPV6
440462
IPAddress AsyncUDPPacket::remoteIPv6() {
441463
if (_remoteIp.type != IPADDR_TYPE_V6) {
442464
return IPAddress(IPv6);
443465
}
444466
return IPAddress(IPv6, (const uint8_t *)_remoteIp.u_addr.ip6.addr, _remoteIp.u_addr.ip6.zone);
445467
}
468+
#endif
446469

447470
uint16_t AsyncUDPPacket::remotePort() {
448471
return _remotePort;
@@ -453,14 +476,22 @@ void AsyncUDPPacket::remoteMac(uint8_t *mac) {
453476
}
454477

455478
bool AsyncUDPPacket::isIPv6() {
479+
#if CONFIG_LWIP_IPV6
456480
return _localIp.type == IPADDR_TYPE_V6;
481+
#else
482+
return false;
483+
#endif
457484
}
458485

459486
bool AsyncUDPPacket::isBroadcast() {
487+
#if CONFIG_LWIP_IPV6
460488
if (_localIp.type == IPADDR_TYPE_V6) {
461489
return false;
462490
}
463491
uint32_t ip = _localIp.u_addr.ip4.addr;
492+
#else
493+
uint32_t ip = _localIp.addr;
494+
#endif
464495
return ip == 0xFFFFFFFF || ip == 0 || (ip & 0xFF000000) == 0xFF000000;
465496
}
466497

@@ -571,6 +602,7 @@ static esp_err_t joinMulticastGroup(const ip_addr_t *addr, bool join, tcpip_adap
571602
}
572603
netif = (struct netif *)nif;
573604

605+
#if CONFIG_LWIP_IPV6
574606
if (addr->type == IPADDR_TYPE_V4) {
575607
if (join) {
576608
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
592624
}
593625
}
594626
}
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
595638
} else {
639+
#if CONFIG_LWIP_IPV6
596640
if (addr->type == IPADDR_TYPE_V4) {
597641
if (join) {
598642
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
614658
}
615659
}
616660
}
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
617672
}
618673
return ESP_OK;
619674
}
@@ -722,18 +777,24 @@ size_t AsyncUDP::writeTo(const uint8_t *data, size_t len, const IPAddress addr,
722777
}
723778

724779
IPAddress AsyncUDP::listenIP() {
780+
#if CONFIG_LWIP_IPV6
725781
if (!_pcb || _pcb->remote_ip.type != IPADDR_TYPE_V4) {
726782
return IPAddress();
727783
}
728784
return IPAddress(_pcb->remote_ip.u_addr.ip4.addr);
785+
#else
786+
return IPAddress(_pcb->remote_ip.addr);
787+
#endif
729788
}
730789

790+
#if CONFIG_LWIP_IPV6
731791
IPAddress AsyncUDP::listenIPv6() {
732792
if (!_pcb || _pcb->remote_ip.type != IPADDR_TYPE_V6) {
733793
return IPAddress(IPv6);
734794
}
735795
return IPAddress(IPv6, (const uint8_t *)_pcb->remote_ip.u_addr.ip6.addr, _pcb->remote_ip.u_addr.ip6.zone);
736796
}
797+
#endif
737798

738799
size_t AsyncUDP::write(const uint8_t *data, size_t len) {
739800
return writeTo(data, len, &(_pcb->remote_ip), _pcb->remote_port);

‎libraries/AsyncUDP/src/AsyncUDP.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,10 +79,14 @@ class AsyncUDPPacket : public Stream {
7979
tcpip_adapter_if_t interface();
8080

8181
IPAddress localIP();
82+
#if CONFIG_LWIP_IPV6
8283
IPAddress localIPv6();
84+
#endif
8385
uint16_t localPort();
8486
IPAddress remoteIP();
87+
#if CONFIG_LWIP_IPV6
8588
IPAddress remoteIPv6();
89+
#endif
8690
uint16_t remotePort();
8791
void remoteMac(uint8_t *mac);
8892

@@ -146,7 +150,9 @@ class AsyncUDP : public Print {
146150
size_t broadcast(AsyncUDPMessage &message);
147151

148152
IPAddress listenIP();
153+
#if CONFIG_LWIP_IPV6
149154
IPAddress listenIPv6();
155+
#endif
150156
bool connected();
151157
esp_err_t lastErr();
152158
operator bool();

‎libraries/Ethernet/src/ETH.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ static void onEthConnected(arduino_event_id_t event, arduino_event_info_t info)
7474
log_e("Could not find ETH interface with that handle!");
7575
return;
7676
}
77+
#if CONFIG_LWIP_IPV6
7778
if (_ethernets[index]->getStatusBits() & ESP_NETIF_WANT_IP6_BIT) {
7879
esp_err_t err = esp_netif_create_ip6_linklocal(_ethernets[index]->netif());
7980
if (err != ESP_OK) {
@@ -82,6 +83,7 @@ static void onEthConnected(arduino_event_id_t event, arduino_event_info_t info)
8283
log_v("Enabled IPv6 Link Local on %s", _ethernets[index]->desc());
8384
}
8485
}
86+
#endif
8587
}
8688
}
8789

‎libraries/Network/src/NetworkClient.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -210,6 +210,7 @@ int NetworkClient::connect(IPAddress ip, uint16_t port, int32_t timeout_ms) {
210210
_timeout = timeout_ms;
211211
int sockfd = -1;
212212

213+
#if CONFIG_LWIP_IPV6
213214
if (ip.type() == IPv6) {
214215
struct sockaddr_in6 *tmpaddr = (struct sockaddr_in6 *)&serveraddr;
215216
sockfd = socket(AF_INET6, SOCK_STREAM, 0);
@@ -218,12 +219,15 @@ int NetworkClient::connect(IPAddress ip, uint16_t port, int32_t timeout_ms) {
218219
tmpaddr->sin6_port = htons(port);
219220
tmpaddr->sin6_scope_id = ip.zone();
220221
} else {
222+
#endif
221223
struct sockaddr_in *tmpaddr = (struct sockaddr_in *)&serveraddr;
222224
sockfd = socket(AF_INET, SOCK_STREAM, 0);
223225
tmpaddr->sin_family = AF_INET;
224226
tmpaddr->sin_addr.s_addr = ip;
225227
tmpaddr->sin_port = htons(port);
228+
#if CONFIG_LWIP_IPV6
226229
}
230+
#endif
227231
if (sockfd < 0) {
228232
log_e("socket: %d", errno);
229233
return 0;
@@ -590,6 +594,7 @@ IPAddress NetworkClient::remoteIP(int fd) const {
590594
return IPAddress((uint32_t)(s->sin_addr.s_addr));
591595
}
592596

597+
#if CONFIG_LWIP_IPV6
593598
// IPv6, but it might be IPv4 mapped address
594599
if (((struct sockaddr *)&addr)->sa_family == AF_INET6) {
595600
struct sockaddr_in6 *saddr6 = (struct sockaddr_in6 *)&addr;
@@ -600,6 +605,7 @@ IPAddress NetworkClient::remoteIP(int fd) const {
600605
}
601606
}
602607
log_e("NetworkClient::remoteIP Not AF_INET or AF_INET6?");
608+
#endif
603609
return (IPAddress(0, 0, 0, 0));
604610
}
605611

@@ -630,6 +636,7 @@ IPAddress NetworkClient::localIP(int fd) const {
630636
return IPAddress((uint32_t)(s->sin_addr.s_addr));
631637
}
632638

639+
#if CONFIG_LWIP_IPV6
633640
// IPv6, but it might be IPv4 mapped address
634641
if (((struct sockaddr *)&addr)->sa_family == AF_INET6) {
635642
struct sockaddr_in6 *saddr6 = (struct sockaddr_in6 *)&addr;
@@ -640,6 +647,7 @@ IPAddress NetworkClient::localIP(int fd) const {
640647
}
641648
}
642649
log_e("NetworkClient::localIP Not AF_INET or AF_INET6?");
650+
#endif
643651
return (IPAddress(0, 0, 0, 0));
644652
}
645653

‎libraries/Network/src/NetworkEvents.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,10 @@
2424
#if SOC_WIFI_SUPPORTED || CONFIG_ESP_WIFI_REMOTE_ENABLED
2525
#include "esp_wifi_types.h"
2626
#include "esp_smartconfig.h"
27+
#if CONFIG_NETWORK_PROV_NETWORK_TYPE_WIFI
2728
#include "network_provisioning/network_config.h"
2829
#endif
30+
#endif
2931

3032
#if SOC_WIFI_SUPPORTED || CONFIG_ESP_WIFI_REMOTE_ENABLED
3133
constexpr int WIFI_SCANNING_BIT = BIT0;
@@ -111,7 +113,9 @@ typedef union {
111113
#endif
112114
#if SOC_WIFI_SUPPORTED
113115
wifi_sta_config_t prov_cred_recv;
116+
#if CONFIG_NETWORK_PROV_NETWORK_TYPE_WIFI
114117
network_prov_wifi_sta_fail_reason_t prov_fail_reason;
118+
#endif
115119
smartconfig_event_got_ssid_pswd_t sc_got_ssid_pswd;
116120
#endif
117121
} arduino_event_info_t;

‎libraries/Network/src/NetworkInterface.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,7 @@ void NetworkInterface::_onIpEvent(int32_t event_id, void *event_data) {
106106
} else if (_interface_id >= ESP_NETIF_ID_ETH && _interface_id < ESP_NETIF_ID_MAX) {
107107
arduino_event.event_id = ARDUINO_EVENT_ETH_LOST_IP;
108108
}
109+
#if CONFIG_LWIP_IPV6
109110
} else if (event_id == IP_EVENT_GOT_IP6) {
110111
ip_event_got_ip6_t *event = (ip_event_got_ip6_t *)event_data;
111112
esp_ip6_addr_type_t addr_type = esp_netif_ip6_get_addr_type(&event->ip6_info.ip);
@@ -134,6 +135,7 @@ void NetworkInterface::_onIpEvent(int32_t event_id, void *event_data) {
134135
} else if (_interface_id >= ESP_NETIF_ID_ETH && _interface_id < ESP_NETIF_ID_MAX) {
135136
arduino_event.event_id = ARDUINO_EVENT_ETH_GOT_IP6;
136137
}
138+
#endif /* CONFIG_LWIP_IPV6 */
137139
#if SOC_WIFI_SUPPORTED
138140
} else if (event_id == IP_EVENT_AP_STAIPASSIGNED && _interface_id == ESP_NETIF_ID_AP) {
139141
setStatusBits(ESP_NETIF_HAS_IP_BIT);
@@ -326,6 +328,7 @@ bool NetworkInterface::hasGlobalIPv6() const {
326328
}
327329

328330
bool NetworkInterface::enableIPv6(bool en) {
331+
#if CONFIG_LWIP_IPV6
329332
if (en) {
330333
setStatusBits(ESP_NETIF_WANT_IP6_BIT);
331334
if (_esp_netif != NULL && connected()) {
@@ -341,6 +344,9 @@ bool NetworkInterface::enableIPv6(bool en) {
341344
clearStatusBits(ESP_NETIF_WANT_IP6_BIT);
342345
}
343346
return true;
347+
#else
348+
return false;
349+
#endif
344350
}
345351

346352
bool NetworkInterface::dnsIP(uint8_t dns_no, IPAddress ip) {
@@ -739,6 +745,7 @@ uint8_t NetworkInterface::subnetCIDR() const {
739745
return calculateSubnetCIDR(IPAddress(ip.netmask.addr));
740746
}
741747

748+
#if CONFIG_LWIP_IPV6
742749
IPAddress NetworkInterface::linkLocalIPv6() const {
743750
if (_esp_netif == NULL) {
744751
return IPAddress(IPv6);
@@ -760,6 +767,7 @@ IPAddress NetworkInterface::globalIPv6() const {
760767
}
761768
return IPAddress(IPv6, (const uint8_t *)addr.addr, addr.zone);
762769
}
770+
#endif
763771

764772
size_t NetworkInterface::printTo(Print &out) const {
765773
size_t bytes = 0;
@@ -834,6 +842,7 @@ size_t NetworkInterface::printTo(Print &out) const {
834842
bytes += out.print(dnsIP());
835843
bytes += out.println();
836844

845+
#if CONFIG_LWIP_IPV6
837846
static const char *types[] = {"UNKNOWN", "GLOBAL", "LINK_LOCAL", "SITE_LOCAL", "UNIQUE_LOCAL", "IPV4_MAPPED_IPV6"};
838847
esp_ip6_addr_t if_ip6[CONFIG_LWIP_IPV6_NUM_ADDRESSES];
839848
int v6addrs = esp_netif_get_all_ip6(_esp_netif, if_ip6);
@@ -845,6 +854,7 @@ size_t NetworkInterface::printTo(Print &out) const {
845854
bytes += out.print(types[esp_netif_ip6_get_addr_type(&if_ip6[i])]);
846855
bytes += out.println();
847856
}
857+
#endif
848858

849859
return bytes;
850860
}

‎libraries/Network/src/NetworkInterface.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,8 +70,10 @@ class NetworkInterface : public Printable {
7070
IPAddress broadcastIP() const;
7171
IPAddress networkID() const;
7272
uint8_t subnetCIDR() const;
73+
#if CONFIG_LWIP_IPV6
7374
IPAddress linkLocalIPv6() const;
7475
IPAddress globalIPv6() const;
76+
#endif
7577

7678
size_t printTo(Print &out) const;
7779

‎libraries/Network/src/NetworkManager.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@ int NetworkManager::hostByName(const char *aHostname, IPAddress &aResult) {
8787
memset(&hints, 0, sizeof(hints));
8888
hints.ai_socktype = SOCK_STREAM;
8989

90+
#if CONFIG_LWIP_IPV6
9091
// **Workaround**
9192
// LWIP AF_UNSPEC always prefers IPv4 and doesn't check what network is
9293
// available. See https://github.com/espressif/esp-idf/issues/13255
@@ -106,22 +107,27 @@ int NetworkManager::hostByName(const char *aHostname, IPAddress &aResult) {
106107
}
107108
}
108109
// **End Workaround**
110+
#endif
109111

110112
hints.ai_family = AF_UNSPEC;
111113
err = lwip_getaddrinfo(aHostname, servname, &hints, &res);
112114

113115
if (err == ERR_OK) {
116+
#if CONFIG_LWIP_IPV6
114117
if (res->ai_family == AF_INET6) {
115118
struct sockaddr_in6 *ipv6 = (struct sockaddr_in6 *)res->ai_addr;
116119
// As an array of u8_t
117120
aResult = IPAddress(IPv6, ipv6->sin6_addr.s6_addr);
118121
log_d("DNS found IPv6 %s", aResult.toString().c_str());
119122
} else {
123+
#endif
120124
struct sockaddr_in *ipv4 = (struct sockaddr_in *)res->ai_addr;
121125
// As a single u32_t
122126
aResult = IPAddress(ipv4->sin_addr.s_addr);
123127
log_d("DNS found IPv4 %s", aResult.toString().c_str());
128+
#if CONFIG_LWIP_IPV6
124129
}
130+
#endif
125131

126132
lwip_freeaddrinfo(res);
127133
return 1;

‎libraries/Network/src/NetworkServer.cpp

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,13 @@ NetworkClient NetworkServer::accept() {
4646
client_sock = _accepted_sockfd;
4747
_accepted_sockfd = -1;
4848
} else {
49+
#if CONFIG_LWIP_IPV6
4950
struct sockaddr_in6 _client;
5051
int cs = sizeof(struct sockaddr_in6);
52+
#else
53+
struct sockaddr_in _client;
54+
int cs = sizeof(struct sockaddr_in);
55+
#endif
5156
#ifdef ESP_IDF_VERSION_MAJOR
5257
client_sock = lwip_accept(sockfd, (struct sockaddr *)&_client, (socklen_t *)&cs);
5358
#else
@@ -77,6 +82,7 @@ void NetworkServer::begin(uint16_t port, int enable) {
7782
if (port) {
7883
_port = port;
7984
}
85+
#if CONFIG_LWIP_IPV6
8086
struct sockaddr_in6 server;
8187
sockfd = socket(AF_INET6, SOCK_STREAM, 0);
8288
if (sockfd < 0) {
@@ -93,6 +99,18 @@ void NetworkServer::begin(uint16_t port, int enable) {
9399
}
94100
memset(server.sin6_addr.s6_addr, 0x0, 16);
95101
server.sin6_port = htons(_port);
102+
#else
103+
struct sockaddr_in server;
104+
memset(&server, 0x0, sizeof(sockaddr_in));
105+
server.sin_family = AF_INET;
106+
sockfd = socket(AF_INET, SOCK_STREAM, 0);
107+
if (sockfd < 0) {
108+
return;
109+
}
110+
setsockopt(sockfd, SOL_SOCKET, SO_REUSEADDR, &enable, sizeof(int));
111+
memcpy((uint8_t *)&(server.sin_addr.s_addr), (uint8_t *)&_addr[0], 4);
112+
server.sin_port = htons(_port);
113+
#endif
96114
if (bind(sockfd, (struct sockaddr *)&server, sizeof(server)) < 0) {
97115
return;
98116
}
@@ -117,8 +135,13 @@ bool NetworkServer::hasClient() {
117135
if (_accepted_sockfd >= 0) {
118136
return true;
119137
}
138+
#if CONFIG_LWIP_IPV6
120139
struct sockaddr_in6 _client;
121140
int cs = sizeof(struct sockaddr_in6);
141+
#else
142+
struct sockaddr _client;
143+
int cs = sizeof(struct sockaddr);
144+
#endif
122145
#ifdef ESP_IDF_VERSION_MAJOR
123146
_accepted_sockfd = lwip_accept(sockfd, (struct sockaddr *)&_client, (socklen_t *)&cs);
124147
#else

‎libraries/Network/src/NetworkUdp.cpp

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -255,6 +255,7 @@ int NetworkUDP::endPacket() {
255255
log_e("could not send data: %d", errno);
256256
return 0;
257257
}
258+
#if LWIP_IPV6
258259
} else {
259260
struct sockaddr_in6 recipient;
260261
recipient.sin6_flowinfo = 0;
@@ -267,6 +268,7 @@ int NetworkUDP::endPacket() {
267268
log_e("could not send data: %d", errno);
268269
return 0;
269270
}
271+
#endif
270272
}
271273
return 1;
272274
}
@@ -336,12 +338,16 @@ int NetworkUDP::parsePacket() {
336338
remote_ip.from_ip_addr_t(&addr);
337339
}
338340
remote_port = ntohs(si_other.sin6_port);
341+
} else {
342+
remote_ip = ip_addr_any.u_addr.ip4.addr;
343+
remote_port = 0;
339344
}
340-
#endif // LWIP_IPV6=1
345+
#else
341346
else {
342-
remote_ip = ip_addr_any.u_addr.ip4.addr;
347+
remote_ip = ip_addr_any.addr;
343348
remote_port = 0;
344349
}
350+
#endif // LWIP_IPV6=1
345351
if (len > 0) {
346352
rx_buffer = new (std::nothrow) cbuf(len);
347353
rx_buffer->write(buf, len);

‎libraries/NetworkClientSecure/src/ssl_client.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@ int start_ssl_client(
8383

8484
fcntl(ssl_client->socket, F_SETFL, fcntl(ssl_client->socket, F_GETFL, 0) | O_NONBLOCK);
8585
struct sockaddr_storage serv_addr = {};
86+
#if CONFIG_LWIP_IPV6
8687
if (domain == AF_INET6) {
8788
struct sockaddr_in6 *tmpaddr = (struct sockaddr_in6 *)&serv_addr;
8889
tmpaddr->sin6_family = AF_INET6;
@@ -92,11 +93,14 @@ int start_ssl_client(
9293
tmpaddr->sin6_port = htons(port);
9394
tmpaddr->sin6_scope_id = ip.zone();
9495
} else {
96+
#endif
9597
struct sockaddr_in *tmpaddr = (struct sockaddr_in *)&serv_addr;
9698
tmpaddr->sin_family = AF_INET;
9799
tmpaddr->sin_addr.s_addr = ip;
98100
tmpaddr->sin_port = htons(port);
101+
#if CONFIG_LWIP_IPV6
99102
}
103+
#endif
100104

101105
if (timeout <= 0) {
102106
timeout = 30000; // Milli seconds.

‎libraries/WiFi/src/AP.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@ static void _onApArduinoEvent(arduino_event_t *ev) {
8787
}
8888
log_v("Arduino AP Event: %d - %s", ev->event_id, Network.eventName(ev->event_id));
8989
if (ev->event_id == ARDUINO_EVENT_WIFI_AP_START) {
90+
#if CONFIG_LWIP_IPV6
9091
if (_ap_network_if->getStatusBits() & ESP_NETIF_WANT_IP6_BIT) {
9192
esp_err_t err = esp_netif_create_ip6_linklocal(_ap_network_if->netif());
9293
if (err != ESP_OK) {
@@ -95,6 +96,7 @@ static void _onApArduinoEvent(arduino_event_t *ev) {
9596
log_v("Enabled IPv6 Link Local on %s", _ap_network_if->desc());
9697
}
9798
}
99+
#endif
98100
}
99101
}
100102

‎libraries/WiFi/src/STA.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,7 @@ static void _onStaArduinoEvent(arduino_event_t *ev) {
118118
_sta_network_if->_setStatus(WL_STOPPED);
119119
} else if (ev->event_id == ARDUINO_EVENT_WIFI_STA_CONNECTED) {
120120
_sta_network_if->_setStatus(WL_IDLE_STATUS);
121+
#if CONFIG_LWIP_IPV6
121122
if (_sta_network_if->getStatusBits() & ESP_NETIF_WANT_IP6_BIT) {
122123
esp_err_t err = esp_netif_create_ip6_linklocal(_sta_network_if->netif());
123124
if (err != ESP_OK) {
@@ -126,6 +127,7 @@ static void _onStaArduinoEvent(arduino_event_t *ev) {
126127
log_v("Enabled IPv6 Link Local on %s", _sta_network_if->desc());
127128
}
128129
}
130+
#endif
129131
} else if (ev->event_id == ARDUINO_EVENT_WIFI_STA_DISCONNECTED) {
130132
uint8_t reason = ev->event_info.wifi_sta_disconnected.reason;
131133
// Reason 0 causes crash, use reason 1 (UNSPECIFIED) instead

‎libraries/WiFi/src/WiFiAP.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,7 @@ bool WiFiAPClass::softAPsetHostname(const char *hostname) {
177177
return AP.setHostname(hostname);
178178
}
179179

180+
#if CONFIG_LWIP_IPV6
180181
/**
181182
* Enable IPv6 on the softAP interface.
182183
* @return true on success
@@ -193,5 +194,5 @@ bool WiFiAPClass::softAPenableIPv6(bool enable) {
193194
IPAddress WiFiAPClass::softAPlinkLocalIPv6() {
194195
return AP.linkLocalIPv6();
195196
}
196-
197+
#endif
197198
#endif /* SOC_WIFI_SUPPORTED */

‎libraries/WiFi/src/WiFiAP.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
#pragma once
2424

2525
#include "soc/soc_caps.h"
26+
#include "sdkconfig.h"
2627
#if SOC_WIFI_SUPPORTED || CONFIG_ESP_WIFI_REMOTE_ENABLED
2728

2829
#include "esp_wifi_types.h"
@@ -100,8 +101,10 @@ class WiFiAPClass {
100101
IPAddress softAPSubnetMask();
101102
uint8_t softAPSubnetCIDR();
102103

104+
#if CONFIG_LWIP_IPV6
103105
bool softAPenableIPv6(bool enable = true);
104106
IPAddress softAPlinkLocalIPv6();
107+
#endif
105108

106109
const char *softAPgetHostname();
107110
bool softAPsetHostname(const char *hostname);

‎libraries/WiFi/src/WiFiGeneric.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,7 @@ static void _arduino_event_cb(void *arg, esp_event_base_t event_base, int32_t ev
127127
log_v("SC Send Ack Done");
128128
arduino_event.event_id = ARDUINO_EVENT_SC_SEND_ACK_DONE;
129129

130+
#if CONFIG_NETWORK_PROV_NETWORK_TYPE_WIFI
130131
/*
131132
* Provisioning
132133
* */
@@ -160,6 +161,7 @@ static void _arduino_event_cb(void *arg, esp_event_base_t event_base, int32_t ev
160161
} else if (event_base == NETWORK_PROV_EVENT && event_id == NETWORK_PROV_WIFI_CRED_SUCCESS) {
161162
log_v("Provisioning Success!");
162163
arduino_event.event_id = ARDUINO_EVENT_PROV_CRED_SUCCESS;
164+
#endif
163165
#endif
164166
}
165167

@@ -180,10 +182,12 @@ static bool initWiFiEvents() {
180182
return false;
181183
}
182184

185+
#if CONFIG_NETWORK_PROV_NETWORK_TYPE_WIFI
183186
if (esp_event_handler_instance_register(NETWORK_PROV_EVENT, ESP_EVENT_ANY_ID, &_arduino_event_cb, NULL, NULL)) {
184187
log_e("event_handler_instance_register for NETWORK_PROV_EVENT Failed!");
185188
return false;
186189
}
190+
#endif
187191
#endif
188192

189193
return true;
@@ -201,10 +205,12 @@ static bool deinitWiFiEvents() {
201205
return false;
202206
}
203207

208+
#if CONFIG_NETWORK_PROV_NETWORK_TYPE_WIFI
204209
if (esp_event_handler_unregister(NETWORK_PROV_EVENT, ESP_EVENT_ANY_ID, &_arduino_event_cb)) {
205210
log_e("esp_event_handler_unregister for NETWORK_PROV_EVENT Failed!");
206211
return false;
207212
}
213+
#endif
208214
#endif
209215

210216
return true;

‎libraries/WiFi/src/WiFiGeneric.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
#pragma once
2424

2525
#include "soc/soc_caps.h"
26+
#include "sdkconfig.h"
2627
#if SOC_WIFI_SUPPORTED || CONFIG_ESP_WIFI_REMOTE_ENABLED
2728

2829
#include "esp_err.h"
@@ -33,7 +34,9 @@
3334
#include "esp_smartconfig.h"
3435
#include "esp_netif_types.h"
3536
#include "esp_eth_driver.h"
37+
#if CONFIG_NETWORK_PROV_NETWORK_TYPE_WIFI
3638
#include "network_provisioning/manager.h"
39+
#endif
3740
#include "lwip/ip_addr.h"
3841

3942
#include "Network.h"

‎libraries/WiFi/src/WiFiMulti.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -251,9 +251,11 @@ uint8_t WiFiMulti::run(uint32_t connectTimeout, bool scanHidden) {
251251
bestBSSID[4], bestBSSID[5], bestNetwork.ssid, bestChannel, bestNetworkDb
252252
);
253253

254+
#if CONFIG_LWIP_IPV6
254255
if (ipv6_support == true) {
255256
WiFi.enableIPv6();
256257
}
258+
#endif
257259
WiFi.disconnect();
258260
delay(10);
259261
WiFi.begin(bestNetwork.ssid, (_bAllowOpenAP && bestNetworkSec == WIFI_AUTH_OPEN) ? NULL : bestNetwork.passphrase, bestChannel, bestBSSID);
@@ -318,9 +320,11 @@ uint8_t WiFiMulti::run(uint32_t connectTimeout, bool scanHidden) {
318320
return status;
319321
}
320322

323+
#if CONFIG_LWIP_IPV6
321324
void WiFiMulti::enableIPv6(bool state) {
322325
ipv6_support = state;
323326
}
327+
#endif
324328

325329
void WiFiMulti::markAsFailed(int32_t i) {
326330
APlist[i].hasFailed = true;

‎libraries/WiFi/src/WiFiMulti.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,9 @@ class WiFiMulti {
4747

4848
bool addAP(const char *ssid, const char *passphrase = NULL);
4949
uint8_t run(uint32_t connectTimeout = 5000, bool scanHidden = false);
50+
#if CONFIG_LWIP_IPV6
5051
void enableIPv6(bool state);
52+
#endif
5153

5254
// Force (default: true) to only keep connected or to connect to an AP from the provided WiFiMulti list.
5355
// When bStrict is false, it will keep the last/current connected AP even if not in the WiFiMulti List.

‎libraries/WiFi/src/WiFiSTA.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -386,6 +386,7 @@ int8_t WiFiSTAClass::RSSI(void) {
386386
return STA.RSSI();
387387
}
388388

389+
#if CONFIG_LWIP_IPV6
389390
/**
390391
* Enable IPv6 on the station interface.
391392
* Should be called before WiFi.begin()
@@ -411,6 +412,7 @@ IPAddress WiFiSTAClass::linkLocalIPv6() {
411412
IPAddress WiFiSTAClass::globalIPv6() {
412413
return STA.globalIPv6();
413414
}
415+
#endif
414416

415417
bool WiFiSTAClass::_smartConfigStarted = false;
416418
bool WiFiSTAClass::_smartConfigDone = false;

‎libraries/WiFi/src/WiFiSTA.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
#pragma once
2424

2525
#include "soc/soc_caps.h"
26+
#include "sdkconfig.h"
2627
#if SOC_WIFI_SUPPORTED || CONFIG_ESP_WIFI_REMOTE_ENABLED
2728

2829
#include "WiFiType.h"
@@ -179,9 +180,11 @@ class WiFiSTAClass {
179180
IPAddress networkID();
180181
uint8_t subnetCIDR();
181182

183+
#if CONFIG_LWIP_IPV6
182184
bool enableIPv6(bool en = true);
183185
IPAddress linkLocalIPv6();
184186
IPAddress globalIPv6();
187+
#endif
185188

186189
// ----------------------------------------------------------------------------------------------
187190
// ---------------------------------------- Smart Config ----------------------------------------

‎libraries/WiFi/src/WiFiScan.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
#pragma once
2424

2525
#include "soc/soc_caps.h"
26+
#include "sdkconfig.h"
2627
#if SOC_WIFI_SUPPORTED || CONFIG_ESP_WIFI_REMOTE_ENABLED
2728

2829
#include "WiFiType.h"

‎libraries/WiFi/src/WiFiType.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
#pragma once
2323

2424
#include "soc/soc_caps.h"
25+
#include "sdkconfig.h"
2526
#if SOC_WIFI_SUPPORTED || CONFIG_ESP_WIFI_REMOTE_ENABLED
2627

2728
#include "esp_wifi_types.h"

‎libraries/WiFiProv/src/WiFiProv.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@
1818
1919
*/
2020
#include "soc/soc_caps.h"
21-
#if SOC_WIFI_SUPPORTED
21+
#include "sdkconfig.h"
22+
#if SOC_WIFI_SUPPORTED && CONFIG_NETWORK_PROV_NETWORK_TYPE_WIFI
2223

2324
#include <stdio.h>
2425
#include <stdint.h>

‎libraries/WiFiProv/src/WiFiProv.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,8 @@
2020
#pragma once
2121

2222
#include "soc/soc_caps.h"
23-
#if SOC_WIFI_SUPPORTED
23+
#include "sdkconfig.h"
24+
#if SOC_WIFI_SUPPORTED && CONFIG_NETWORK_PROV_NETWORK_TYPE_WIFI
2425

2526
#include "WiFi.h"
2627
#include "HardwareSerial.h"

0 commit comments

Comments
 (0)
Please sign in to comment.