35
35
#define IP_IS_V4_VAL (x ) (1 )
36
36
#define IP_SET_TYPE_VAL (x,y ) do { (void )0 ; } while (0 )
37
37
#define IP_ANY_TYPE (&ip_addr_any)
38
+ #define IP4_ADDR_ANY IPADDR_ANY
38
39
#define IP4_ADDR_ANY4 IPADDR_ANY
39
40
#define IPADDR4_INIT (x ) { x }
40
41
#define CONST /* nothing: lwIP-v1 does not use const */
42
+ #define ip4_addr_netcmp ip_addr_netcmp
43
+ #define netif_dhcp_data (netif ) ((netif)->dhcp)
41
44
#else // lwIP-v2+
42
45
#define CONST const
43
46
#if !LWIP_IPV6
@@ -84,13 +87,15 @@ class IPAddress: public Printable {
84
87
85
88
// Overloaded cast operator to allow IPAddress objects to be used where a pointer
86
89
// to a four-byte uint8_t array is expected
87
- operator uint32_t () const {
88
- return isV4 ()? v4 (): (uint32_t )0 ;
89
- }
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 ; }
90
94
91
- // the above uint32_t() cast can be ambiguous
92
- // if gcc complains, use instead isSet() or v4() according to what's relevant
93
95
bool isSet () const ;
96
+ operator bool () const { return isSet (); } // <-
97
+ operator bool () { return isSet (); } // <- both are needed
98
+
94
99
// generic IPv4 wrapper to uint32-view like arduino loves to see it
95
100
const u32_t & v4 () const { return ip_2_ip4 (&_ip)->addr ; } // for raw_address(const)
96
101
u32_t & v4 () { return ip_2_ip4 (&_ip)->addr ; }
@@ -115,6 +120,10 @@ class IPAddress: public Printable {
115
120
}
116
121
bool operator ==(const uint8_t * addr) const ;
117
122
123
+ int operator >>(int n) const {
124
+ return isV4 ()? v4 () >> n: 0 ;
125
+ }
126
+
118
127
// Overloaded index operator to allow getting and setting individual octets of the address
119
128
uint8_t operator [](int index) const {
120
129
return isV4 ()? *(raw_address () + index ): 0 ;
@@ -152,6 +161,9 @@ class IPAddress: public Printable {
152
161
IPAddress (const ipv4_addr& fw_addr) { setV4 (); v4 () = fw_addr.addr ; }
153
162
IPAddress (const ipv4_addr* fw_addr) { setV4 (); v4 () = fw_addr->addr ; }
154
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
+
155
167
operator ip_addr_t () const { return _ip; }
156
168
operator const ip_addr_t *() const { return &_ip; }
157
169
operator ip_addr_t *() { return &_ip; }
@@ -166,6 +178,9 @@ class IPAddress: public Printable {
166
178
IPAddress (const ip_addr_t & lwip_addr) { ip_addr_copy (_ip, lwip_addr); }
167
179
IPAddress (const ip_addr_t * lwip_addr) { ip_addr_copy (_ip, *lwip_addr); }
168
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
+
169
184
uint16_t * raw6 ()
170
185
{
171
186
setV6 ();
0 commit comments