File tree Expand file tree Collapse file tree 2 files changed +31
-0
lines changed
features/net/network-socket Expand file tree Collapse file tree 2 files changed +31
-0
lines changed Original file line number Diff line number Diff line change @@ -258,6 +258,25 @@ SocketAddress::operator bool() const
258
258
return false ;
259
259
}
260
260
261
+ bool operator ==(const SocketAddress &a, const SocketAddress &b)
262
+ {
263
+ int count = 0 ;
264
+ if (a._addr .version == NSAPI_IPv4 && b._addr .version == NSAPI_IPv4) {
265
+ count = NSAPI_IPv4_BYTES;
266
+ } else if (a._addr .version == NSAPI_IPv6 && b._addr .version == NSAPI_IPv6) {
267
+ count = NSAPI_IPv6_BYTES;
268
+ } else {
269
+ return false ;
270
+ }
271
+
272
+ return (memcmp (a._addr .bytes , b._addr .bytes , count) == 0 );
273
+ }
274
+
275
+ bool operator !=(const SocketAddress &a, const SocketAddress &b)
276
+ {
277
+ return !(a == b);
278
+ }
279
+
261
280
void SocketAddress::_SocketAddress (NetworkStack *iface, const char *host, uint16_t port)
262
281
{
263
282
_ip_address[0 ] = ' \0 ' ;
Original file line number Diff line number Diff line change @@ -137,6 +137,18 @@ class SocketAddress {
137
137
*/
138
138
operator bool () const ;
139
139
140
+ /* * Compare two addresses for equality
141
+ *
142
+ * @return True if both addresses are equal
143
+ */
144
+ friend bool operator ==(const SocketAddress &a, const SocketAddress &b);
145
+
146
+ /* * Compare two addresses for equality
147
+ *
148
+ * @return True if both addresses are not equal
149
+ */
150
+ friend bool operator !=(const SocketAddress &a, const SocketAddress &b);
151
+
140
152
private:
141
153
void _SocketAddress (NetworkStack *iface, const char *host, uint16_t port);
142
154
You can’t perform that action at this time.
0 commit comments