From 7763473803db5f82417a75ea12bdcf5441229a41 Mon Sep 17 00:00:00 2001 From: david gauchard Date: Mon, 28 Jan 2019 00:27:39 +0100 Subject: [PATCH 1/5] fix testing IPAddress validity +add new operator= --- cores/esp8266/IPAddress.h | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/cores/esp8266/IPAddress.h b/cores/esp8266/IPAddress.h index e93e6cc3c4..7a8367edf6 100644 --- a/cores/esp8266/IPAddress.h +++ b/cores/esp8266/IPAddress.h @@ -84,9 +84,11 @@ class IPAddress: public Printable { // Overloaded cast operator to allow IPAddress objects to be used where a pointer // to a four-byte uint8_t array is expected - operator uint32_t() const { - return isV4()? v4(): (uint32_t)0; - } + operator uint32_t() const { return isV4()? v4(): (uint32_t)0; } + operator uint32_t() { return isV4()? v4(): (uint32_t)0; } + + operator bool () const { return isSet(); } // <- + operator bool () { return isSet(); } // <- both are needed // the above uint32_t() cast can be ambiguous // if gcc complains, use instead isSet() or v4() according to what's relevant @@ -152,6 +154,9 @@ class IPAddress: public Printable { IPAddress(const ipv4_addr& fw_addr) { setV4(); v4() = fw_addr.addr; } IPAddress(const ipv4_addr* fw_addr) { setV4(); v4() = fw_addr->addr; } + IPAddress& operator=(const ipv4_addr& fw_addr) { setV4(); v4() = fw_addr.addr; return *this; } + IPAddress& operator=(const ipv4_addr* fw_addr) { setV4(); v4() = fw_addr->addr; return *this; } + operator ip_addr_t () const { return _ip; } operator const ip_addr_t*() const { return &_ip; } operator ip_addr_t*() { return &_ip; } @@ -166,6 +171,9 @@ class IPAddress: public Printable { IPAddress(const ip_addr_t& lwip_addr) { ip_addr_copy(_ip, lwip_addr); } IPAddress(const ip_addr_t* lwip_addr) { ip_addr_copy(_ip, *lwip_addr); } + IPAddress& operator=(const ip_addr_t& lwip_addr) { ip_addr_copy(_ip, lwip_addr); return *this; } + IPAddress& operator=(const ip_addr_t* lwip_addr) { ip_addr_copy(_ip, *lwip_addr); return *this; } + uint16_t* raw6() { setV6(); From b8195537ef37595933d63c52f43e95c95220d157 Mon Sep 17 00:00:00 2001 From: David Gauchard Date: Mon, 28 Jan 2019 14:51:49 +0100 Subject: [PATCH 2/5] +cast to u32_t --- cores/esp8266/IPAddress.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/cores/esp8266/IPAddress.h b/cores/esp8266/IPAddress.h index 7a8367edf6..ae0626f5d3 100644 --- a/cores/esp8266/IPAddress.h +++ b/cores/esp8266/IPAddress.h @@ -86,6 +86,8 @@ class IPAddress: public Printable { // to a four-byte uint8_t array is expected operator uint32_t() const { return isV4()? v4(): (uint32_t)0; } operator uint32_t() { return isV4()? v4(): (uint32_t)0; } + operator u32_t() const { return isV4()? v4(): (u32_t)0; } + operator u32_t() { return isV4()? v4(): (u32_t)0; } operator bool () const { return isSet(); } // <- operator bool () { return isSet(); } // <- both are needed From 449076d58d1a116efa44b39bf85cdf8d6ee42bba Mon Sep 17 00:00:00 2001 From: David Gauchard Date: Mon, 28 Jan 2019 15:03:52 +0100 Subject: [PATCH 3/5] + cast to int --- cores/esp8266/IPAddress.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/cores/esp8266/IPAddress.h b/cores/esp8266/IPAddress.h index ae0626f5d3..ac2f7bc4ce 100644 --- a/cores/esp8266/IPAddress.h +++ b/cores/esp8266/IPAddress.h @@ -88,6 +88,8 @@ class IPAddress: public Printable { operator uint32_t() { return isV4()? v4(): (uint32_t)0; } operator u32_t() const { return isV4()? v4(): (u32_t)0; } operator u32_t() { return isV4()? v4(): (u32_t)0; } + operator int() const { return isV4()? v4(): (int)0; } + operator int() { return isV4()? v4(): (int)0; } operator bool () const { return isSet(); } // <- operator bool () { return isSet(); } // <- both are needed From 3cf7a04c7727815f5bb4f7857342d583d368011a Mon Sep 17 00:00:00 2001 From: David Gauchard Date: Mon, 28 Jan 2019 15:22:47 +0100 Subject: [PATCH 4/5] + operator >> --- cores/esp8266/IPAddress.h | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/cores/esp8266/IPAddress.h b/cores/esp8266/IPAddress.h index ac2f7bc4ce..748caf9b52 100644 --- a/cores/esp8266/IPAddress.h +++ b/cores/esp8266/IPAddress.h @@ -91,12 +91,10 @@ class IPAddress: public Printable { operator int() const { return isV4()? v4(): (int)0; } operator int() { return isV4()? v4(): (int)0; } + bool isSet () const; operator bool () const { return isSet(); } // <- operator bool () { return isSet(); } // <- both are needed - // the above uint32_t() cast can be ambiguous - // if gcc complains, use instead isSet() or v4() according to what's relevant - bool isSet () const; // generic IPv4 wrapper to uint32-view like arduino loves to see it const u32_t& v4() const { return ip_2_ip4(&_ip)->addr; } // for raw_address(const) u32_t& v4() { return ip_2_ip4(&_ip)->addr; } @@ -121,6 +119,10 @@ class IPAddress: public Printable { } bool operator==(const uint8_t* addr) const; + int operator>>(int n) const { + return isV4()? v4() >> n: 0; + } + // Overloaded index operator to allow getting and setting individual octets of the address uint8_t operator[](int index) const { return isV4()? *(raw_address() + index): 0; From 6046d74bbf914fa339a750fbe446c25d56600c94 Mon Sep 17 00:00:00 2001 From: David Gauchard Date: Mon, 28 Jan 2019 15:36:17 +0100 Subject: [PATCH 5/5] remove useless cast --- cores/esp8266/IPAddress.h | 2 -- 1 file changed, 2 deletions(-) diff --git a/cores/esp8266/IPAddress.h b/cores/esp8266/IPAddress.h index 748caf9b52..7354c8656a 100644 --- a/cores/esp8266/IPAddress.h +++ b/cores/esp8266/IPAddress.h @@ -88,8 +88,6 @@ class IPAddress: public Printable { operator uint32_t() { return isV4()? v4(): (uint32_t)0; } operator u32_t() const { return isV4()? v4(): (u32_t)0; } operator u32_t() { return isV4()? v4(): (u32_t)0; } - operator int() const { return isV4()? v4(): (int)0; } - operator int() { return isV4()? v4(): (int)0; } bool isSet () const; operator bool () const { return isSet(); } // <-