Skip to content

IPADDR_NONE conflicting defines #6760

Closed
@mrengineer7777

Description

@mrengineer7777

Board

Adafruit Feather ESP32

Device Description

ESP32-C3-DevKitC-02

Hardware Configuration

None

Version

v2.0.3

IDE Name

VSCODE w/ PIO

Operating System

Win10

Flash frequency

40Mhz

PSRAM enabled

no

Upload speed

115200

Description

I have run into an issue while creating a new "PingClass" library to replace the deprecated ping.h and esp_ping.h libraries.

This issue is mentioned in issue #6247, #6610. Even when applying the fix in #6659 to my copy of IPAddress.cpp/h, I still get the error seen below.

I have resolved the issue in my class by dropping all references to String and IPAddress, and just using C strings. However, I believe the definitions still conflict. Definitions:

IPAddress.cpp: IPAddress INADDR_NONE(0, 0, 0, 0);
IPAddress.h: extern IPAddress INADDR_NONE;
inet.h: #define INADDR_NONE IPADDR_NONE
ip4_addr.h: #define IPADDR_NONE ((u32_t)0xffffffffUL)

I believe INADDR_NONE expands in IPAddress.h as: IPAddress(0,0,0,0), which works with the constructor. But if inet.h is included it may expand as:
((u32_t)0xffffffffUL)(0, 0, 0, 0).

Note also that 0.0.0.0 is a completely different IP than IPADDR_NONE=255.255.255.255.

Sketch

#include <stdio.h>
#include "lwip/netdb.h"
#include "ping/ping_sock.h"
#include "IPAddress.h"

extern "C" {
  #include "esp32-hal.h"
  #include "lwip\sockets.h"
}

#include <Arduino.h>

//-----Prototypes-----
ip_addr_t _url_to_ipaddr(const char *ip_cstr);
//-----Prototypes-----

//Convert passed URL or IP cstr into ip address
//Uses new ip_addr_t format that combines IP4 and IP6 addresses
//Based on https://github.com/espressif/esp-idf/blob/master/examples/protocols/icmp_echo/main/echo_example_main.c
ip_addr_t _url_to_ipaddr(const char *ip_cstr) {
    struct sockaddr_in6 sock_addr6;
    ip_addr_t target_addr;
    memset(&target_addr, 0, sizeof(target_addr));

    if (inet_pton(AF_INET6, ip_cstr, &sock_addr6.sin6_addr) == 1) {
        /* convert ip6 string to ip6 address */
        ipaddr_aton(ip_cstr, &target_addr);
    } else {
        struct addrinfo hint;
        struct addrinfo *res = NULL;
        memset(&hint, 0, sizeof(hint));
        /* convert ip4 string or hostname to ip4 or ip6 address */
        if (getaddrinfo(ip_cstr, NULL, &hint, &res) != 0) {
            log_v("Unknown host %s\n", ip_cstr);
            return target_addr;
        }
        if (res->ai_family == AF_INET) {
            struct in_addr addr4 = ((struct sockaddr_in *) (res->ai_addr))->sin_addr;
            inet_addr_to_ip4addr(ip_2_ip4(&target_addr), &addr4);
        } else {
            struct in6_addr addr6 = ((struct sockaddr_in6 *) (res->ai_addr))->sin6_addr;
            inet6_addr_to_ip6addr(ip_2_ip6(&target_addr), &addr6);
        }
        freeaddrinfo(res);
    }
    return target_addr;
}

void setup() {
    char buf[64];
    
    Serial.begin(115200);
    delay(2000);
    
    sprintf(buf, "%s", "www.google.com");
    ip_addr_t ip = _url_to_ipaddr(buf);

    log_v("%s = %s", buf, IPAddress(ip.u_addr.ip4.addr).toString().c_str());
}

void loop() {
    delay(1000);                        // Allow other tasks to run
}

Debug Message

No dependencies
Building in release mode
Compiling .pio\build\featheresp32ard\src\main.cpp.o
In file included from C:/Users/David/.platformio/packages/framework-arduinoespressif32/tools/sdk/esp32/include/lwip/lwip/src/include/lwip/ip_addr.h:43,
                 from C:/Users/David/.platformio/packages/framework-arduinoespressif32/tools/sdk/esp32/include/lwip/lwip/src/include/lwip/inet.h:45,
                 from C:/Users/David/.platformio/packages/framework-arduinoespressif32/tools/sdk/esp32/include/lwip/lwip/src/include/lwip/netdb.h:42,
                 from src/main.cpp:2:
C:/Users/David/.platformio/packages/framework-arduinoespressif32/tools/sdk/esp32/include/lwip/lwip/src/include/lwip/ip4_addr.h:63:37: error: expected ')' before numeric constant
 #define IPADDR_NONE         ((u32_t)0xffffffffUL)
                             ~       ^~~~~~~~~~~~
C:/Users/David/.platformio/packages/framework-arduinoespressif32/tools/sdk/esp32/include/lwip/lwip/src/include/lwip/inet.h:71:29: note: in expansion of macro 'IPADDR_NONE'
 #define INADDR_NONE         IPADDR_NONE
                             ^~~~~~~~~~~
C:/Users/David/.platformio/packages/framework-arduinoespressif32/cores/esp32/IPAddress.h:95:18: note: in expansion of macro 'INADDR_NONE'
 extern IPAddress INADDR_NONE;
                  ^~~~~~~~~~~
*** [.pio\build\featheresp32ard\src\main.cpp.o] Error 1

Other Steps to Reproduce

No response

I have checked existing issues, online documentation and the Troubleshooting Guide

  • I confirm I have checked existing issues, online documentation and Troubleshooting guide.

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions