2015-12-13 17:58:29 +01:00
|
|
|
// Copyright (c) 2012-2015 The Bitcoin Core developers
|
2014-12-13 05:09:33 +01:00
|
|
|
// Distributed under the MIT software license, see the accompanying
|
2014-03-18 10:11:00 +01:00
|
|
|
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
|
|
|
|
2013-04-13 07:13:08 +02:00
|
|
|
#include "netbase.h"
|
2015-03-12 09:34:42 +01:00
|
|
|
#include "test/test_bitcoin.h"
|
2012-06-08 18:42:05 +02:00
|
|
|
|
|
|
|
#include <string>
|
|
|
|
|
2015-08-19 20:34:56 +02:00
|
|
|
#include <boost/assign/list_of.hpp>
|
2013-04-13 07:13:08 +02:00
|
|
|
#include <boost/test/unit_test.hpp>
|
2012-06-08 18:42:05 +02:00
|
|
|
|
|
|
|
using namespace std;
|
|
|
|
|
2015-03-12 09:34:42 +01:00
|
|
|
BOOST_FIXTURE_TEST_SUITE(netbase_tests, BasicTestingSetup)
|
2012-06-08 18:42:05 +02:00
|
|
|
|
2016-05-31 19:05:52 +02:00
|
|
|
static CNetAddr ResolveIP(const char* ip)
|
|
|
|
{
|
|
|
|
CNetAddr addr;
|
|
|
|
LookupHost(ip, addr, false);
|
|
|
|
return addr;
|
|
|
|
}
|
|
|
|
|
2016-05-31 21:50:24 +02:00
|
|
|
static CSubNet ResolveSubNet(const char* subnet)
|
|
|
|
{
|
|
|
|
CSubNet ret;
|
|
|
|
LookupSubNet(subnet, ret);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2012-06-08 18:42:05 +02:00
|
|
|
BOOST_AUTO_TEST_CASE(netbase_networks)
|
|
|
|
{
|
2016-05-31 19:05:52 +02:00
|
|
|
BOOST_CHECK(ResolveIP("127.0.0.1").GetNetwork() == NET_UNROUTABLE);
|
|
|
|
BOOST_CHECK(ResolveIP("::1").GetNetwork() == NET_UNROUTABLE);
|
|
|
|
BOOST_CHECK(ResolveIP("8.8.8.8").GetNetwork() == NET_IPV4);
|
|
|
|
BOOST_CHECK(ResolveIP("2001::8888").GetNetwork() == NET_IPV6);
|
|
|
|
BOOST_CHECK(ResolveIP("FD87:D87E:EB43:edb1:8e4:3588:e546:35ca").GetNetwork() == NET_TOR);
|
|
|
|
|
2012-06-08 18:42:05 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
BOOST_AUTO_TEST_CASE(netbase_properties)
|
|
|
|
{
|
2016-05-31 19:05:52 +02:00
|
|
|
|
|
|
|
BOOST_CHECK(ResolveIP("127.0.0.1").IsIPv4());
|
|
|
|
BOOST_CHECK(ResolveIP("::FFFF:192.168.1.1").IsIPv4());
|
|
|
|
BOOST_CHECK(ResolveIP("::1").IsIPv6());
|
|
|
|
BOOST_CHECK(ResolveIP("10.0.0.1").IsRFC1918());
|
|
|
|
BOOST_CHECK(ResolveIP("192.168.1.1").IsRFC1918());
|
|
|
|
BOOST_CHECK(ResolveIP("172.31.255.255").IsRFC1918());
|
|
|
|
BOOST_CHECK(ResolveIP("2001:0DB8::").IsRFC3849());
|
|
|
|
BOOST_CHECK(ResolveIP("169.254.1.1").IsRFC3927());
|
|
|
|
BOOST_CHECK(ResolveIP("2002::1").IsRFC3964());
|
|
|
|
BOOST_CHECK(ResolveIP("FC00::").IsRFC4193());
|
|
|
|
BOOST_CHECK(ResolveIP("2001::2").IsRFC4380());
|
|
|
|
BOOST_CHECK(ResolveIP("2001:10::").IsRFC4843());
|
|
|
|
BOOST_CHECK(ResolveIP("FE80::").IsRFC4862());
|
|
|
|
BOOST_CHECK(ResolveIP("64:FF9B::").IsRFC6052());
|
|
|
|
BOOST_CHECK(ResolveIP("FD87:D87E:EB43:edb1:8e4:3588:e546:35ca").IsTor());
|
|
|
|
BOOST_CHECK(ResolveIP("127.0.0.1").IsLocal());
|
|
|
|
BOOST_CHECK(ResolveIP("::1").IsLocal());
|
|
|
|
BOOST_CHECK(ResolveIP("8.8.8.8").IsRoutable());
|
|
|
|
BOOST_CHECK(ResolveIP("2001::1").IsRoutable());
|
|
|
|
BOOST_CHECK(ResolveIP("127.0.0.1").IsValid());
|
|
|
|
|
2012-06-08 18:42:05 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
bool static TestSplitHost(string test, string host, int port)
|
|
|
|
{
|
|
|
|
string hostOut;
|
|
|
|
int portOut = -1;
|
|
|
|
SplitHostPort(test, portOut, hostOut);
|
|
|
|
return hostOut == host && port == portOut;
|
|
|
|
}
|
|
|
|
|
|
|
|
BOOST_AUTO_TEST_CASE(netbase_splithost)
|
|
|
|
{
|
|
|
|
BOOST_CHECK(TestSplitHost("www.bitcoin.org", "www.bitcoin.org", -1));
|
|
|
|
BOOST_CHECK(TestSplitHost("[www.bitcoin.org]", "www.bitcoin.org", -1));
|
|
|
|
BOOST_CHECK(TestSplitHost("www.bitcoin.org:80", "www.bitcoin.org", 80));
|
|
|
|
BOOST_CHECK(TestSplitHost("[www.bitcoin.org]:80", "www.bitcoin.org", 80));
|
|
|
|
BOOST_CHECK(TestSplitHost("127.0.0.1", "127.0.0.1", -1));
|
|
|
|
BOOST_CHECK(TestSplitHost("127.0.0.1:8333", "127.0.0.1", 8333));
|
|
|
|
BOOST_CHECK(TestSplitHost("[127.0.0.1]", "127.0.0.1", -1));
|
|
|
|
BOOST_CHECK(TestSplitHost("[127.0.0.1]:8333", "127.0.0.1", 8333));
|
|
|
|
BOOST_CHECK(TestSplitHost("::ffff:127.0.0.1", "::ffff:127.0.0.1", -1));
|
|
|
|
BOOST_CHECK(TestSplitHost("[::ffff:127.0.0.1]:8333", "::ffff:127.0.0.1", 8333));
|
|
|
|
BOOST_CHECK(TestSplitHost("[::]:8333", "::", 8333));
|
|
|
|
BOOST_CHECK(TestSplitHost("::8333", "::8333", -1));
|
|
|
|
BOOST_CHECK(TestSplitHost(":8333", "", 8333));
|
|
|
|
BOOST_CHECK(TestSplitHost("[]:8333", "", 8333));
|
|
|
|
BOOST_CHECK(TestSplitHost("", "", -1));
|
|
|
|
}
|
|
|
|
|
|
|
|
bool static TestParse(string src, string canon)
|
|
|
|
{
|
2016-08-04 22:37:49 +02:00
|
|
|
CService addr(LookupNumeric(src.c_str(), 65535));
|
2012-06-08 18:42:05 +02:00
|
|
|
return canon == addr.ToString();
|
|
|
|
}
|
|
|
|
|
|
|
|
BOOST_AUTO_TEST_CASE(netbase_lookupnumeric)
|
|
|
|
{
|
|
|
|
BOOST_CHECK(TestParse("127.0.0.1", "127.0.0.1:65535"));
|
|
|
|
BOOST_CHECK(TestParse("127.0.0.1:8333", "127.0.0.1:8333"));
|
|
|
|
BOOST_CHECK(TestParse("::ffff:127.0.0.1", "127.0.0.1:65535"));
|
|
|
|
BOOST_CHECK(TestParse("::", "[::]:65535"));
|
|
|
|
BOOST_CHECK(TestParse("[::]:8333", "[::]:8333"));
|
|
|
|
BOOST_CHECK(TestParse("[127.0.0.1]", "127.0.0.1:65535"));
|
2016-08-04 22:37:49 +02:00
|
|
|
BOOST_CHECK(TestParse(":::", "[::]:0"));
|
2012-06-08 18:42:05 +02:00
|
|
|
}
|
|
|
|
|
2012-04-29 02:11:56 +02:00
|
|
|
BOOST_AUTO_TEST_CASE(onioncat_test)
|
|
|
|
{
|
2016-05-31 19:05:52 +02:00
|
|
|
|
2014-03-24 21:26:02 +01:00
|
|
|
// values from https://web.archive.org/web/20121122003543/http://www.cypherpunk.at/onioncat/wiki/OnionCat
|
2016-05-31 19:05:52 +02:00
|
|
|
CNetAddr addr1(ResolveIP("5wyqrzbvrdsumnok.onion"));
|
|
|
|
CNetAddr addr2(ResolveIP("FD87:D87E:EB43:edb1:8e4:3588:e546:35ca"));
|
2012-04-29 02:11:56 +02:00
|
|
|
BOOST_CHECK(addr1 == addr2);
|
|
|
|
BOOST_CHECK(addr1.IsTor());
|
|
|
|
BOOST_CHECK(addr1.ToStringIP() == "5wyqrzbvrdsumnok.onion");
|
|
|
|
BOOST_CHECK(addr1.IsRoutable());
|
2016-05-31 19:05:52 +02:00
|
|
|
|
2012-04-29 02:11:56 +02:00
|
|
|
}
|
|
|
|
|
2014-04-28 11:08:57 +02:00
|
|
|
BOOST_AUTO_TEST_CASE(subnet_test)
|
|
|
|
{
|
2016-05-31 19:05:52 +02:00
|
|
|
|
2016-05-31 21:50:24 +02:00
|
|
|
BOOST_CHECK(ResolveSubNet("1.2.3.0/24") == ResolveSubNet("1.2.3.0/255.255.255.0"));
|
|
|
|
BOOST_CHECK(ResolveSubNet("1.2.3.0/24") != ResolveSubNet("1.2.4.0/255.255.255.0"));
|
|
|
|
BOOST_CHECK(ResolveSubNet("1.2.3.0/24").Match(ResolveIP("1.2.3.4")));
|
|
|
|
BOOST_CHECK(!ResolveSubNet("1.2.2.0/24").Match(ResolveIP("1.2.3.4")));
|
|
|
|
BOOST_CHECK(ResolveSubNet("1.2.3.4").Match(ResolveIP("1.2.3.4")));
|
|
|
|
BOOST_CHECK(ResolveSubNet("1.2.3.4/32").Match(ResolveIP("1.2.3.4")));
|
|
|
|
BOOST_CHECK(!ResolveSubNet("1.2.3.4").Match(ResolveIP("5.6.7.8")));
|
|
|
|
BOOST_CHECK(!ResolveSubNet("1.2.3.4/32").Match(ResolveIP("5.6.7.8")));
|
|
|
|
BOOST_CHECK(ResolveSubNet("::ffff:127.0.0.1").Match(ResolveIP("127.0.0.1")));
|
|
|
|
BOOST_CHECK(ResolveSubNet("1:2:3:4:5:6:7:8").Match(ResolveIP("1:2:3:4:5:6:7:8")));
|
|
|
|
BOOST_CHECK(!ResolveSubNet("1:2:3:4:5:6:7:8").Match(ResolveIP("1:2:3:4:5:6:7:9")));
|
|
|
|
BOOST_CHECK(ResolveSubNet("1:2:3:4:5:6:7:0/112").Match(ResolveIP("1:2:3:4:5:6:7:1234")));
|
|
|
|
BOOST_CHECK(ResolveSubNet("192.168.0.1/24").Match(ResolveIP("192.168.0.2")));
|
|
|
|
BOOST_CHECK(ResolveSubNet("192.168.0.20/29").Match(ResolveIP("192.168.0.18")));
|
|
|
|
BOOST_CHECK(ResolveSubNet("1.2.2.1/24").Match(ResolveIP("1.2.2.4")));
|
|
|
|
BOOST_CHECK(ResolveSubNet("1.2.2.110/31").Match(ResolveIP("1.2.2.111")));
|
|
|
|
BOOST_CHECK(ResolveSubNet("1.2.2.20/26").Match(ResolveIP("1.2.2.63")));
|
2014-04-28 11:08:57 +02:00
|
|
|
// All-Matching IPv6 Matches arbitrary IPv4 and IPv6
|
2016-05-31 21:50:24 +02:00
|
|
|
BOOST_CHECK(ResolveSubNet("::/0").Match(ResolveIP("1:2:3:4:5:6:7:1234")));
|
|
|
|
BOOST_CHECK(ResolveSubNet("::/0").Match(ResolveIP("1.2.3.4")));
|
2014-04-28 11:08:57 +02:00
|
|
|
// All-Matching IPv4 does not Match IPv6
|
2016-05-31 21:50:24 +02:00
|
|
|
BOOST_CHECK(!ResolveSubNet("0.0.0.0/0").Match(ResolveIP("1:2:3:4:5:6:7:1234")));
|
2014-04-28 11:08:57 +02:00
|
|
|
// Invalid subnets Match nothing (not even invalid addresses)
|
2016-05-31 19:05:52 +02:00
|
|
|
BOOST_CHECK(!CSubNet().Match(ResolveIP("1.2.3.4")));
|
2016-05-31 21:50:24 +02:00
|
|
|
BOOST_CHECK(!ResolveSubNet("").Match(ResolveIP("4.5.6.7")));
|
|
|
|
BOOST_CHECK(!ResolveSubNet("bloop").Match(ResolveIP("0.0.0.0")));
|
|
|
|
BOOST_CHECK(!ResolveSubNet("bloop").Match(ResolveIP("hab")));
|
2014-04-28 11:08:57 +02:00
|
|
|
// Check valid/invalid
|
2016-05-31 21:50:24 +02:00
|
|
|
BOOST_CHECK(ResolveSubNet("1.2.3.0/0").IsValid());
|
|
|
|
BOOST_CHECK(!ResolveSubNet("1.2.3.0/-1").IsValid());
|
|
|
|
BOOST_CHECK(ResolveSubNet("1.2.3.0/32").IsValid());
|
|
|
|
BOOST_CHECK(!ResolveSubNet("1.2.3.0/33").IsValid());
|
|
|
|
BOOST_CHECK(ResolveSubNet("1:2:3:4:5:6:7:8/0").IsValid());
|
|
|
|
BOOST_CHECK(ResolveSubNet("1:2:3:4:5:6:7:8/33").IsValid());
|
|
|
|
BOOST_CHECK(!ResolveSubNet("1:2:3:4:5:6:7:8/-1").IsValid());
|
|
|
|
BOOST_CHECK(ResolveSubNet("1:2:3:4:5:6:7:8/128").IsValid());
|
|
|
|
BOOST_CHECK(!ResolveSubNet("1:2:3:4:5:6:7:8/129").IsValid());
|
|
|
|
BOOST_CHECK(!ResolveSubNet("fuzzy").IsValid());
|
2015-06-29 20:37:22 +02:00
|
|
|
|
|
|
|
//CNetAddr constructor test
|
2016-05-31 19:05:52 +02:00
|
|
|
BOOST_CHECK(CSubNet(ResolveIP("127.0.0.1")).IsValid());
|
|
|
|
BOOST_CHECK(CSubNet(ResolveIP("127.0.0.1")).Match(ResolveIP("127.0.0.1")));
|
|
|
|
BOOST_CHECK(!CSubNet(ResolveIP("127.0.0.1")).Match(ResolveIP("127.0.0.2")));
|
|
|
|
BOOST_CHECK(CSubNet(ResolveIP("127.0.0.1")).ToString() == "127.0.0.1/32");
|
2015-06-29 20:37:22 +02:00
|
|
|
|
2016-06-01 00:18:41 +02:00
|
|
|
CSubNet subnet = CSubNet(ResolveIP("1.2.3.4"), 32);
|
|
|
|
BOOST_CHECK_EQUAL(subnet.ToString(), "1.2.3.4/32");
|
|
|
|
subnet = CSubNet(ResolveIP("1.2.3.4"), 8);
|
|
|
|
BOOST_CHECK_EQUAL(subnet.ToString(), "1.0.0.0/8");
|
|
|
|
subnet = CSubNet(ResolveIP("1.2.3.4"), 0);
|
|
|
|
BOOST_CHECK_EQUAL(subnet.ToString(), "0.0.0.0/0");
|
|
|
|
|
|
|
|
subnet = CSubNet(ResolveIP("1.2.3.4"), ResolveIP("255.255.255.255"));
|
|
|
|
BOOST_CHECK_EQUAL(subnet.ToString(), "1.2.3.4/32");
|
|
|
|
subnet = CSubNet(ResolveIP("1.2.3.4"), ResolveIP("255.0.0.0"));
|
|
|
|
BOOST_CHECK_EQUAL(subnet.ToString(), "1.0.0.0/8");
|
|
|
|
subnet = CSubNet(ResolveIP("1.2.3.4"), ResolveIP("0.0.0.0"));
|
|
|
|
BOOST_CHECK_EQUAL(subnet.ToString(), "0.0.0.0/0");
|
|
|
|
|
2016-05-31 19:05:52 +02:00
|
|
|
BOOST_CHECK(CSubNet(ResolveIP("1:2:3:4:5:6:7:8")).IsValid());
|
|
|
|
BOOST_CHECK(CSubNet(ResolveIP("1:2:3:4:5:6:7:8")).Match(ResolveIP("1:2:3:4:5:6:7:8")));
|
|
|
|
BOOST_CHECK(!CSubNet(ResolveIP("1:2:3:4:5:6:7:8")).Match(ResolveIP("1:2:3:4:5:6:7:9")));
|
|
|
|
BOOST_CHECK(CSubNet(ResolveIP("1:2:3:4:5:6:7:8")).ToString() == "1:2:3:4:5:6:7:8/128");
|
2015-06-23 17:20:00 +02:00
|
|
|
|
2016-06-01 00:18:41 +02:00
|
|
|
subnet = ResolveSubNet("1.2.3.4/255.255.255.255");
|
2015-06-23 17:20:00 +02:00
|
|
|
BOOST_CHECK_EQUAL(subnet.ToString(), "1.2.3.4/32");
|
2016-05-31 21:50:24 +02:00
|
|
|
subnet = ResolveSubNet("1.2.3.4/255.255.255.254");
|
2015-06-23 17:20:00 +02:00
|
|
|
BOOST_CHECK_EQUAL(subnet.ToString(), "1.2.3.4/31");
|
2016-05-31 21:50:24 +02:00
|
|
|
subnet = ResolveSubNet("1.2.3.4/255.255.255.252");
|
2015-06-23 17:20:00 +02:00
|
|
|
BOOST_CHECK_EQUAL(subnet.ToString(), "1.2.3.4/30");
|
2016-05-31 21:50:24 +02:00
|
|
|
subnet = ResolveSubNet("1.2.3.4/255.255.255.248");
|
2015-06-23 17:20:00 +02:00
|
|
|
BOOST_CHECK_EQUAL(subnet.ToString(), "1.2.3.0/29");
|
2016-05-31 21:50:24 +02:00
|
|
|
subnet = ResolveSubNet("1.2.3.4/255.255.255.240");
|
2015-06-23 17:20:00 +02:00
|
|
|
BOOST_CHECK_EQUAL(subnet.ToString(), "1.2.3.0/28");
|
2016-05-31 21:50:24 +02:00
|
|
|
subnet = ResolveSubNet("1.2.3.4/255.255.255.224");
|
2015-06-23 17:20:00 +02:00
|
|
|
BOOST_CHECK_EQUAL(subnet.ToString(), "1.2.3.0/27");
|
2016-05-31 21:50:24 +02:00
|
|
|
subnet = ResolveSubNet("1.2.3.4/255.255.255.192");
|
2015-06-23 17:20:00 +02:00
|
|
|
BOOST_CHECK_EQUAL(subnet.ToString(), "1.2.3.0/26");
|
2016-05-31 21:50:24 +02:00
|
|
|
subnet = ResolveSubNet("1.2.3.4/255.255.255.128");
|
2015-06-23 17:20:00 +02:00
|
|
|
BOOST_CHECK_EQUAL(subnet.ToString(), "1.2.3.0/25");
|
2016-05-31 21:50:24 +02:00
|
|
|
subnet = ResolveSubNet("1.2.3.4/255.255.255.0");
|
2015-06-23 17:20:00 +02:00
|
|
|
BOOST_CHECK_EQUAL(subnet.ToString(), "1.2.3.0/24");
|
2016-05-31 21:50:24 +02:00
|
|
|
subnet = ResolveSubNet("1.2.3.4/255.255.254.0");
|
2015-06-23 17:20:00 +02:00
|
|
|
BOOST_CHECK_EQUAL(subnet.ToString(), "1.2.2.0/23");
|
2016-05-31 21:50:24 +02:00
|
|
|
subnet = ResolveSubNet("1.2.3.4/255.255.252.0");
|
2015-06-23 17:20:00 +02:00
|
|
|
BOOST_CHECK_EQUAL(subnet.ToString(), "1.2.0.0/22");
|
2016-05-31 21:50:24 +02:00
|
|
|
subnet = ResolveSubNet("1.2.3.4/255.255.248.0");
|
2015-06-23 17:20:00 +02:00
|
|
|
BOOST_CHECK_EQUAL(subnet.ToString(), "1.2.0.0/21");
|
2016-05-31 21:50:24 +02:00
|
|
|
subnet = ResolveSubNet("1.2.3.4/255.255.240.0");
|
2015-06-23 17:20:00 +02:00
|
|
|
BOOST_CHECK_EQUAL(subnet.ToString(), "1.2.0.0/20");
|
2016-05-31 21:50:24 +02:00
|
|
|
subnet = ResolveSubNet("1.2.3.4/255.255.224.0");
|
2015-06-23 17:20:00 +02:00
|
|
|
BOOST_CHECK_EQUAL(subnet.ToString(), "1.2.0.0/19");
|
2016-05-31 21:50:24 +02:00
|
|
|
subnet = ResolveSubNet("1.2.3.4/255.255.192.0");
|
2015-06-23 17:20:00 +02:00
|
|
|
BOOST_CHECK_EQUAL(subnet.ToString(), "1.2.0.0/18");
|
2016-05-31 21:50:24 +02:00
|
|
|
subnet = ResolveSubNet("1.2.3.4/255.255.128.0");
|
2015-06-23 17:20:00 +02:00
|
|
|
BOOST_CHECK_EQUAL(subnet.ToString(), "1.2.0.0/17");
|
2016-05-31 21:50:24 +02:00
|
|
|
subnet = ResolveSubNet("1.2.3.4/255.255.0.0");
|
2015-06-23 17:20:00 +02:00
|
|
|
BOOST_CHECK_EQUAL(subnet.ToString(), "1.2.0.0/16");
|
2016-05-31 21:50:24 +02:00
|
|
|
subnet = ResolveSubNet("1.2.3.4/255.254.0.0");
|
2015-06-23 17:20:00 +02:00
|
|
|
BOOST_CHECK_EQUAL(subnet.ToString(), "1.2.0.0/15");
|
2016-05-31 21:50:24 +02:00
|
|
|
subnet = ResolveSubNet("1.2.3.4/255.252.0.0");
|
2015-06-23 17:20:00 +02:00
|
|
|
BOOST_CHECK_EQUAL(subnet.ToString(), "1.0.0.0/14");
|
2016-05-31 21:50:24 +02:00
|
|
|
subnet = ResolveSubNet("1.2.3.4/255.248.0.0");
|
2015-06-23 17:20:00 +02:00
|
|
|
BOOST_CHECK_EQUAL(subnet.ToString(), "1.0.0.0/13");
|
2016-05-31 21:50:24 +02:00
|
|
|
subnet = ResolveSubNet("1.2.3.4/255.240.0.0");
|
2015-06-23 17:20:00 +02:00
|
|
|
BOOST_CHECK_EQUAL(subnet.ToString(), "1.0.0.0/12");
|
2016-05-31 21:50:24 +02:00
|
|
|
subnet = ResolveSubNet("1.2.3.4/255.224.0.0");
|
2015-06-23 17:20:00 +02:00
|
|
|
BOOST_CHECK_EQUAL(subnet.ToString(), "1.0.0.0/11");
|
2016-05-31 21:50:24 +02:00
|
|
|
subnet = ResolveSubNet("1.2.3.4/255.192.0.0");
|
2015-06-23 17:20:00 +02:00
|
|
|
BOOST_CHECK_EQUAL(subnet.ToString(), "1.0.0.0/10");
|
2016-05-31 21:50:24 +02:00
|
|
|
subnet = ResolveSubNet("1.2.3.4/255.128.0.0");
|
2015-06-23 17:20:00 +02:00
|
|
|
BOOST_CHECK_EQUAL(subnet.ToString(), "1.0.0.0/9");
|
2016-05-31 21:50:24 +02:00
|
|
|
subnet = ResolveSubNet("1.2.3.4/255.0.0.0");
|
2015-06-23 17:20:00 +02:00
|
|
|
BOOST_CHECK_EQUAL(subnet.ToString(), "1.0.0.0/8");
|
2016-05-31 21:50:24 +02:00
|
|
|
subnet = ResolveSubNet("1.2.3.4/254.0.0.0");
|
2015-06-23 17:20:00 +02:00
|
|
|
BOOST_CHECK_EQUAL(subnet.ToString(), "0.0.0.0/7");
|
2016-05-31 21:50:24 +02:00
|
|
|
subnet = ResolveSubNet("1.2.3.4/252.0.0.0");
|
2015-06-23 17:20:00 +02:00
|
|
|
BOOST_CHECK_EQUAL(subnet.ToString(), "0.0.0.0/6");
|
2016-05-31 21:50:24 +02:00
|
|
|
subnet = ResolveSubNet("1.2.3.4/248.0.0.0");
|
2015-06-23 17:20:00 +02:00
|
|
|
BOOST_CHECK_EQUAL(subnet.ToString(), "0.0.0.0/5");
|
2016-05-31 21:50:24 +02:00
|
|
|
subnet = ResolveSubNet("1.2.3.4/240.0.0.0");
|
2015-06-23 17:20:00 +02:00
|
|
|
BOOST_CHECK_EQUAL(subnet.ToString(), "0.0.0.0/4");
|
2016-05-31 21:50:24 +02:00
|
|
|
subnet = ResolveSubNet("1.2.3.4/224.0.0.0");
|
2015-06-23 17:20:00 +02:00
|
|
|
BOOST_CHECK_EQUAL(subnet.ToString(), "0.0.0.0/3");
|
2016-05-31 21:50:24 +02:00
|
|
|
subnet = ResolveSubNet("1.2.3.4/192.0.0.0");
|
2015-06-23 17:20:00 +02:00
|
|
|
BOOST_CHECK_EQUAL(subnet.ToString(), "0.0.0.0/2");
|
2016-05-31 21:50:24 +02:00
|
|
|
subnet = ResolveSubNet("1.2.3.4/128.0.0.0");
|
2015-06-23 17:20:00 +02:00
|
|
|
BOOST_CHECK_EQUAL(subnet.ToString(), "0.0.0.0/1");
|
2016-05-31 21:50:24 +02:00
|
|
|
subnet = ResolveSubNet("1.2.3.4/0.0.0.0");
|
2015-06-23 17:20:00 +02:00
|
|
|
BOOST_CHECK_EQUAL(subnet.ToString(), "0.0.0.0/0");
|
|
|
|
|
2016-05-31 21:50:24 +02:00
|
|
|
subnet = ResolveSubNet("1:2:3:4:5:6:7:8/ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff");
|
2015-06-23 17:20:00 +02:00
|
|
|
BOOST_CHECK_EQUAL(subnet.ToString(), "1:2:3:4:5:6:7:8/128");
|
2016-05-31 21:50:24 +02:00
|
|
|
subnet = ResolveSubNet("1:2:3:4:5:6:7:8/ffff:0000:0000:0000:0000:0000:0000:0000");
|
2015-06-23 17:20:00 +02:00
|
|
|
BOOST_CHECK_EQUAL(subnet.ToString(), "1::/16");
|
2016-05-31 21:50:24 +02:00
|
|
|
subnet = ResolveSubNet("1:2:3:4:5:6:7:8/0000:0000:0000:0000:0000:0000:0000:0000");
|
2015-06-23 17:20:00 +02:00
|
|
|
BOOST_CHECK_EQUAL(subnet.ToString(), "::/0");
|
2016-05-31 21:50:24 +02:00
|
|
|
subnet = ResolveSubNet("1.2.3.4/255.255.232.0");
|
2015-06-25 10:47:34 +02:00
|
|
|
BOOST_CHECK_EQUAL(subnet.ToString(), "1.2.0.0/255.255.232.0");
|
2016-05-31 21:50:24 +02:00
|
|
|
subnet = ResolveSubNet("1:2:3:4:5:6:7:8/ffff:ffff:ffff:fffe:ffff:ffff:ffff:ff0f");
|
2015-06-25 10:47:34 +02:00
|
|
|
BOOST_CHECK_EQUAL(subnet.ToString(), "1:2:3:4:5:6:7:8/ffff:ffff:ffff:fffe:ffff:ffff:ffff:ff0f");
|
2016-05-31 19:05:52 +02:00
|
|
|
|
2014-04-28 11:08:57 +02:00
|
|
|
}
|
|
|
|
|
2015-08-19 20:34:56 +02:00
|
|
|
BOOST_AUTO_TEST_CASE(netbase_getgroup)
|
|
|
|
{
|
2016-05-31 19:05:52 +02:00
|
|
|
|
|
|
|
BOOST_CHECK(ResolveIP("127.0.0.1").GetGroup() == boost::assign::list_of(0)); // Local -> !Routable()
|
|
|
|
BOOST_CHECK(ResolveIP("257.0.0.1").GetGroup() == boost::assign::list_of(0)); // !Valid -> !Routable()
|
|
|
|
BOOST_CHECK(ResolveIP("10.0.0.1").GetGroup() == boost::assign::list_of(0)); // RFC1918 -> !Routable()
|
|
|
|
BOOST_CHECK(ResolveIP("169.254.1.1").GetGroup() == boost::assign::list_of(0)); // RFC3927 -> !Routable()
|
|
|
|
BOOST_CHECK(ResolveIP("1.2.3.4").GetGroup() == boost::assign::list_of((unsigned char)NET_IPV4)(1)(2)); // IPv4
|
|
|
|
BOOST_CHECK(ResolveIP("::FFFF:0:102:304").GetGroup() == boost::assign::list_of((unsigned char)NET_IPV4)(1)(2)); // RFC6145
|
|
|
|
BOOST_CHECK(ResolveIP("64:FF9B::102:304").GetGroup() == boost::assign::list_of((unsigned char)NET_IPV4)(1)(2)); // RFC6052
|
|
|
|
BOOST_CHECK(ResolveIP("2002:102:304:9999:9999:9999:9999:9999").GetGroup() == boost::assign::list_of((unsigned char)NET_IPV4)(1)(2)); // RFC3964
|
|
|
|
BOOST_CHECK(ResolveIP("2001:0:9999:9999:9999:9999:FEFD:FCFB").GetGroup() == boost::assign::list_of((unsigned char)NET_IPV4)(1)(2)); // RFC4380
|
|
|
|
BOOST_CHECK(ResolveIP("FD87:D87E:EB43:edb1:8e4:3588:e546:35ca").GetGroup() == boost::assign::list_of((unsigned char)NET_TOR)(239)); // Tor
|
|
|
|
BOOST_CHECK(ResolveIP("2001:470:abcd:9999:9999:9999:9999:9999").GetGroup() == boost::assign::list_of((unsigned char)NET_IPV6)(32)(1)(4)(112)(175)); //he.net
|
|
|
|
BOOST_CHECK(ResolveIP("2001:2001:9999:9999:9999:9999:9999:9999").GetGroup() == boost::assign::list_of((unsigned char)NET_IPV6)(32)(1)(32)(1)); //IPv6
|
|
|
|
|
2015-08-19 20:34:56 +02:00
|
|
|
}
|
|
|
|
|
2012-06-08 18:42:05 +02:00
|
|
|
BOOST_AUTO_TEST_SUITE_END()
|