From: Pieter Lexis Date: Wed, 24 Feb 2016 13:18:44 +0000 (+0100) Subject: ComboAddress: add '!=' operator X-Git-Tag: rec-4.0.0-alpha2~25^2~3 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=bb6f86bd1bab87c807b89783908c660c6968fd8d;p=thirdparty%2Fpdns.git ComboAddress: add '!=' operator And tests. --- diff --git a/pdns/iputils.hh b/pdns/iputils.hh index abdc4e96f0..3e975cabc4 100644 --- a/pdns/iputils.hh +++ b/pdns/iputils.hh @@ -93,6 +93,11 @@ union ComboAddress { return memcmp(&sin6.sin6_addr.s6_addr, &rhs.sin6.sin6_addr.s6_addr, 16)==0; } + bool operator!=(const ComboAddress& rhs) const + { + return(!operator==(rhs)); + } + bool operator<(const ComboAddress& rhs) const { if(boost::tie(sin4.sin_family, sin4.sin_port) < boost::tie(rhs.sin4.sin_family, rhs.sin4.sin_port)) diff --git a/pdns/test-iputils_hh.cc b/pdns/test-iputils_hh.cc index 37e09bd8bf..a8243f0663 100644 --- a/pdns/test-iputils_hh.cc +++ b/pdns/test-iputils_hh.cc @@ -39,6 +39,17 @@ BOOST_AUTO_TEST_CASE(test_ComboAddress) { ComboAddress a = ComboAddress(); ComboAddress b = ComboAddress(); BOOST_CHECK(a == b); + + // Verify that 2 ComboAddresses are not the same + ComboAddress c = ComboAddress("127.0.0.1:53"); + ComboAddress d = ComboAddress("127.0.0.1:52"); + ComboAddress e = ComboAddress("127.0.0.2:53"); + + BOOST_CHECK(a != c); + BOOST_CHECK(c != d); + BOOST_CHECK(c != e); + BOOST_CHECK(d != e); + BOOST_CHECK(!(a != b)); } BOOST_AUTO_TEST_CASE(test_ComboAddressTruncate) {