@@ -87,13 +87,15 @@ class IPAddress: public Printable {
87
87
88
88
// Overloaded cast operator to allow IPAddress objects to be used where a pointer
89
89
// 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 ; }
93
94
94
- // the above uint32_t() cast can be ambiguous
95
- // if gcc complains, use instead isSet() or v4() according to what's relevant
96
95
bool isSet () const ;
96
+ operator bool () const { return isSet (); } // <-
97
+ operator bool () { return isSet (); } // <- both are needed
98
+
97
99
// generic IPv4 wrapper to uint32-view like arduino loves to see it
98
100
const u32_t & v4 () const { return ip_2_ip4 (&_ip)->addr ; } // for raw_address(const)
99
101
u32_t & v4 () { return ip_2_ip4 (&_ip)->addr ; }
@@ -118,6 +120,10 @@ class IPAddress: public Printable {
118
120
}
119
121
bool operator ==(const uint8_t * addr) const ;
120
122
123
+ int operator >>(int n) const {
124
+ return isV4 ()? v4 () >> n: 0 ;
125
+ }
126
+
121
127
// Overloaded index operator to allow getting and setting individual octets of the address
122
128
uint8_t operator [](int index) const {
123
129
return isV4 ()? *(raw_address () + index ): 0 ;
@@ -155,6 +161,9 @@ class IPAddress: public Printable {
155
161
IPAddress (const ipv4_addr& fw_addr) { setV4 (); v4 () = fw_addr.addr ; }
156
162
IPAddress (const ipv4_addr* fw_addr) { setV4 (); v4 () = fw_addr->addr ; }
157
163
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
+
158
167
operator ip_addr_t () const { return _ip; }
159
168
operator const ip_addr_t *() const { return &_ip; }
160
169
operator ip_addr_t *() { return &_ip; }
@@ -169,6 +178,9 @@ class IPAddress: public Printable {
169
178
IPAddress (const ip_addr_t & lwip_addr) { ip_addr_copy (_ip, lwip_addr); }
170
179
IPAddress (const ip_addr_t * lwip_addr) { ip_addr_copy (_ip, *lwip_addr); }
171
180
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
+
172
184
uint16_t * raw6 ()
173
185
{
174
186
setV6 ();
0 commit comments