{
public:
//! If this IP address is matched by any of the classes within
+
bool match(const ComboAddress *ip)
{
for(container_t::const_iterator i=d_masks.begin();i!=d_masks.end();++i)
return false;
}
+
+ bool match(const ComboAddress& ip)
+ {
+ return match(&ip);
+ }
+
//! Add this Netmask to the list of possible matches
void addMask(const string &ip)
{
BOOST_CHECK(!(local == remote));
}
+BOOST_AUTO_TEST_CASE(test_Netmask) {
+ ComboAddress local("127.0.0.1", 53);
+ ComboAddress remote("130.161.252.29", 53);
+
+ Netmask nm("127.0.0.1/24");
+ BOOST_CHECK(nm.match(local));
+ BOOST_CHECK(!nm.match(remote));
+
+ Netmask nm6("fe80::92fb:a6ff:fe4a:51da/64");
+ BOOST_CHECK(nm6.match("fe80::92fb:a6ff:fe4a:51db"));
+ BOOST_CHECK(!nm6.match("fe81::92fb:a6ff:fe4a:51db"));
+
+ Netmask nmp("130.161.252.29/32");
+ BOOST_CHECK(nmp.match(remote));
+
+ Netmask nmp6("fe80::92fb:a6ff:fe4a:51da/128");
+ BOOST_CHECK(nmp6.match("fe80::92fb:a6ff:fe4a:51da"));
+ BOOST_CHECK(!nmp6.match("fe81::92fb:a6ff:fe4a:51db"));
+
+ Netmask all("0.0.0.0/0");
+ BOOST_CHECK(all.match(local) && all.match(remote));
+
+ Netmask all6("::/0");
+ BOOST_CHECK(all6.match("::1") && all6.match("fe80::92fb:a6ff:fe4a:51da"));
+}
+
+BOOST_AUTO_TEST_CASE(test_NetmaskGroup) {
+ NetmaskGroup ng;
+ ng.addMask("127.0.0.0/8");
+ ng.addMask("10.0.0.0/24");
+ BOOST_CHECK(ng.match(ComboAddress("127.0.0.1")));
+ BOOST_CHECK(ng.match(ComboAddress("10.0.0.3")));
+ BOOST_CHECK(!ng.match(ComboAddress("128.1.2.3")));
+ BOOST_CHECK(!ng.match(ComboAddress("10.0.1.0")));
+ BOOST_CHECK(!ng.match(ComboAddress("::1")));
+ ng.addMask("::1");
+ BOOST_CHECK(ng.match(ComboAddress("::1")));
+ BOOST_CHECK(!ng.match(ComboAddress("::2")));
+ ng.addMask("fe80::/16");
+ BOOST_CHECK(ng.match(ComboAddress("fe80::1")));
+ BOOST_CHECK(!ng.match(ComboAddress("fe81::1")));
+}
+
+
BOOST_AUTO_TEST_SUITE_END()