5 #include <glog/logging.h>
7 int main(int argc
, char const* argv
[])
10 using IP4::is_address
;
11 using IP4::is_address_literal
;
12 using IP4::is_private
;
14 using IP4::to_address_literal
;
16 CHECK(is_address_literal("[69.0.0.0]"));
17 CHECK(!is_address_literal("69.0.0.0]"));
18 CHECK(!is_address_literal("[69.0.0.0"));
19 CHECK(!is_address_literal("[]"));
20 CHECK(!is_address_literal("[1234]"));
22 CHECK(is_address("0.0.0.0"));
23 CHECK(is_address("69.0.0.0"));
24 CHECK(is_address("160.0.0.0"));
25 CHECK(is_address("250.0.0.0"));
26 CHECK(is_address("251.0.0.0"));
27 CHECK(is_address("252.0.0.0"));
28 CHECK(is_address("253.0.0.0"));
29 CHECK(is_address("254.0.0.0"));
30 CHECK(is_address("111.0.0.0"));
32 CHECK(is_address("9.9.9.9"));
33 CHECK(is_address("99.99.99.99"));
34 CHECK(is_address("255.0.0.1"));
35 CHECK(is_address("127.0.0.1"));
37 CHECK(!is_address("127.0.0.1."));
38 CHECK(!is_address("foo.bar"));
39 CHECK(!is_address(""));
41 // These are NOT acceptable:
42 CHECK(!is_address("001.001.001.001"));
43 CHECK(!is_address("01.01.01.01"));
44 CHECK(!is_address("000.000.000.000"));
45 CHECK(!is_address("0001.0.0.0"));
46 CHECK(!is_address("00001.0.0.0"));
47 CHECK(!is_address("0000.0.0.0"));
49 CHECK(!is_address("256.0.0.0"));
50 CHECK(!is_address("260.0.0.0"));
51 CHECK(!is_address("300.0.0.0"));
52 CHECK(!is_address("1000.0.0.0"));
54 CHECK(!is_address("1.256.0.0"));
55 CHECK(!is_address("1.260.0.0"));
56 CHECK(!is_address("1.300.0.0"));
57 CHECK(!is_address("1.1000.0.0"));
59 CHECK(!is_address("1.1.256.0"));
60 CHECK(!is_address("1.1.260.0"));
61 CHECK(!is_address("1.1.300.0"));
62 CHECK(!is_address("1.1.1000.0"));
64 CHECK(!is_address("1.1.1.256"));
65 CHECK(!is_address("1.1.1.260"));
66 CHECK(!is_address("1.1.1.300"));
67 CHECK(!is_address("1.1.1.1000"));
69 auto const rev
{reverse("1.2.3.4")};
70 CHECK_EQ(0, rev
.compare("4.3.2.1."));
72 auto const addr
= "108.83.36.113";
73 auto const addr_lit
= "[108.83.36.113]";
75 CHECK(is_address(addr
));
76 CHECK(is_address_literal(addr_lit
));
78 CHECK_EQ(to_address_literal(addr
), addr_lit
);
79 CHECK_EQ(as_address(addr_lit
), addr
);
81 CHECK(!is_private("1.2.3.4"));
82 CHECK(!is_private("127.0.0.1"));
84 CHECK(is_private("10.0.0.1"));
86 CHECK(!is_private("172.15.0.1"));
87 CHECK(is_private("172.16.0.1"));
88 CHECK(is_private("172.31.255.255"));
89 CHECK(!is_private("172.32.0.1"));
91 CHECK(is_private("192.168.0.1"));