proxygen
|
#include <IPAddressV4.h>
Classes | |
union | AddressStorage |
Public Member Functions | |
ByteRange | toBinary () const |
IPAddressV4 () | |
IPAddressV4 (StringPiece ip) | |
IPAddressV4 (const ByteArray4 &src) noexcept | |
IPAddressV4 (const in_addr src) noexcept | |
IPAddressV6 | createIPv6 () const |
IPAddressV6 | getIPv6For6To4 () const |
uint32_t | toLong () const |
uint32_t | toLongHBO () const |
std::string | toJson () const |
size_t | hash () const |
bool | inSubnet (StringPiece cidrNetwork) const |
bool | inSubnet (const IPAddressV4 &subnet, uint8_t cidr) const |
bool | inSubnetWithMask (const IPAddressV4 &subnet, const ByteArray4 mask) const |
bool | isLoopback () const |
bool | isLinkLocal () const |
bool | isNonroutable () const |
bool | isPrivate () const |
bool | isMulticast () const |
bool | isZero () const |
bool | isLinkLocalBroadcast () const |
IPAddressV4 | mask (size_t numBits) const |
std::string | str () const |
std::string | toInverseArpaName () const |
in_addr | toAddr () const |
sockaddr_in | toSockAddr () const |
ByteArray4 | toByteArray () const |
std::string | toFullyQualified () const |
void | toFullyQualifiedAppend (std::string &out) const |
uint8_t | version () const |
bool | getNthMSBit (size_t bitIndex) const |
uint8_t | getNthMSByte (size_t byteIndex) const |
bool | getNthLSBit (size_t bitIndex) const |
uint8_t | getNthLSByte (size_t byteIndex) const |
const unsigned char * | bytes () const |
Static Public Member Functions | |
static bool | validate (StringPiece ip) noexcept |
static IPAddressV4 | fromLong (uint32_t src) |
static IPAddressV4 | fromLongHBO (uint32_t src) |
static IPAddressV4 | fromBinary (ByteRange bytes) |
static Expected< IPAddressV4, IPAddressFormatError > | tryFromBinary (ByteRange bytes) noexcept |
static Expected< IPAddressV4, IPAddressFormatError > | tryFromString (StringPiece str) noexcept |
static IPAddressV4 | fromInverseArpaName (const std::string &arpaname) |
static uint32_t | toLong (StringPiece ip) |
static uint32_t | toLongHBO (StringPiece ip) |
static constexpr size_t | bitCount () |
static const ByteArray4 | fetchMask (size_t numBits) |
static CIDRNetworkV4 | longestCommonPrefix (const CIDRNetworkV4 &one, const CIDRNetworkV4 &two) |
static size_t | byteCount () |
Static Public Attributes | |
static constexpr size_t | kMaxToFullyQualifiedSize |
Private Member Functions | |
Expected< Unit, IPAddressFormatError > | trySetFromBinary (ByteRange bytes) noexcept |
Private Attributes | |
union folly::IPAddressV4::AddressStorage | addr_ |
IPv4 variation of IPAddress.
Added methods: toLong, toLongHBO and createIPv6
Definition at line 58 of file IPAddressV4.h.
folly::IPAddressV4::IPAddressV4 | ( | ) |
Default constructor for IPAddressV4.
The address value will be 0.0.0.0
Definition at line 81 of file IPAddressV4.cpp.
Referenced by fromInverseArpaName(), fromLong(), fromLongHBO(), longestCommonPrefix(), mask(), toBinary(), and tryFromString().
|
explicit |
Definition at line 87 of file IPAddressV4.cpp.
References folly::gen::move, and tryFromString().
|
explicitnoexcept |
Definition at line 84 of file IPAddressV4.cpp.
|
explicitnoexcept |
Definition at line 106 of file IPAddressV4.cpp.
|
inlinestatic |
Definition at line 156 of file IPAddressV4.h.
References string, and toJson().
Referenced by fetchMask(), getNthLSBit(), mask(), and TEST().
|
inlinestatic |
Definition at line 262 of file IPAddressV4.h.
Referenced by getNthLSByte(), and getNthMSByte().
|
inline |
Definition at line 280 of file IPAddressV4.h.
References addr_, and folly::IPAddressV4::AddressStorage::bytes_.
Referenced by folly::IPAddressV4::AddressStorage::AddressStorage(), createIPv6(), getIPv6For6To4(), getNthMSByte(), isZero(), toByteArray(), tryFromBinary(), and trySetFromBinary().
IPAddressV6 folly::IPAddressV4::createIPv6 | ( | ) | const |
|
static |
Return the mask associated with the given number of bits. If for instance numBits was 24 (e.g. /24) then the V4 mask returned should be {0xff, 0xff, 0xff, 0x00}.
[in] | numBits | bitmask to retrieve |
abort | if numBits == 0 or numBits > bitCount() |
Definition at line 282 of file IPAddressV4.cpp.
References folly::Endian::big(), bitCount(), uint32_t, uint64_t, and val.
Referenced by inSubnet(), isLinkLocal(), isLoopback(), mask(), TEST(), and version().
|
static |
Create a new IPAddress instance from the provided binary data.
IPAddressFormatException | if the input length is not 4 bytes. |
Definition at line 108 of file IPAddressV4.cpp.
References folly::Range< Iter >::size(), and tryFromBinary().
Referenced by TEST(), TEST_P(), and folly::toAppend().
|
static |
Create a new IPAddress instance from the in-addr.arpa representation.
IPAddressFormatException | if the input is not a valid in-addr.arpa representation |
Definition at line 138 of file IPAddressV4.cpp.
References IPAddressV4(), folly::join(), folly::sformat(), and folly::split().
Referenced by TEST(), and toBinary().
|
static |
Definition at line 52 of file IPAddressV4.cpp.
References addr, and IPAddressV4().
Referenced by folly::toAppend().
|
static |
Definition at line 58 of file IPAddressV4.cpp.
References addr, and IPAddressV4().
Referenced by folly::toAppend().
IPAddressV6 folly::IPAddressV4::getIPv6For6To4 | ( | ) | const |
Return a V6 address in the format of an 6To4 address.
Definition at line 162 of file IPAddressV4.cpp.
References bytes(), folly::IPAddressV6::PREFIX_6TO4, and uint8_t.
Referenced by TEST(), and toBinary().
|
inline |
Definition at line 272 of file IPAddressV4.h.
References bitCount(), and getNthMSBit().
|
inline |
Definition at line 276 of file IPAddressV4.h.
References byteCount(), and getNthMSByte().
|
inline |
Definition at line 266 of file IPAddressV4.h.
References folly::detail::getNthMSBitImpl(), getNthMSByte(), and uint8_t.
Referenced by getNthLSBit().
uint8_t folly::IPAddressV4::getNthMSByte | ( | size_t | byteIndex | ) | const |
Definition at line 271 of file IPAddressV4.cpp.
References byteCount(), bytes(), folly::detail::familyNameStr(), and folly::sformat().
Referenced by getNthLSByte(), and getNthMSBit().
|
inline |
Definition at line 165 of file IPAddressV4.h.
References addr_, folly::hash::fnv32_buf(), folly::hash::hash_combine(), inSubnet(), seed, and uint32_t.
Referenced by folly::hash_value(), std::hash< folly::IPAddressV4 >::operator()(), and toJson().
bool folly::IPAddressV4::inSubnet | ( | StringPiece | cidrNetwork | ) | const |
Definition at line 176 of file IPAddressV4.cpp.
References addr, fetchMask(), inSubnetWithMask(), and folly::sformat().
Referenced by hash(), and folly::toAppend().
|
inline |
Definition at line 176 of file IPAddressV4.h.
References fetchMask(), inSubnetWithMask(), isLinkLocal(), isLoopback(), isMulticast(), isNonroutable(), isPrivate(), and mask().
bool folly::IPAddressV4::inSubnetWithMask | ( | const IPAddressV4 & | subnet, |
const ByteArray4 | mask | ||
) | const |
Definition at line 187 of file IPAddressV4.cpp.
References folly::detail::Bytes::mask(), mask(), and toByteArray().
Referenced by inSubnet(), isLinkLocal(), isLoopback(), and folly::toAppend().
bool folly::IPAddressV4::isLinkLocal | ( | ) | const |
Definition at line 202 of file IPAddressV4.cpp.
References fetchMask(), and inSubnetWithMask().
Referenced by inSubnet().
|
inline |
Definition at line 202 of file IPAddressV4.h.
References mask(), str(), string, toInverseArpaName(), and toLongHBO().
bool folly::IPAddressV4::isLoopback | ( | ) | const |
Definition at line 196 of file IPAddressV4.cpp.
References fetchMask(), and inSubnetWithMask().
Referenced by inSubnet().
bool folly::IPAddressV4::isMulticast | ( | ) | const |
bool folly::IPAddressV4::isNonroutable | ( | ) | const |
Definition at line 208 of file IPAddressV4.cpp.
References isPrivate(), and toLongHBO().
Referenced by inSubnet().
bool folly::IPAddressV4::isPrivate | ( | ) | const |
Definition at line 222 of file IPAddressV4.cpp.
References toLongHBO().
Referenced by inSubnet(), and isNonroutable().
|
inline |
|
static |
Definition at line 293 of file IPAddressV4.cpp.
References IPAddressV4(), folly::detail::Bytes::longestCommonPrefix(), and prefix().
Referenced by folly::operator<(), TEST(), and version().
IPAddressV4 folly::IPAddressV4::mask | ( | size_t | numBits | ) | const |
Definition at line 239 of file IPAddressV4.cpp.
References addr_, bitCount(), folly::IPAddressV4::AddressStorage::bytes_, fetchMask(), IPAddressV4(), folly::detail::Bytes::mask(), and folly::sformat().
Referenced by inSubnet(), inSubnetWithMask(), and isLinkLocalBroadcast().
string folly::IPAddressV4::str | ( | ) | const |
Definition at line 251 of file IPAddressV4.cpp.
References addr_, folly::detail::fastIpv4ToString(), and folly::IPAddressV4::AddressStorage::inAddr_.
Referenced by isLinkLocalBroadcast(), folly::operator<<(), folly::toAppend(), toFullyQualified(), toJson(), toLong(), and tryFromString().
|
inline |
Definition at line 215 of file IPAddressV4.h.
References addr_, and folly::IPAddressV4::AddressStorage::inAddr_.
Referenced by BENCHMARK(), and toLong().
|
inline |
Returns the address as a Range.
Definition at line 95 of file IPAddressV4.h.
References addr_, createIPv6(), fromInverseArpaName(), getIPv6For6To4(), folly::IPAddressV4::AddressStorage::inAddr_, IPAddressV4(), folly::pushmi::__adl::noexcept(), string, toLong(), toLongHBO(), and uint32_t.
|
inline |
|
inline |
Definition at line 234 of file IPAddressV4.h.
References str(), string, and toFullyQualifiedAppend().
Referenced by BENCHMARK(), and BENCHMARK_RELATIVE().
void folly::IPAddressV4::toFullyQualifiedAppend | ( | std::string & | out | ) | const |
Definition at line 256 of file IPAddressV4.cpp.
References addr_, folly::detail::fastIpv4AppendToString(), and folly::IPAddressV4::AddressStorage::inAddr_.
Referenced by BENCHMARK_RELATIVE(), and toFullyQualified().
string folly::IPAddressV4::toInverseArpaName | ( | ) | const |
Definition at line 261 of file IPAddressV4.cpp.
References addr_, folly::IPAddressV4::AddressStorage::bytes_, and folly::sformat().
Referenced by isLinkLocalBroadcast(), and TEST().
string folly::IPAddressV4::toJson | ( | ) | const |
IPAddress::toJson
Definition at line 171 of file IPAddressV4.cpp.
References hash(), folly::sformat(), and str().
Referenced by bitCount().
|
static |
Convert a IPv4 address string to a long in network byte order.
[in] | ip | the address to convert |
Definition at line 65 of file IPAddressV4.cpp.
References addr, folly::sformat(), str(), and folly::Range< Iter >::str().
Referenced by folly::operator==().
|
inline |
Definition at line 142 of file IPAddressV4.h.
References toAddr().
Referenced by toBinary(), and toLongHBO().
|
static |
Definition at line 76 of file IPAddressV4.cpp.
References toLong().
Referenced by folly::operator<().
|
inline |
Definition at line 148 of file IPAddressV4.h.
References toLong().
Referenced by isLinkLocalBroadcast(), isMulticast(), isNonroutable(), isPrivate(), and toBinary().
|
inline |
Definition at line 219 of file IPAddressV4.h.
References addr, addr_, and folly::IPAddressV4::AddressStorage::inAddr_.
|
staticnoexcept |
Non-throwing version of fromBinary(). On failure returns IPAddressFormatError.
Definition at line 118 of file IPAddressV4.cpp.
References addr, bytes(), folly::makeUnexpected(), folly::gen::move, and trySetFromBinary().
Referenced by fromBinary(), TEST(), TEST_P(), and folly::toAppend().
|
staticnoexcept |
Tries to create a new IPAddressV4 instance from provided string and returns it on success. Returns IPAddressFormatError on failure.
Definition at line 96 of file IPAddressV4.cpp.
References folly::INVALID_IP, IPAddressV4(), folly::makeUnexpected(), and str().
Referenced by IPAddressV4(), TEST_P(), and folly::toAppend().
|
privatenoexcept |
Set the current IPAddressV4 object to have the address specified by bytes. Returns IPAddressFormatError if bytes.size() is not 4.
Definition at line 128 of file IPAddressV4.cpp.
References addr_, bytes(), folly::IPAddressV4::AddressStorage::inAddr_, folly::INVALID_IP, folly::makeUnexpected(), and folly::unit.
Referenced by folly::IPAddressV4::AddressStorage::AddressStorage(), and tryFromBinary().
|
staticnoexcept |
Definition at line 47 of file IPAddressV4.cpp.
Referenced by TEST(), and folly::toAppend().
|
inline |
Definition at line 242 of file IPAddressV4.h.
References fetchMask(), and longestCommonPrefix().
|
private |
|
static |
Definition at line 61 of file IPAddressV4.h.
Referenced by BENCHMARK_RELATIVE(), and TEST().