41 result->append(addr.
str());
48 return tryFromString(ip).hasValue();
60 addr.s_addr = htonl(src);
68 if (inet_pton(AF_INET,
str.c_str(), &
addr) != 1) {
70 sformat(
"Can't convert invalid IP '{}' to long", ip));
89 if (maybeIp.hasError()) {
91 to<std::string>(
"Invalid IPv4 address '", addr,
"'"));
98 struct in_addr inAddr;
99 if (inet_pton(AF_INET,
str.str().c_str(), &inAddr) != 1) {
110 if (maybeIp.hasError()) {
112 "Invalid IPv4 binary data: length must be 4 bytes, got ",
115 return maybeIp.value();
122 if (setResult.hasError()) {
130 if (
bytes.size() != 4) {
141 if (!piece.removeSuffix(
".in-addr.arpa")) {
143 sformat(
"input does not end with '.in-addr.arpa': '{}'", arpaname));
145 std::vector<StringPiece> pieces;
146 split(
".", piece, pieces);
147 if (pieces.size() != 4) {
157 std::memcpy(&ba[12],
bytes(), 4);
166 std::memcpy(&ba[2],
bytes(), 4);
172 return sformat(
"{{family:'AF_INET', addr:'{}', hash:{}}}",
str(),
hash());
177 auto subnetInfo = IPAddress::createNetwork(cidrNetwork);
178 auto addr = subnetInfo.first;
181 sformat(
"Address '{}' is not a V4 address",
addr.toJson()));
192 return (
mask == subMask);
211 (
true && ip <= 0x00FFFFFF) ||
212 (ip >= 0xC0000000 && ip <= 0xC00000FF) ||
213 (ip >= 0xC0000200 && ip <= 0xC00002FF) ||
214 (ip >= 0xC6120000 && ip <= 0xC613FFFF) ||
215 (ip >= 0xC6336400 && ip <= 0xC63364FF) ||
216 (ip >= 0xCB007100 && ip <= 0xCB0071FF) ||
217 (ip >= 0xE0000000 && ip <= 0xFFFFFFFF) ||
225 (ip >= 0x0A000000 && ip <= 0x0AFFFFFF) ||
226 (ip >= 0x7F000000 && ip <= 0x7FFFFFFF) ||
227 (ip >= 0xA9FE0000 && ip <= 0xA9FEFFFF) ||
228 (ip >= 0xAC100000 && ip <= 0xAC1FFFFF) ||
229 (ip >= 0xC0A80000 && ip <= 0xC0A8FFFF) ||
235 return (
toLongHBO() & 0xf0000000) == 0xe0000000;
240 static const auto bits =
bitCount();
241 if (numBits > bits) {
243 sformat(
"numBits({}) > bitsCount({})", numBits, bits));
263 "{}.{}.{}.{}.in-addr.arpa",
272 const auto highestIndex =
byteCount() - 1;
273 if (byteIndex > highestIndex) {
274 throw std::invalid_argument(
sformat(
275 "Byte index must be <= {} for addresses of type: {}",
279 return bytes()[byteIndex];
283 static const size_t bits =
bitCount();
284 if (numBits > bits) {
289 std::memcpy(arr.data(), &
val,
sizeof(
val));
297 one.first.addr_.bytes_, one.second, two.first.addr_.bytes_, two.second);
IPAddressV4 mask(size_t numBits) const
std::string toInverseArpaName() const
static CIDRNetworkV4 longestCommonPrefix(const CIDRNetworkV4 &one, const CIDRNetworkV4 &two)
static const uint32_t PREFIX_6TO4
std::string sformat(StringPiece fmt, Args &&...args)
bool isNonroutable() const
static size_t byteCount()
constexpr detail::Map< Move > move
static std::array< uint8_t, N > mask(const std::array< uint8_t, N > &a, const std::array< uint8_t, N > &b)
constexpr size_type size() const
static IPAddressV4 fromBinary(ByteRange bytes)
—— Concurrent Priority Queue Implementation ——
uint8_t getNthMSByte(size_t byteIndex) const
requires E e noexcept(noexcept(s.error(std::move(e))))
bool prefix(Cursor &c, uint32_t expected)
static Expected< IPAddressV4, IPAddressFormatError > tryFromString(StringPiece str) noexcept
void split(const Delim &delimiter, const String &input, std::vector< OutputType > &out, bool ignoreEmpty)
ByteArray4 toByteArray() const
static Expected< IPAddressV4, IPAddressFormatError > tryFromBinary(ByteRange bytes) noexcept
union folly::IPAddressV4::AddressStorage addr_
bool inSubnetWithMask(const IPAddressV4 &subnet, const ByteArray4 mask) const
static IPAddressV4 fromLong(uint32_t src)
constexpr Unexpected< typename std::decay< Error >::type > makeUnexpected(Error &&)
static const ByteArray4 fetchMask(size_t numBits)
std::array< uint8_t, 16 > ByteArray16
IPAddressV6 getIPv6For6To4() const
size_t hash_value(const IPAddress &addr)
const unsigned char * bytes() const
std::pair< IPAddressV4, uint8_t > CIDRNetworkV4
static std::pair< std::array< uint8_t, N >, uint8_t > longestCommonPrefix(const std::array< uint8_t, N > &one, uint8_t oneMask, const std::array< uint8_t, N > &two, uint8_t twoMask)
void toFullyQualifiedAppend(std::string &out) const
void toAppend(char value, Tgt *result)
Expected< Unit, IPAddressFormatError > trySetFromBinary(ByteRange bytes) noexcept
std::string toJson() const
uint32_t toLongHBO() const
static IPAddressV4 fromLongHBO(uint32_t src)
static bool validate(StringPiece ip) noexcept
void join(const Delim &delimiter, Iterator begin, Iterator end, String &output)
bool inSubnet(StringPiece cidrNetwork) const
std::string fastIpv4ToString(const in_addr &inAddr)
basic_fbstring & append(const basic_fbstring &str)
void fastIpv4AppendToString(const in_addr &inAddr, std::string &out)
std::array< uint8_t, 4 > ByteArray4
static constexpr size_t bitCount()
Range< const char * > StringPiece
static IPAddressV4 fromInverseArpaName(const std::string &arpaname)
std::string familyNameStr(sa_family_t family)
ThreadPoolListHook * addr
IPAddressV6 createIPv6() const
std::ostream & operator<<(std::ostream &out, dynamic const &d)