16 #include <sys/types.h> 30 using namespace folly;
45 : address(address_), bytes(bytes_), version(version_) {}
47 : address(address_), bytes(), version(version_) {}
49 : address(address_), bytes(), version(0) {}
54 inet_pton(AF_INET, src.c_str(), &
addr);
60 inet_pton(AF_INET6, src.c_str(), &
addr);
79 : address(addr), flags(flags_), version(version_) {}
82 return (flags & IS_LOCAL);
85 return (flags & IS_NONROUTABLE);
88 return (flags & IS_PRIVATE);
91 return (flags & IS_ZERO);
94 return (flags & IS_LINK_LOCAL);
97 return (flags & IS_LINK_LOCAL_BROADCAST);
106 : address(addr), mask(mask_), subnet(subnet_) {}
116 :
MaskData(addr, mask_, subnet_), inSubnet(inSubnet_) {}
124 : address(addr), bytes(bytes_) {}
134 EXPECT_EQ(0, memcmp(&v4addr, addr.asV4().toByteArray().data(), 4));
139 EXPECT_EQ(0, memcmp(&v6addr, addr.asV6().toByteArray().data(), 16));
149 : TestWithParam<std::pair<std::string, std::string>> {};
174 const static std::vector<StringTestParam> ret = {
175 {lo6, lo6,
none, lo6},
176 {lo6brackets, lo6,
none, lo6},
177 {ip6, ip6,
none, ip6},
179 {lo4, lo4, lo4, none},
180 {ip4, ip4, ip4, none},
193 IPAddress uninitaddr;
194 IPAddress v4addr(
"192.0.2.129");
195 IPAddress v6map(
"::ffff:192.0.2.129");
200 EXPECT_TRUE(v4addr.inSubnet(IPAddress(
"192.0.2.0"), 24));
203 EXPECT_EQ(2164392128, v4addr.asV4().toLong());
204 EXPECT_EQ(3221226113, v4addr.asV4().toLongHBO());
211 EXPECT_TRUE(v4addr.asV4() == IPAddress::createIPv4(v6map));
212 EXPECT_TRUE(IPAddress::createIPv6(v4addr) == v6map.asV6());
217 auto str =
"fe80::62eb:69ff:fe9b:ba60%eth0";
233 TEST(IPAddress, ScopeNumeric) {
236 auto str =
"fe80::62eb:69ff:fe9b:ba60%42";
253 IPAddress a1(
"0.1.1.1");
254 IPAddress a2(
"1.1.1.0");
257 IPAddress b1(
"::ffff:0.1.1.1");
258 IPAddress b2(
"::ffff:1.1.1.0");
262 TEST(IPAddress, InvalidAddressFamilyExceptions) {
277 addr.sin_family = AF_UNSPEC;
283 TEST(IPAddress, TryCreateNetwork) {
286 auto net = IPAddress::tryCreateNetwork(
"192.168.0.1/24").value();
288 EXPECT_EQ(
"192.168.0.0", net.first.str());
290 EXPECT_EQ(
"192.168.0.0/24", IPAddress::networkToString(net));
294 auto net = IPAddress::tryCreateNetwork(
"192.168.0.1/24", -1,
false).value();
296 EXPECT_EQ(
"192.168.0.1", net.first.str());
298 EXPECT_EQ(
"192.168.0.1/24", IPAddress::networkToString(net));
302 auto net = IPAddress::tryCreateNetwork(
"1999::1/24").value();
306 EXPECT_EQ(
"1999::/24", IPAddress::networkToString(net));
310 auto net = IPAddress::tryCreateNetwork(
"1999::1/24", -1,
false).value();
314 EXPECT_EQ(
"1999::1/24", IPAddress::networkToString(net));
320 IPAddress::tryCreateNetwork(
"192.168.1.1", 300).
error());
329 IPAddress::tryCreateNetwork(
"192.168.0.1/24/36").
error());
333 auto net = IPAddress::tryCreateNetwork(
"192.168.0.1").value();
335 EXPECT_EQ(
"192.168.0.1", net.first.str());
337 net = IPAddress::createNetwork(
"192.168.0.1", -1,
false);
339 EXPECT_EQ(
"192.168.0.1", net.first.str());
344 auto net = IPAddress::tryCreateNetwork(
"1999::1").value();
352 IPAddress::tryCreateNetwork(
"192.168.0.1", 33).
error());
356 TEST(IPAddress, CreateNetworkExceptions) {
358 EXPECT_THROW(IPAddress::createNetwork(
"192.168.0.1", 300), std::range_error);
371 static const string kIPv4Addr =
"69.63.189.16";
372 static const string kIPv6Addr =
"2620:0:1cfe:face:b00c::3";
376 IPAddress
addr(kIPv4Addr);
386 IPAddress
addr(kIPv6Addr);
396 IPAddress
addr(kIPv4Addr);
397 IPAddress addrV6 = IPAddress(kIPv6Addr);
406 IPAddress
addr(kIPv6Addr);
407 IPAddress addrV4 = IPAddress(kIPv4Addr);
449 IPAddress strAddr(param.
address);
454 address = IPAddress(v4addr);
457 address = IPAddress(v6addr);
459 ExpectIsValid(address);
470 address = IPAddress::fromBinary(
ByteRange((
unsigned char*)&v4addr, 4));
473 address = IPAddress::fromBinary(
ByteRange((
unsigned char*)&v6addr, 16));
476 ExpectIsValid(address);
483 IPAddress address(param.
address);
485 ExpectIsValid(address);
490 ExpectIsValid(IPAddress(v4));
492 }
else if (param.
version == 6) {
494 ExpectIsValid(IPAddress(v6));
499 TEST(IPAddress, CtorSockaddr) {
505 sin_addr.s_addr = htonl(2122547223);
506 addr.sin_family = AF_INET;
507 addr.sin_addr = sin_addr;
509 IPAddress ipAddr((sockaddr*)&addr);
511 EXPECT_EQ(
"126.131.128.23", ipAddr.str());
517 memset(&addr, 0,
sizeof(addr));
521 {38, 32, 0, 0, 28, 254, 250, 206, 176, 12, 0, 0, 0, 0, 0, 3}};
522 std::memcpy(sin_addr.s6_addr, sec.data(), 16);
523 addr.sin6_family = AF_INET6;
524 addr.sin6_addr = sin_addr;
526 IPAddress ipAddr((sockaddr*)&addr);
528 EXPECT_EQ(
"2620:0:1cfe:face:b00c::3", ipAddr.str());
532 sockaddr*
addr =
nullptr;
540 sin_addr.s_addr = htonl(2122547223);
541 addr.sin_family = AF_UNSPEC;
542 addr.sin_addr = sin_addr;
548 TEST(IPAddress, ToSockaddrStorage) {
551 string strAddr(
"126.131.128.23");
552 IPAddress
addr(strAddr);
553 sockaddr_storage out;
556 EXPECT_GT(addr.toSockaddrStorage(&out), 0);
558 IPAddress sockAddr((sockaddr*)&out);
564 string strAddr(
"2620:0:1cfe:face:b00c::3");
565 IPAddress
addr(strAddr);
566 sockaddr_storage out;
569 EXPECT_GT(addr.toSockaddrStorage(&out), 0);
571 IPAddress sockAddr((sockaddr*)&out);
577 sockaddr_storage* out =
nullptr;
578 IPAddress
addr(
"127.0.0.1");
584 sockaddr_storage out;
591 auto param = GetParam();
592 auto maybeIp = IPAddress::tryFromString(param.in);
595 EXPECT_EQ(param.out, maybeIp.value().str());
605 auto param = GetParam();
609 EXPECT_EQ(param.out4, maybeIp.value().str());
617 auto param = GetParam();
621 EXPECT_EQ(param.out6, maybeIp.value().str());
631 EXPECT_EQ(
"10.0.0.1", folly::to<string>(addr_10_0_0_1));
634 EXPECT_EQ(
"::1", folly::to<string>(addr_1));
636 IPAddress addr_10_1_2_3(
"10.1.2.3");
637 EXPECT_EQ(
"10.1.2.3", folly::to<string>(addr_10_1_2_3));
638 IPAddress addr_1_2_3(
"1:2::3");
639 EXPECT_EQ(
"1:2::3", folly::to<string>(addr_1_2_3));
643 "1:2::3 - 10.0.0.1 - ::1 - 10.1.2.3",
654 TEST(IPaddress, toInverseArpaName) {
657 IPAddressV6 addr_ipv6(
"2620:0000:1cfe:face:b00c:0000:0000:0003");
661 "3.0.0.0.0.0.0.0.0.0.0.0.c.0.0.b.e.c.a.f.e.f.c.1.0.0.0.0.0.2.6.2"),
662 addr_ipv6.toInverseArpaName());
665 TEST(IPaddress, fromInverseArpaName) {
670 IPAddressV6(
"2620:0000:1cfe:face:b00c:0000:0000:0003"),
673 "3.0.0.0.0.0.0.0.0.0.0.0.c.0.0.b.e.c.a.f.e.f.c.1.0.0.0.0.0.2.6.2")));
678 string addr = GetParam();
680 <<
"IPAddress(" << addr <<
") " 681 <<
"should have thrown an IPAddressFormatException";
686 auto bin = GetParam();
687 auto byteRange =
ByteRange(&bin[0], bin.size());
693 EXPECT_TRUE(IPAddress::tryFromBinary(byteRange).hasError());
699 vector<std::uint8_t>
data = {{0xff, 0x20, 0x45}};
707 TEST(IPAddress, ToFullyQualifiedFb) {
708 IPAddress ip(
"2620:0:1cfe:face:b00c::3");
709 EXPECT_EQ(
"2620:0000:1cfe:face:b00c:0000:0000:0003", ip.toFullyQualified())
712 TEST(IPAddress, ToFullyQualifiedLocal) {
714 EXPECT_EQ(
"0000:0000:0000:0000:0000:0000:0000:0001", ip.toFullyQualified())
717 TEST(IPAddress, ToFullyQualifiedAppendV6) {
718 IPAddress ip(
"2620:0:1cfe:face:b00c::3");
720 ip.toFullyQualifiedAppend(result);
721 EXPECT_EQ(
"2620:0000:1cfe:face:b00c:0000:0000:0003", result) << ip;
723 TEST(IPAddress, ToFullyQualifiedAppendV4) {
724 IPAddress ip(
"127.0.0.1");
726 ip.toFullyQualifiedAppend(result);
729 TEST(IPAddress, ToFullyQualifiedSizeV6) {
731 auto expected = IPAddress(
"::").toFullyQualified().size();
734 TEST(IPAddress, MaxToFullyQualifiedSizeV4) {
736 auto expected = IPAddress(
"255.255.255.255").toFullyQualified().size();
742 auto param = GetParam();
743 string mappedIp = param.first;
744 string otherIp = param.second;
746 auto mapped = IPAddress(mappedIp);
747 auto expected = IPAddress(otherIp);
753 v6addr =
mapped.asV4().createIPv6();
754 }
else if (expected.isV4()) {
755 v6addr = expected.asV4().createIPv6();
764 auto param = GetParam();
766 IPAddress ip(param.address);
767 IPAddress masked = ip.mask(param.mask);
769 << param.address <<
"/" << folly::to<std::string>(param.mask) <<
" -> " 775 auto param = GetParam();
777 IPAddress ip(param.address);
778 IPAddress subnet(param.subnet);
784 auto param = GetParam();
785 IPAddress ip(param.address);
786 IPAddress subnet(param.subnet);
787 EXPECT_EQ(param.inSubnet, ip.inSubnet(subnet, param.mask));
790 TEST(IPAddress, UnitializedEqual) {
792 IPAddress ip4(
"127.0.0.1");
795 IPAddress ip6(
"::1");
798 IPAddress ip6Map(
"::ffff:192.0.2.129");
801 IPAddress ip4Zero(
"0.0.0.0");
804 IPAddress ip6Zero(
"::");
811 TEST(IPAddress, InSubnetWith6to4) {
812 auto ip = IPAddress(
"2002:c000:022a::");
813 auto subnet = IPAddress(
"192.0.0.0");
816 auto ip2 = IPAddress(
"192.0.0.1");
817 auto subnet2 = IPAddress(
"2002:c000:0000::");
820 auto ip3 = IPAddress(
"2002:c000:022a::");
821 auto subnet3 = IPAddress(
"2002:c000:0000::");
830 TEST(IPAddress, getIPv6For6To4) {
831 for (
auto ipv4Str : ipv4Strs) {
832 auto ip = IPAddress(ipv4Str);
836 EXPECT_EQ(ipv6.type(), IPAddressV6::Type::T6TO4);
837 auto ipv4New = ipv6.getIPv4For6To4();
847 for (
auto&
tc : invalidMasks) {
848 auto ip = IPAddress(
tc.first);
853 static const vector<pair<string, IPAddressV6::Type>>
v6types = {
854 {
"::1", IPAddressV6::Type::NORMAL},
855 {
"2620:0:1cfe:face:b00c::3", IPAddressV6::Type::NORMAL},
856 {
"2001:0000:4136:e378:8000:63bf:3fff:fdd2", IPAddressV6::Type::TEREDO},
857 {
"2002:c000:022a::", IPAddressV6::Type::T6TO4},
862 case IPAddressV6::Type::TEREDO:
864 case IPAddressV6::Type::T6TO4:
871 for (
auto&
tc : v6types) {
872 auto ip = IPAddress(
tc.first);
876 <<
"expected " << mkName(
tc.second) <<
", got " << mkName(ipv6.type());
878 case IPAddressV6::Type::TEREDO:
879 EXPECT_TRUE(ipv6.isTeredo()) <<
"isTeredo was false";
882 case IPAddressV6::Type::T6TO4:
886 case IPAddressV6::Type::NORMAL:
891 FAIL() <<
"Invalid expected type: " << to<std::string>(
tc.second);
898 {
"10.0.0.0", 167772160},
899 {
"126.131.128.23", 2122547223},
900 {
"192.168.0.0", 3232235520},
903 for (
auto&
tc : provideToLong) {
904 auto ip = IPAddress(
tc.first);
909 auto ip2 = IPAddress::fromLongHBO(
tc.second);
914 auto nla = htonl(
tc.second);
915 auto ip3 = IPAddress::fromLong(nla);
922 TEST(IPAddress, fromBinaryV4) {
923 for (
auto&
tc : provideToLong) {
944 IPAddress genericAddr = IPAddress::fromBinary(bytes);
960 for (
auto&
tc : provideToLong) {
970 auto toBin = fromBin.toBinary();
977 static auto join8 = [](std::array<ByteArray8, 2> parts) {
979 std::memcpy(_return.data(), parts.data(), _return.size());
987 ByteArray8{{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}},
988 ByteArray8{{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}},
993 ByteArray8{{0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}},
994 ByteArray8{{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02}},
997 "fe80::0012:34ff:fe56:78ab",
999 {{
ByteArray8{{0xfe, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}},
1000 ByteArray8{{0x00, 0x12, 0x34, 0xff, 0xfe, 0x56, 0x78, 0xab}}}})),
1002 "2001:db8:1234:5678:90ab:cdef:8765:4321",
1004 ByteArray8{{0x20, 0x01, 0x0d, 0xb8, 0x12, 0x34, 0x56, 0x78}},
1005 ByteArray8{{0x90, 0xab, 0xcd, 0xef, 0x87, 0x65, 0x43, 0x21}},
1010 ByteArray8{{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}},
1011 ByteArray8{{0xff, 0xff, 0x00, 0x00, 0xc0, 0xa8, 0x00, 0x01}},
1016 for (
auto&
tc : provideBinary16Bytes) {
1032 IPAddress genericAddr = IPAddress::fromBinary(bytes);
1048 for (
auto&
tc : provideBinary16Bytes) {
1053 auto toBin = fromBin.toBinary();
1111 TEST(IPAddress, SolicitedNodeAddress) {
1115 IPAddressV6(
"4037::01:800:200e:8c6c").getSolicitedNodeAddress());
1121 IPAddressV6(
"fe80::2aa:ff:fe28:9c5a").getSolicitedNodeAddress());
1125 auto addrData = GetParam();
1126 IPAddress ip(addrData.address);
1128 for (
auto byitr = addrData.bytes.begin(); i < ip.byteCount(); ++
i, ++byitr) {
1132 ip.isV4() ? ip.asV4().getNthMSByte(i) : ip.asV6().getNthMSByte(i));
1135 for (
auto byritr = addrData.bytes.rbegin(); i < ip.byteCount();
1140 ip.isV4() ? ip.asV4().getNthLSByte(i) : ip.asV6().getNthLSByte(i));
1145 auto addrData = GetParam();
1146 auto littleEndianAddrData = addrData.bytes;
1148 reverse(littleEndianAddrData.begin(), littleEndianAddrData.end());
1152 IPAddress ip(addrData.address);
1153 for (
size_t i = 0;
i < ip.bitCount(); ++
i) {
1154 auto msbIndex = ip.bitCount() -
i - 1;
1155 EXPECT_EQ(*bitr, ip.getNthMSBit(msbIndex));
1158 ip.isV4() ? ip.asV4().getNthMSBit(msbIndex)
1159 : ip.asV6().getNthMSBit(msbIndex));
1162 *bitr, ip.isV4() ? ip.asV4().getNthLSBit(
i) : ip.asV6().getNthLSBit(
i));
1167 TEST(IPAddress, InvalidByteAccess) {
1168 IPAddress ip4(
"10.10.10.10");
1170 EXPECT_THROW(ip4.getNthMSByte(ip4.byteCount()), std::invalid_argument);
1171 EXPECT_THROW(ip4.getNthLSByte(ip4.byteCount()), std::invalid_argument);
1172 EXPECT_THROW(ip4.getNthMSByte(-1), std::invalid_argument);
1173 EXPECT_THROW(ip4.getNthLSByte(-1), std::invalid_argument);
1174 auto asV4 = ip4.asV4();
1175 EXPECT_THROW(asV4.getNthMSByte(asV4.byteCount()), std::invalid_argument);
1176 EXPECT_THROW(asV4.getNthLSByte(asV4.byteCount()), std::invalid_argument);
1177 EXPECT_THROW(asV4.getNthMSByte(-1), std::invalid_argument);
1178 EXPECT_THROW(asV4.getNthLSByte(-1), std::invalid_argument);
1180 IPAddress ip6(
"2620:0:1cfe:face:b00c::3");
1181 EXPECT_THROW(ip6.getNthMSByte(ip6.byteCount()), std::invalid_argument);
1182 EXPECT_THROW(ip6.getNthLSByte(ip6.byteCount()), std::invalid_argument);
1183 EXPECT_THROW(ip6.getNthMSByte(-1), std::invalid_argument);
1184 EXPECT_THROW(ip6.getNthLSByte(-1), std::invalid_argument);
1185 auto asV6 = ip6.asV6();
1186 EXPECT_THROW(asV6.getNthMSByte(asV6.byteCount()), std::invalid_argument);
1187 EXPECT_THROW(asV6.getNthLSByte(asV6.byteCount()), std::invalid_argument);
1188 EXPECT_THROW(asV6.getNthMSByte(-1), std::invalid_argument);
1189 EXPECT_THROW(asV6.getNthLSByte(-1), std::invalid_argument);
1192 TEST(IPAddress, InvalidBBitAccess) {
1193 IPAddress ip4(
"10.10.10.10");
1195 EXPECT_THROW(ip4.getNthMSBit(ip4.bitCount()), std::invalid_argument);
1196 EXPECT_THROW(ip4.getNthLSBit(ip4.bitCount()), std::invalid_argument);
1197 EXPECT_THROW(ip4.getNthMSBit(-1), std::invalid_argument);
1198 EXPECT_THROW(ip4.getNthLSBit(-1), std::invalid_argument);
1199 auto asV4 = ip4.asV4();
1200 EXPECT_THROW(asV4.getNthMSBit(asV4.bitCount()), std::invalid_argument);
1201 EXPECT_THROW(asV4.getNthLSBit(asV4.bitCount()), std::invalid_argument);
1202 EXPECT_THROW(asV4.getNthMSBit(-1), std::invalid_argument);
1203 EXPECT_THROW(asV4.getNthLSBit(-1), std::invalid_argument);
1205 IPAddress ip6(
"2620:0:1cfe:face:b00c::3");
1206 EXPECT_THROW(ip6.getNthMSBit(ip6.bitCount()), std::invalid_argument);
1207 EXPECT_THROW(ip6.getNthLSBit(ip6.bitCount()), std::invalid_argument);
1208 EXPECT_THROW(ip6.getNthMSBit(-1), std::invalid_argument);
1209 EXPECT_THROW(ip6.getNthLSBit(-1), std::invalid_argument);
1210 auto asV6 = ip6.asV6();
1211 EXPECT_THROW(asV6.getNthMSBit(asV6.bitCount()), std::invalid_argument);
1212 EXPECT_THROW(asV6.getNthLSBit(asV6.bitCount()), std::invalid_argument);
1213 EXPECT_THROW(asV6.getNthMSBit(-1), std::invalid_argument);
1214 EXPECT_THROW(asV6.getNthLSBit(-1), std::invalid_argument);
1219 for (
int i = 0;
i < 8; ++
i) {
1220 auto t = htons(0x0123 + ((
i % 4) * 0x4444));
1224 a6.s6_addr16[
i] =
t;
1231 a4.s_addr = htonl(0x01020304);
1235 TEST(IPAddress, getMacAddressFromLinkLocal) {
1241 TEST(IPAddress, getMacAddressFromLinkLocal_Negative) {
1242 IPAddressV6 no_link_local_ip6(
"2803:6082:a2:4447::1");
1244 no_link_local_ip6 =
IPAddressV6(
"fe80::f652:14ff:ccc5:74d8");
1245 EXPECT_FALSE(no_link_local_ip6.getMacAddressFromLinkLocal().hasValue());
1246 no_link_local_ip6 =
IPAddressV6(
"fe80::f652:14ff:ffc5:74d8");
1247 EXPECT_FALSE(no_link_local_ip6.getMacAddressFromLinkLocal().hasValue());
1248 no_link_local_ip6 =
IPAddressV6(
"fe81::f652:14ff:ffc5:74d8");
1249 EXPECT_FALSE(no_link_local_ip6.getMacAddressFromLinkLocal().hasValue());
1252 TEST(IPAddress, getMacAddressFromEUI64) {
1253 IPAddressV6 ip6(
"2401:db00:3020:51dc:4a57:ddff:fe04:5643");
1257 EXPECT_TRUE(ip6.getMacAddressFromEUI64().hasValue());
1258 EXPECT_EQ(
"48:57:dd:04:56:43", ip6.getMacAddressFromEUI64()->toString());
1261 TEST(IPAddress, getMacAddressFromEUI64_Negative) {
1262 IPAddressV6 not_eui64_ip6(
"2401:db00:3020:51dc:face:0000:009a:0000");
1266 TEST(IPAddress, LongestCommonPrefix) {
1267 IPAddress ip10(
"10.0.0.0");
1268 IPAddress ip11(
"11.0.0.0");
1269 IPAddress ip12(
"12.0.0.0");
1270 IPAddress ip128(
"128.0.0.0");
1271 IPAddress ip10dot10(
"10.10.0.0");
1272 auto prefix = IPAddress::longestCommonPrefix({ip10, 8}, {ip128, 8});
1281 prefix = IPAddress::longestCommonPrefix({ip10, 8}, {ip10dot10, 16});
1283 {ip10.asV4(), 8}, {ip10dot10.asV4(), 16});
1290 prefix = IPAddress::longestCommonPrefix({ip11, 8}, {ip12, 8});
1300 prefix = IPAddress::longestCommonPrefix({ip128, 1}, {ip128, 2});
1308 IPAddress ip6(
"2620:0:1cfe:face:b00c::3");
1309 prefix = IPAddress::longestCommonPrefix(
1310 {ip6, ip6.bitCount()}, {ip6, ip6.bitCount()});
1318 EXPECT_EQ(ip6.asV6().bitCount(), prefix6.second);
1320 IPAddress ip6Zero(
"::");
1321 prefix = IPAddress::longestCommonPrefix({ip6, ip6.bitCount()}, {ip6Zero, 0});
1330 IPAddress::longestCommonPrefix({ip10, 8}, {ip6, 128}),
1331 std::invalid_argument);
1333 IPAddress::longestCommonPrefix({ip10, ip10.bitCount() + 1}, {ip10, 8}),
1334 std::invalid_argument);
1338 std::invalid_argument);
1340 IPAddress::longestCommonPrefix(
1341 {ip6, ip6.bitCount() + 1}, {ip6, ip6.bitCount()}),
1342 std::invalid_argument);
1347 std::invalid_argument);
1352 AddressData(
"69.63.189.16", {69, 63, 189, 16}, 4),
1354 AddressData(
"::1", {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1}, 6),
1356 "2620:0:1cfe:face:b00c::3",
1357 {38, 32, 0, 0, 28, 254, 250, 206, 176, 12, 0, 0, 0, 0, 0, 3},
1367 "127.0.0.1,127.0.0.1",
1372 {0x31, 0x32, 0x37, 0x2e, 0x30, 0x30, 0x2e, 0x30, 0x2e, 0x31},
1378 {0x00, 0x00, 0x00, 0x00, 0x00},
1471 {
"::ffff:192.0.2.128",
"192.0.2.128"},
1472 {
"192.0.2.128",
"::ffff:192.0.2.128"},
1473 {
"::FFFF:129.144.52.38",
"129.144.52.38"},
1474 {
"129.144.52.38",
"::FFFF:129.144.52.38"},
1475 {
"0:0:0:0:0:FFFF:222.1.41.90",
"222.1.41.90"},
1476 {
"::FFFF:222.1.41.90",
"222.1.41.90"},
1480 MaskData(
"255.255.255.255", 1,
"128.0.0.0"),
1481 MaskData(
"255.255.255.255", 2,
"192.0.0.0"),
1482 MaskData(
"192.0.2.42", 16,
"192.0.0.0"),
1483 MaskData(
"255.255.255.255", 24,
"255.255.255.0"),
1484 MaskData(
"255.255.255.255", 32,
"255.255.255.255"),
1485 MaskData(
"10.10.10.10", 0,
"0.0.0.0"),
1487 MaskData(
"2620:0:1cfe:face:b00c::3", 1,
"::"),
1488 MaskData(
"2620:0:1cfe:face:b00c::3", 3,
"2000::"),
1489 MaskData(
"2620:0:1cfe:face:b00c::3", 6,
"2400::"),
1490 MaskData(
"2620:0:1cfe:face:b00c::3", 7,
"2600::"),
1491 MaskData(
"2620:0:1cfe:face:b00c::3", 11,
"2620::"),
1492 MaskData(
"2620:0:1cfe:face:b00c::3", 36,
"2620:0:1000::"),
1493 MaskData(
"2620:0:1cfe:face:b00c::3", 37,
"2620:0:1800::"),
1494 MaskData(
"2620:0:1cfe:face:b00c::3", 38,
"2620:0:1c00::"),
1495 MaskData(
"2620:0:1cfe:face:b00c::3", 41,
"2620:0:1c80::"),
1496 MaskData(
"2620:0:1cfe:face:b00c::3", 42,
"2620:0:1cc0::"),
1497 MaskData(
"2620:0:1cfe:face:b00c::3", 43,
"2620:0:1ce0::"),
1498 MaskData(
"2620:0:1cfe:face:b00c::3", 44,
"2620:0:1cf0::"),
1499 MaskData(
"2620:0:1cfe:face:b00c::3", 45,
"2620:0:1cf8::"),
1500 MaskData(
"2620:0:1cfe:face:b00c::3", 46,
"2620:0:1cfc::"),
1501 MaskData(
"2620:0:1cfe:face:b00c::3", 47,
"2620:0:1cfe::"),
1502 MaskData(
"2620:0:1cfe:face:b00c::3", 49,
"2620:0:1cfe:8000::"),
1503 MaskData(
"2620:0:1cfe:face:b00c::3", 50,
"2620:0:1cfe:c000::"),
1504 MaskData(
"2620:0:1cfe:face:b00c::3", 51,
"2620:0:1cfe:e000::"),
1505 MaskData(
"2620:0:1cfe:face:b00c::3", 52,
"2620:0:1cfe:f000::"),
1506 MaskData(
"2620:0:1cfe:face:b00c::3", 53,
"2620:0:1cfe:f800::"),
1507 MaskData(
"2620:0:1cfe:face:b00c::3", 55,
"2620:0:1cfe:fa00::"),
1508 MaskData(
"2620:0:1cfe:face:b00c::3", 57,
"2620:0:1cfe:fa80::"),
1509 MaskData(
"2620:0:1cfe:face:b00c::3", 58,
"2620:0:1cfe:fac0::"),
1510 MaskData(
"2620:0:1cfe:face:b00c::3", 61,
"2620:0:1cfe:fac8::"),
1511 MaskData(
"2620:0:1cfe:face:b00c::3", 62,
"2620:0:1cfe:facc::"),
1512 MaskData(
"2620:0:1cfe:face:b00c::3", 63,
"2620:0:1cfe:face::"),
1513 MaskData(
"2620:0:1cfe:face:b00c::3", 65,
"2620:0:1cfe:face:8000::"),
1514 MaskData(
"2620:0:1cfe:face:b00c::3", 67,
"2620:0:1cfe:face:a000::"),
1515 MaskData(
"2620:0:1cfe:face:b00c::3", 68,
"2620:0:1cfe:face:b000::"),
1516 MaskData(
"2620:0:1cfe:face:b00c::3", 77,
"2620:0:1cfe:face:b008::"),
1517 MaskData(
"2620:0:1cfe:face:b00c::3", 78,
"2620:0:1cfe:face:b00c::"),
1518 MaskData(
"2620:0:1cfe:face:b00c::3", 127,
"2620:0:1cfe:face:b00c::2"),
1519 MaskData(
"2620:0:1cfe:face:b00c::3", 128,
"2620:0:1cfe:face:b00c::3"),
1520 MaskData(
"2620:0:1cfe:face:b00c::3", 0,
"::"),
1536 ::testing::ValuesIn(validAddressProvider));
1540 ::testing::ValuesIn(flagProvider));
1544 ::testing::ValuesIn(mapProvider));
1548 ::testing::ValuesIn(invalidAddressProvider));
1552 ::testing::ValuesIn(invalidBinaryProvider));
1556 ::testing::ValuesIn(masksProvider));
1560 ::testing::ValuesIn(maskBoundaryProvider));
1564 ::testing::ValuesIn(validAddressProvider));
1568 ::testing::ValuesIn(validAddressProvider));
1604 ByteArray8{{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}},
1605 ByteArray8{{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}},
1611 ByteArray8{{0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}},
1612 ByteArray8{{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}},
1618 ByteArray8{{0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xfe}},
1619 ByteArray8{{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}},
1625 ByteArray8{{0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff}},
1626 ByteArray8{{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}},
1632 ByteArray8{{0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff}},
1633 ByteArray8{{0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}},
1639 ByteArray8{{0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff}},
1640 ByteArray8{{0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xfe}},
1646 ByteArray8{{0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff}},
1647 ByteArray8{{0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff}},
static CIDRNetworkV6 longestCommonPrefix(const CIDRNetworkV6 &one, const CIDRNetworkV6 &two)
std::string toInverseArpaName() const
static CIDRNetworkV4 longestCommonPrefix(const CIDRNetworkV4 &one, const CIDRNetworkV4 &two)
static const uint8_t IS_MULTICAST
#define EXPECT_THROW(statement, expected_exception)
static in6_addr parseAddress6(const std::string &src)
SerializeData(const std::string &addr, const ByteVector &bytes_)
#define ASSERT_EQ(val1, val2)
Optional< MacAddress > getMacAddressFromLinkLocal() const
static const vector< pair< string, ByteArray16 > > provideBinary16Bytes
std::string sformat(StringPiece fmt, Args &&...args)
BitIterator< BaseIter > makeBitIterator(const BaseIter &iter)
static IPAddressV6 fromBinary(ByteRange bytes)
static constexpr size_t kMaxToFullyQualifiedSize
#define EXPECT_EQ(val1, val2)
static constexpr size_t bitCount()
static IPAddressV4 fromBinary(ByteRange bytes)
#define SCOPED_TRACE(message)
static const uint8_t IS_LINK_LOCAL_BROADCAST
—— Concurrent Priority Queue Implementation ——
static const vector< string > invalidAddressProvider
bool prefix(Cursor &c, uint32_t expected)
static const uint8_t IS_LINK_LOCAL
requires And< SemiMovable< VN >... > &&SemiMovable< E > auto error(E e)
static const vector< pair< string, uint8_t > > invalidMasks
sockaddr_in6 toSockAddr() const
folly::Optional< std::string > out6
static Expected< IPAddressV4, IPAddressFormatError > tryFromString(StringPiece str) noexcept
void setScopeId(uint16_t scope)
MaskBoundaryData(const std::string &addr, uint8_t mask_, const std::string &subnet_, bool inSubnet_)
AddressData(const std::string &address_, uint8_t version_)
static Expected< IPAddressV4, IPAddressFormatError > tryFromBinary(ByteRange bytes) noexcept
MaskData(const std::string &addr, uint8_t mask_, const std::string &subnet_)
static const uint8_t IS_PVT_NONROUTE
static in6_addr mkAddress6(const uint8_t *src)
std::array< uint8_t, 8 > ByteArray8
static Expected< IPAddressV6, IPAddressFormatError > tryFromBinary(ByteRange bytes) noexcept
AddressData(const std::string &address_, const ByteVector &bytes_, uint8_t version_)
static const vector< MaskBoundaryData > maskBoundaryProvider
static const uint8_t IS_ZERO
internal::ElementsAreArrayMatcher< typename::std::iterator_traits< Iter >::value_type > ElementsAreArray(Iter first, Iter last)
static in_addr parseAddress4(const std::string &src)
static constexpr size_t kToFullyQualifiedSize
static const ByteArray16 fetchMask(size_t numBits)
constexpr auto data(C &c) -> decltype(c.data())
static bool validate(StringPiece ip) noexcept
static const uint8_t IS_LINK_LOCAL_BROADCAST
static const ByteArray4 fetchMask(size_t numBits)
static Expected< IPAddressV6, IPAddressFormatError > tryFromString(StringPiece str) noexcept
std::array< uint8_t, 16 > ByteArray16
IPAddressV6 getIPv6For6To4() const
static const uint8_t IS_LINK_LOCAL
folly::Optional< std::string > out
bool isNonroutable() const
static const uint8_t IS_LOCAL
AddressFlags(const std::string &addr, uint8_t version_, uint8_t flags_)
static std::vector< StringTestParam > ipInOutProvider()
Optional< MacAddress > getMacAddressFromEUI64() const
static const vector< AddressData > validAddressProvider
#define EXPECT_TRUE(condition)
#define EXPECT_THAT(value, matcher)
static const vector< string > ipv4Strs
static const uint8_t IS_NONROUTABLE
static in_addr mkAddress4(const uint8_t *src)
static const uint8_t IS_LOCAL
Range< const unsigned char * > ByteRange
#define EXPECT_NE(val1, val2)
static bool validate(StringPiece ip) noexcept
INSTANTIATE_TEST_CASE_P(IPAddress, IPAddressTest,::testing::ValuesIn(validAddressProvider))
Map mapped(Predicate pred=Predicate())
TEST_P(IPAddressTest, CtorAddress)
static const vector< pair< string, uint32_t > > provideToLong
static IPAddressV6 fromInverseArpaName(const std::string &arpaname)
static const vector< ByteVector > invalidBinaryProvider
static const uint8_t IS_NONROUTABLE
bool isLinkLocalBroadcast() const
void ExpectIsValid(const IPAddress &addr)
std::vector< uint8_t > ByteVector
#define ASSERT_FALSE(condition)
std::string fastIpv4ToString(const in_addr &inAddr)
#define EXPECT_FALSE(condition)
static const vector< MaskData > masksProvider
std::array< uint8_t, 4 > ByteArray4
static const uint8_t IS_PRIVATE
static constexpr size_t bitCount()
static const uint8_t IS_MULTICAST
folly::Optional< std::string > out4
AddressData(const std::string &address_)
static std::string toHex(const uint8_t *src, std::size_t len)
std::string fastIpv6ToString(const in6_addr &in6Addr)
static IPAddressV4 fromInverseArpaName(const std::string &arpaname)
#define ASSERT_TRUE(condition)
static const vector< pair< string, IPAddressV6::Type > > v6types
ThreadPoolListHook * addr
TEST(SequencedExecutor, CPUThreadPoolExecutor)
static const vector< pair< string, string > > mapProvider
static const uint8_t IS_PRIVATE
static const uint8_t IS_ZERO
#define EXPECT_GT(val1, val2)
static vector< AddressFlags > flagProvider