@@ -87,13 +87,15 @@ class IPAddress: public Printable {
8787
8888 // Overloaded cast operator to allow IPAddress objects to be used where a pointer
8989 // to a four-byte uint8_t array is expected
90- operator uint32_t () const {
91- return isV4 ()? v4 (): (uint32_t )0 ;
92- }
90+ operator uint32_t () const { return isV4 ()? v4 (): (uint32_t )0 ; }
91+ operator uint32_t () { return isV4 ()? v4 (): (uint32_t )0 ; }
92+ operator u32_t () const { return isV4 ()? v4 (): (u32_t )0 ; }
93+ operator u32_t () { return isV4 ()? v4 (): (u32_t )0 ; }
9394
94- // the above uint32_t() cast can be ambiguous
95- // if gcc complains, use instead isSet() or v4() according to what's relevant
9695 bool isSet () const ;
96+ operator bool () const { return isSet (); } // <-
97+ operator bool () { return isSet (); } // <- both are needed
98+
9799 // generic IPv4 wrapper to uint32-view like arduino loves to see it
98100 const u32_t & v4 () const { return ip_2_ip4 (&_ip)->addr ; } // for raw_address(const)
99101 u32_t & v4 () { return ip_2_ip4 (&_ip)->addr ; }
@@ -118,6 +120,10 @@ class IPAddress: public Printable {
118120 }
119121 bool operator ==(const uint8_t * addr) const ;
120122
123+ int operator >>(int n) const {
124+ return isV4 ()? v4 () >> n: 0 ;
125+ }
126+
121127 // Overloaded index operator to allow getting and setting individual octets of the address
122128 uint8_t operator [](int index) const {
123129 return isV4 ()? *(raw_address () + index): 0 ;
@@ -155,6 +161,9 @@ class IPAddress: public Printable {
155161 IPAddress (const ipv4_addr& fw_addr) { setV4 (); v4 () = fw_addr.addr ; }
156162 IPAddress (const ipv4_addr* fw_addr) { setV4 (); v4 () = fw_addr->addr ; }
157163
164+ IPAddress& operator =(const ipv4_addr& fw_addr) { setV4 (); v4 () = fw_addr.addr ; return *this ; }
165+ IPAddress& operator =(const ipv4_addr* fw_addr) { setV4 (); v4 () = fw_addr->addr ; return *this ; }
166+
158167 operator ip_addr_t () const { return _ip; }
159168 operator const ip_addr_t *() const { return &_ip; }
160169 operator ip_addr_t *() { return &_ip; }
@@ -169,6 +178,9 @@ class IPAddress: public Printable {
169178 IPAddress (const ip_addr_t & lwip_addr) { ip_addr_copy (_ip, lwip_addr); }
170179 IPAddress (const ip_addr_t * lwip_addr) { ip_addr_copy (_ip, *lwip_addr); }
171180
181+ IPAddress& operator =(const ip_addr_t & lwip_addr) { ip_addr_copy (_ip, lwip_addr); return *this ; }
182+ IPAddress& operator =(const ip_addr_t * lwip_addr) { ip_addr_copy (_ip, *lwip_addr); return *this ; }
183+
172184 uint16_t * raw6 ()
173185 {
174186 setV6 ();
0 commit comments