[[nodiscard]] bool isUnspecified() const
{
+ const auto compare = ComboAddress::addressOnlyEqual();
const ComboAddress unspecifiedV4("0.0.0.0:0");
const ComboAddress unspecifiedV6("[::]:0");
- return *this == unspecifiedV4 || *this == unspecifiedV6;
+ return compare(*this, unspecifiedV4) || compare(*this, unspecifiedV6);
}
[[nodiscard]] ComboAddress mapToIPv4() const
}
}
+BOOST_AUTO_TEST_CASE(test_unspecified)
+{
+ struct {
+ std::string str;
+ bool unspecified;
+ } tests[] = {
+ { "0.0.0.0:0", true },
+ { "[::]:0", true },
+ { "0.0.0.0:853", true },
+ { "[::]:853", true },
+ { "192.0.2.1:0", false },
+ { "192.0.2.1:853", false },
+ { "[2001:db8::1]:0", false },
+ { "[2001:db8::1]:853", false },
+ };
+
+ for (const auto& test : tests) {
+ const ComboAddress address(test.str);
+ BOOST_CHECK_EQUAL(address.isUnspecified(), test.unspecified);
+ }
+}
+
BOOST_AUTO_TEST_SUITE_END()