Skip to content

more compatibility fixes for IPAddress, restore INADDR_ANY, INADDR_NONE #5416

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Dec 3, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions cores/esp8266/IPAddress.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ IPAddress::IPAddress(uint8_t first_octet, uint8_t second_octet, uint8_t third_oc
(*this)[3] = fourth_octet;
}

IPAddress::IPAddress(uint32_t address) {
void IPAddress::ctor32(uint32_t address) {
setV4();
v4() = address;
}
Expand Down Expand Up @@ -172,7 +172,8 @@ bool IPAddress::isValid(const char* arg) {
return IPAddress().fromString(arg);
}

CONST IPAddress IPNoAddress; // generic "0.0.0.0" for v4 & v6
CONST IPAddress INADDR_ANY; // generic "0.0.0.0" for IPv4 & IPv6
const IPAddress INADDR_NONE(255,255,255,255);

/**************************************/

Expand Down
10 changes: 7 additions & 3 deletions cores/esp8266/IPAddress.h
Original file line number Diff line number Diff line change
Expand Up @@ -67,11 +67,15 @@ class IPAddress: public Printable {
return reinterpret_cast<const uint8_t*>(&v4());
}

void ctor32 (uint32_t);

public:
// Constructors
IPAddress();
IPAddress(uint8_t first_octet, uint8_t second_octet, uint8_t third_octet, uint8_t fourth_octet);
IPAddress(uint32_t address);
IPAddress(uint32_t address) { ctor32(address); }
IPAddress(u32_t address) { ctor32(address); }
IPAddress(int address) { ctor32(address); }
IPAddress(const uint8_t *address);

bool fromString(const char *address);
Expand Down Expand Up @@ -200,9 +204,9 @@ class IPAddress: public Printable {

};

extern CONST IPAddress IPNoAddress;
extern CONST IPAddress INADDR_ANY;
extern const IPAddress INADDR_NONE;

#include <lwip/inet.h> // bring definition of INADDR_NONE
#include <AddrList.h> // bring interface iterator

#endif
4 changes: 2 additions & 2 deletions libraries/ESP8266WiFi/src/WiFiUdp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ void WiFiUDP::flush()
IPAddress WiFiUDP::remoteIP() const
{
if (!_ctx)
return IPNoAddress;
return INADDR_ANY;

return _ctx->getRemoteAddress();
}
Expand All @@ -250,7 +250,7 @@ uint16_t WiFiUDP::remotePort() const
IPAddress WiFiUDP::destinationIP() const
{
if (!_ctx)
return IPNoAddress;
return INADDR_ANY;

return _ctx->getDestAddress();
}
Expand Down
2 changes: 1 addition & 1 deletion libraries/Ethernet/src/Dns.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ int DNSClient::getHostByName(const char* aHostname, IPAddress& aResult)
}

// Check we've got a valid DNS server to use
if (iDNSServer == IPNoAddress)
if (iDNSServer == INADDR_NONE || iDNSServer == INADDR_ANY)
{
return INVALID_SERVER;
}
Expand Down