Skip to content

Commit ce2cd11

Browse files
authored
Fixes INADDR_NONE (espressif#6659)
Description of Change Fixes IPAddress INADDR_NONE declaration when using Arduino WiFi or ETH. This symbol was defined as 0xffffffff by lwip /inet.h, making it impossible to use INADDR_NONE correctly. This PR only works when <wifi-provisioning/wifi_config.h> has a modification to include <lwip/ip4_addr.h> instead of <lwip/inet.h>. This will be done directly to the sdk folder in the github structure and it has been fixed in IDF by a separated Merge Request. This will be reflected in the future, for good. Tests scenarios This PR was tested with all Arduino WiFi examples, including AsyncUDP. Also with ETH examples. It was also tested for espressif#6610 test cases. Testing done for ESP32, ESP32-S2, ESP32-C3 and ESP32-S3. Related links fixes espressif#6610 fixes espressif#6247 fixes espressif#4732
1 parent 5f6d093 commit ce2cd11

File tree

8 files changed

+11
-9
lines changed

8 files changed

+11
-9
lines changed

cores/esp32/IPAddress.cpp

+3
Original file line numberDiff line numberDiff line change
@@ -120,3 +120,6 @@ bool IPAddress::fromString(const char *address)
120120
_address.bytes[3] = acc;
121121
return true;
122122
}
123+
124+
// declared one time - as external in IPAddress.h
125+
IPAddress INADDR_NONE(0, 0, 0, 0);

cores/esp32/IPAddress.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,6 @@ class IPAddress: public Printable
9191
friend class DNSClient;
9292
};
9393

94-
const IPAddress INADDR_NONE(0, 0, 0, 0);
95-
94+
// changed to extern because const declaration creates copies in BSS of INADDR_NONE for each CPP unit that includes it
95+
extern IPAddress INADDR_NONE;
9696
#endif

libraries/AsyncUDP/src/AsyncUDP.h

-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
#include "Stream.h"
88
#include <functional>
99
extern "C" {
10-
#include "lwip/ip_addr.h"
1110
#include "esp_netif.h"
1211
#include "freertos/queue.h"
1312
#include "freertos/semphr.h"

libraries/WiFi/src/WiFiServer.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222
#include "Arduino.h"
2323
#include "Server.h"
2424
#include "WiFiClient.h"
25-
#include "arpa/inet.h"
2625
#include "IPAddress.h"
2726

2827
class WiFiServer : public Server {
@@ -38,7 +37,8 @@ class WiFiServer : public Server {
3837
public:
3938
void listenOnLocalhost(){}
4039

41-
WiFiServer(uint16_t port=80, uint8_t max_clients=4):sockfd(-1),_accepted_sockfd(-1),_addr(INADDR_ANY),_port(port),_max_clients(max_clients),_listening(false),_noDelay(false) {
40+
// _addr(INADDR_ANY) is the same as _addr() ==> 0.0.0.0
41+
WiFiServer(uint16_t port=80, uint8_t max_clients=4):sockfd(-1),_accepted_sockfd(-1),_addr(),_port(port),_max_clients(max_clients),_listening(false),_noDelay(false) {
4242
log_v("WiFiServer::WiFiServer(port=%d, ...)", port);
4343
}
4444
WiFiServer(const IPAddress& addr, uint16_t port=80, uint8_t max_clients=4):sockfd(-1),_accepted_sockfd(-1),_addr(addr),_port(port),_max_clients(max_clients),_listening(false),_noDelay(false) {

tools/sdk/esp32/include/wifi_provisioning/include/wifi_provisioning/wifi_config.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
#ifndef _WIFI_PROV_CONFIG_H_
1616
#define _WIFI_PROV_CONFIG_H_
1717

18-
#include <lwip/inet.h>
18+
#include <lwip/ip4_addr.h>
1919

2020
#ifdef __cplusplus
2121
extern "C" {

tools/sdk/esp32c3/include/wifi_provisioning/include/wifi_provisioning/wifi_config.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
#ifndef _WIFI_PROV_CONFIG_H_
1616
#define _WIFI_PROV_CONFIG_H_
1717

18-
#include <lwip/inet.h>
18+
#include <lwip/ip4_addr.h>
1919

2020
#ifdef __cplusplus
2121
extern "C" {

tools/sdk/esp32s2/include/wifi_provisioning/include/wifi_provisioning/wifi_config.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
#ifndef _WIFI_PROV_CONFIG_H_
1616
#define _WIFI_PROV_CONFIG_H_
1717

18-
#include <lwip/inet.h>
18+
#include <lwip/ip4_addr.h>
1919

2020
#ifdef __cplusplus
2121
extern "C" {

tools/sdk/esp32s3/include/wifi_provisioning/include/wifi_provisioning/wifi_config.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
#ifndef _WIFI_PROV_CONFIG_H_
1616
#define _WIFI_PROV_CONFIG_H_
1717

18-
#include <lwip/inet.h>
18+
#include <lwip/ip4_addr.h>
1919

2020
#ifdef __cplusplus
2121
extern "C" {

0 commit comments

Comments
 (0)