Skip to content
Snippets Groups Projects
Commit ef5447e3 authored by Guillaume Roguez's avatar Guillaume Roguez Committed by gerrit2
Browse files

ip_utils: fix IP comparaison

Comparing two IP was broken.
If you try "ip1 != ip2" this always return false whatever be
ip1 and ip2.
The operator!= is not called in fact, because ip1 and ip2 were
converted by operator bool() first!

This patch resolves that by:
- mark explicit operator bool()
- declare operator!= as the opposite of operator==

Note: these latest operators have been externalized of the class
as a good C++ practice.

Change-Id: I65d01c391d3871e92bd0d2a49cad3cfa62f698cf
Tuleap: #662
parent cb0ea36b
No related branches found
No related tags found
Loading
...@@ -104,12 +104,8 @@ public: ...@@ -104,12 +104,8 @@ public:
addr.addr.sa_family = AF_UNSPEC; addr.addr.sa_family = AF_UNSPEC;
} }
inline bool operator==(const IpAddr& other) const {
return pj_sockaddr_cmp(&addr, &other.addr) == 0;
}
// Is defined // Is defined
inline operator bool() const { inline explicit operator bool() const {
return isIpv4() or isIpv6(); return isIpv4() or isIpv6();
} }
...@@ -226,6 +222,10 @@ private: ...@@ -226,6 +222,10 @@ private:
pj_sockaddr addr; pj_sockaddr addr;
}; };
// IpAddr helpers
inline bool operator==(const IpAddr& lhs, const IpAddr& rhs) { return !pj_sockaddr_cmp(&lhs, &rhs); }
inline bool operator!=(const IpAddr& lhs, const IpAddr& rhs) { return !(lhs == rhs); }
namespace ip_utils { namespace ip_utils {
static const char *const DEFAULT_INTERFACE = "default"; static const char *const DEFAULT_INTERFACE = "default";
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment