Skip to content

Commit

Permalink
Fixes INADDR_NONE (espressif#6659) (#136)
Browse files Browse the repository at this point in the history
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

Co-authored-by: Rodrigo Garcia <rodrigo.garcia@espressif.com>
  • Loading branch information
Jason2866 and SuGlider authored Apr 29, 2022
1 parent b6b28ee commit e139e7b
Show file tree
Hide file tree
Showing 8 changed files with 11 additions and 9 deletions.
3 changes: 3 additions & 0 deletions cores/esp32/IPAddress.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -120,3 +120,6 @@ bool IPAddress::fromString(const char *address)
_address.bytes[3] = acc;
return true;
}

// declared one time - as external in IPAddress.h
IPAddress INADDR_NONE(0, 0, 0, 0);
4 changes: 2 additions & 2 deletions cores/esp32/IPAddress.h
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,6 @@ class IPAddress: public Printable
friend class DNSClient;
};

const IPAddress INADDR_NONE(0, 0, 0, 0);

// changed to extern because const declaration creates copies in BSS of INADDR_NONE for each CPP unit that includes it
extern IPAddress INADDR_NONE;
#endif
1 change: 0 additions & 1 deletion libraries/AsyncUDP/src/AsyncUDP.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
#include "Stream.h"
#include <functional>
extern "C" {
#include "lwip/ip_addr.h"
#include "esp_netif.h"
#include "freertos/queue.h"
#include "freertos/semphr.h"
Expand Down
4 changes: 2 additions & 2 deletions libraries/WiFi/src/WiFiServer.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
#include "Arduino.h"
#include "Server.h"
#include "WiFiClient.h"
#include "arpa/inet.h"
#include "IPAddress.h"

class WiFiServer : public Server {
Expand All @@ -38,7 +37,8 @@ class WiFiServer : public Server {
public:
void listenOnLocalhost(){}

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) {
// _addr(INADDR_ANY) is the same as _addr() ==> 0.0.0.0
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) {
log_v("WiFiServer::WiFiServer(port=%d, ...)", port);
}
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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
#ifndef _WIFI_PROV_CONFIG_H_
#define _WIFI_PROV_CONFIG_H_

#include <lwip/inet.h>
#include <lwip/ip4_addr.h>

#ifdef __cplusplus
extern "C" {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
#ifndef _WIFI_PROV_CONFIG_H_
#define _WIFI_PROV_CONFIG_H_

#include <lwip/inet.h>
#include <lwip/ip4_addr.h>

#ifdef __cplusplus
extern "C" {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
#ifndef _WIFI_PROV_CONFIG_H_
#define _WIFI_PROV_CONFIG_H_

#include <lwip/inet.h>
#include <lwip/ip4_addr.h>

#ifdef __cplusplus
extern "C" {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
#ifndef _WIFI_PROV_CONFIG_H_
#define _WIFI_PROV_CONFIG_H_

#include <lwip/inet.h>
#include <lwip/ip4_addr.h>

#ifdef __cplusplus
extern "C" {
Expand Down

0 comments on commit e139e7b

Please sign in to comment.