Skip to content

Commit 324b3f9

Browse files
d-a-vdevyte
authored andcommitted
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
1 parent 4b16fa0 commit 324b3f9

File tree

3 files changed

+16
-6
lines changed

3 files changed

+16
-6
lines changed

cores/esp8266/IPAddress.h

+13-3
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,12 @@
3838
#define IP4_ADDR_ANY4 IPADDR_ANY
3939
#define IPADDR4_INIT(x) { x }
4040
#define CONST /* nothing: lwIP-v1 does not use const */
41-
#else
41+
#else // lwIP-v2+
4242
#define CONST const
43-
#endif
43+
#if !LWIP_IPV6
44+
#define ip_addr ipv4_addr
45+
#endif // !LWIP_IPV6
46+
#endif // lwIP-v2+
4447

4548
// A class to make it easier to handle and pass around IP addresses
4649
// IPv6 update:
@@ -96,9 +99,15 @@ class IPAddress: public Printable {
9699
bool operator==(uint32_t addr) const {
97100
return isV4() && v4() == addr;
98101
}
102+
bool operator==(u32_t addr) const {
103+
return isV4() && v4() == addr;
104+
}
99105
bool operator!=(uint32_t addr) const {
100106
return !(isV4() && v4() == addr);
101107
}
108+
bool operator!=(u32_t addr) const {
109+
return !(isV4() && v4() == addr);
110+
}
102111
bool operator==(const uint8_t* addr) const;
103112

104113
// Overloaded index operator to allow getting and setting individual octets of the address
@@ -193,6 +202,7 @@ class IPAddress: public Printable {
193202

194203
extern CONST IPAddress IPNoAddress;
195204

196-
#include <AddrList.h>
205+
#include <lwip/inet.h> // bring definition of INADDR_NONE
206+
#include <AddrList.h> // bring interface iterator
197207

198208
#endif

libraries/Ethernet/src/Dns.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ void DNSClient::begin(const IPAddress& aDNSServer)
5555
}
5656

5757

58-
int DNSClient::inet_aton(const char* aIPAddrString, IPAddress& aResult)
58+
int DNSClient::inet_aton_ethlib(const char* aIPAddrString, IPAddress& aResult)
5959
{
6060
// See if we've been given a valid IP address
6161
const char* p =aIPAddrString;
@@ -120,7 +120,7 @@ int DNSClient::getHostByName(const char* aHostname, IPAddress& aResult)
120120
int ret =0;
121121

122122
// See if it's a numeric IP address
123-
if (inet_aton(aHostname, aResult))
123+
if (inet_aton_ethlib(aHostname, aResult))
124124
{
125125
// It is, our work here is done
126126
return 1;

libraries/Ethernet/src/Dns.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ class DNSClient
1919
@result 1 if aIPAddrString was successfully converted to an IP address,
2020
else error code
2121
*/
22-
int inet_aton(const char *aIPAddrString, IPAddress& aResult);
22+
int inet_aton_ethlib(const char *aIPAddrString, IPAddress& aResult);
2323

2424
/** Resolve the given hostname to an IP address.
2525
@param aHostname Name to be resolved

0 commit comments

Comments
 (0)