From 324b3f9678c88075545d8f6a53658d3b191e8980 Mon Sep 17 00:00:00 2001 From: david gauchard Date: Sun, 2 Dec 2018 03:21:33 +0100 Subject: [PATCH] IPAddress updates (#5409) * restore definition of ip_addr (=ipv4_addr) when IPv6 is not enabled * overload IPAddress:operator == and != to avoid ambiguousness * brings lwIP's INADDR_NONE (which is IPv4 255.255.255.255, suposed to be invalid address but it is) * inet_aton is a lwIP define, rename Ethernet DNS implementation of this to prevent name collision that's because IPAddress now includes lwip/inet.h --- cores/esp8266/IPAddress.h | 16 +++++++++++++--- libraries/Ethernet/src/Dns.cpp | 4 ++-- libraries/Ethernet/src/Dns.h | 2 +- 3 files changed, 16 insertions(+), 6 deletions(-) diff --git a/cores/esp8266/IPAddress.h b/cores/esp8266/IPAddress.h index 925054e23..97d278500 100644 --- a/cores/esp8266/IPAddress.h +++ b/cores/esp8266/IPAddress.h @@ -38,9 +38,12 @@ #define IP4_ADDR_ANY4 IPADDR_ANY #define IPADDR4_INIT(x) { x } #define CONST /* nothing: lwIP-v1 does not use const */ -#else +#else // lwIP-v2+ #define CONST const -#endif +#if !LWIP_IPV6 +#define ip_addr ipv4_addr +#endif // !LWIP_IPV6 +#endif // lwIP-v2+ // A class to make it easier to handle and pass around IP addresses // IPv6 update: @@ -96,9 +99,15 @@ class IPAddress: public Printable { bool operator==(uint32_t addr) const { return isV4() && v4() == addr; } + bool operator==(u32_t addr) const { + return isV4() && v4() == addr; + } bool operator!=(uint32_t addr) const { return !(isV4() && v4() == addr); } + bool operator!=(u32_t addr) const { + return !(isV4() && v4() == addr); + } bool operator==(const uint8_t* addr) const; // Overloaded index operator to allow getting and setting individual octets of the address @@ -193,6 +202,7 @@ class IPAddress: public Printable { extern CONST IPAddress IPNoAddress; -#include +#include // bring definition of INADDR_NONE +#include // bring interface iterator #endif diff --git a/libraries/Ethernet/src/Dns.cpp b/libraries/Ethernet/src/Dns.cpp index 365058fc6..8f5cec8f0 100644 --- a/libraries/Ethernet/src/Dns.cpp +++ b/libraries/Ethernet/src/Dns.cpp @@ -55,7 +55,7 @@ void DNSClient::begin(const IPAddress& aDNSServer) } -int DNSClient::inet_aton(const char* aIPAddrString, IPAddress& aResult) +int DNSClient::inet_aton_ethlib(const char* aIPAddrString, IPAddress& aResult) { // See if we've been given a valid IP address const char* p =aIPAddrString; @@ -120,7 +120,7 @@ int DNSClient::getHostByName(const char* aHostname, IPAddress& aResult) int ret =0; // See if it's a numeric IP address - if (inet_aton(aHostname, aResult)) + if (inet_aton_ethlib(aHostname, aResult)) { // It is, our work here is done return 1; diff --git a/libraries/Ethernet/src/Dns.h b/libraries/Ethernet/src/Dns.h index 6bcb98ab9..aa7212f70 100644 --- a/libraries/Ethernet/src/Dns.h +++ b/libraries/Ethernet/src/Dns.h @@ -19,7 +19,7 @@ public: @result 1 if aIPAddrString was successfully converted to an IP address, else error code */ - int inet_aton(const char *aIPAddrString, IPAddress& aResult); + int inet_aton_ethlib(const char *aIPAddrString, IPAddress& aResult); /** Resolve the given hostname to an IP address. @param aHostname Name to be resolved