throw IPAddressFormatException(
to<std::string>("IPv4 addresses are 32 bits"));
}
- // masks_ is backed by an array so is zero indexed
- return masks_[numBits];
+ auto const val = Endian::big(uint32_t(~uint64_t(0) << (32 - numBits)));
+ ByteArray4 arr;
+ std::memcpy(arr.data(), &val, sizeof(val));
+ return arr;
}
// public static
CIDRNetworkV4 IPAddressV4::longestCommonPrefix(
return {IPAddressV4(prefix.first), prefix.second};
}
-// static private
-const std::array<ByteArray4, 33> IPAddressV4::masks_ = {{
- {{0x00, 0x00, 0x00, 0x00}},
- {{0x80, 0x00, 0x00, 0x00}},
- {{0xc0, 0x00, 0x00, 0x00}},
- {{0xe0, 0x00, 0x00, 0x00}},
- {{0xf0, 0x00, 0x00, 0x00}},
- {{0xf8, 0x00, 0x00, 0x00}},
- {{0xfc, 0x00, 0x00, 0x00}},
- {{0xfe, 0x00, 0x00, 0x00}},
- {{0xff, 0x00, 0x00, 0x00}},
- {{0xff, 0x80, 0x00, 0x00}},
- {{0xff, 0xc0, 0x00, 0x00}},
- {{0xff, 0xe0, 0x00, 0x00}},
- {{0xff, 0xf0, 0x00, 0x00}},
- {{0xff, 0xf8, 0x00, 0x00}},
- {{0xff, 0xfc, 0x00, 0x00}},
- {{0xff, 0xfe, 0x00, 0x00}},
- {{0xff, 0xff, 0x00, 0x00}},
- {{0xff, 0xff, 0x80, 0x00}},
- {{0xff, 0xff, 0xc0, 0x00}},
- {{0xff, 0xff, 0xe0, 0x00}},
- {{0xff, 0xff, 0xf0, 0x00}},
- {{0xff, 0xff, 0xf8, 0x00}},
- {{0xff, 0xff, 0xfc, 0x00}},
- {{0xff, 0xff, 0xfe, 0x00}},
- {{0xff, 0xff, 0xff, 0x00}},
- {{0xff, 0xff, 0xff, 0x80}},
- {{0xff, 0xff, 0xff, 0xc0}},
- {{0xff, 0xff, 0xff, 0xe0}},
- {{0xff, 0xff, 0xff, 0xf0}},
- {{0xff, 0xff, 0xff, 0xf8}},
- {{0xff, 0xff, 0xff, 0xfc}},
- {{0xff, 0xff, 0xff, 0xfe}},
- {{0xff, 0xff, 0xff, 0xff}}
-}};
-
} // folly