proxygen
|
#include <IPAddressV6.h>
Classes | |
union | AddressStorage |
Public Types | |
enum | Type { TEREDO, T6TO4, NORMAL } |
enum | LinkLocalTag { LINK_LOCAL } |
typedef std::runtime_error | TypeError |
Public Member Functions | |
ByteRange | toBinary () const |
IPAddressV6 () | |
IPAddressV6 (StringPiece ip) | |
IPAddressV6 (const ByteArray16 &src) noexcept | |
IPAddressV6 (const in6_addr &src) noexcept | |
IPAddressV6 (const sockaddr_in6 &src) noexcept | |
IPAddressV6 (LinkLocalTag tag, MacAddress mac) | |
IPAddressV4 | createIPv4 () const |
IPAddressV4 | getIPv4For6To4 () const |
bool | is6To4 () const |
bool | isTeredo () const |
bool | isIPv4Mapped () const |
Type | type () const |
std::string | toJson () const |
size_t | hash () const |
bool | inSubnet (StringPiece cidrNetwork) const |
bool | inSubnet (const IPAddressV6 &subnet, uint8_t cidr) const |
bool | inSubnetWithMask (const IPAddressV6 &subnet, const ByteArray16 &mask) const |
bool | isLoopback () const |
bool | isNonroutable () const |
bool | isRoutable () const |
bool | isPrivate () const |
bool | isLinkLocal () const |
Optional< MacAddress > | getMacAddressFromLinkLocal () const |
Optional< MacAddress > | getMacAddressFromEUI64 () const |
bool | isMulticast () const |
uint8_t | getMulticastFlags () const |
uint8_t | getMulticastScope () const |
bool | isZero () const |
bool | isLinkLocalBroadcast () const |
IPAddressV6 | mask (size_t numBits) const |
in6_addr | toAddr () const |
uint16_t | getScopeId () const |
void | setScopeId (uint16_t scope) |
sockaddr_in6 | toSockAddr () const |
ByteArray16 | toByteArray () const |
std::string | toFullyQualified () const |
void | toFullyQualifiedAppend (std::string &out) const |
std::string | toInverseArpaName () const |
std::string | str () const |
uint8_t | version () const |
IPAddressV6 | getSolicitedNodeAddress () 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 IPAddressV6 | fromBinary (ByteRange bytes) |
static Expected< IPAddressV6, IPAddressFormatError > | tryFromBinary (ByteRange bytes) noexcept |
static Expected< IPAddressV6, IPAddressFormatError > | tryFromString (StringPiece str) noexcept |
static IPAddressV6 | fromInverseArpaName (const std::string &arpaname) |
static constexpr size_t | bitCount () |
static const ByteArray16 | fetchMask (size_t numBits) |
static CIDRNetworkV6 | longestCommonPrefix (const CIDRNetworkV6 &one, const CIDRNetworkV6 &two) |
static constexpr size_t | byteCount () |
Static Public Attributes | |
static const uint32_t | PREFIX_TEREDO = 0x20010000 |
static const uint32_t | PREFIX_6TO4 = 0x2002 |
static constexpr size_t | kToFullyQualifiedSize |
Protected Member Functions | |
bool | inBinarySubnet (const std::array< uint8_t, 2 > addr, size_t numBits) const |
Private Member Functions | |
auto | tie () const |
Expected< Unit, IPAddressFormatError > | trySetFromBinary (ByteRange bytes) noexcept |
Private Attributes | |
union folly::IPAddressV6::AddressStorage | addr_ |
uint16_t | scope_ {0} |
Friends | |
bool | operator== (const IPAddressV6 &a, const IPAddressV6 &b) |
bool | operator!= (const IPAddressV6 &a, const IPAddressV6 &b) |
bool | operator< (const IPAddressV6 &a, const IPAddressV6 &b) |
bool | operator> (const IPAddressV6 &a, const IPAddressV6 &b) |
bool | operator<= (const IPAddressV6 &a, const IPAddressV6 &b) |
bool | operator>= (const IPAddressV6 &a, const IPAddressV6 &b) |
IPv6 variation of IPAddress.
Added methods: createIPv4, getIPv4For6To4, is6To4, isTeredo, isIPv4Mapped, tryCreateIPv4, type
Notes on scope ID parsing:
getaddrinfo() uses if_nametoindex() to convert interface names into a numerical index. For instance, "fe80::202:c9ff:fec1:ee08%eth0" may return scope ID 2 on some hosts, but other numbers on other hosts. It will fail entirely on hosts without an eth0 interface.
Serializing / Deserializing IPAddressB6's on different hosts that use link-local scoping probably won't work.
Definition at line 71 of file IPAddressV6.h.
typedef std::runtime_error folly::IPAddressV6::TypeError |
Definition at line 85 of file IPAddressV6.h.
Enumerator | |
---|---|
LINK_LOCAL |
Definition at line 81 of file IPAddressV6.h.
Enumerator | |
---|---|
TEREDO | |
T6TO4 | |
NORMAL |
Definition at line 74 of file IPAddressV6.h.
folly::IPAddressV6::IPAddressV6 | ( | ) |
Default constructor for IPAddressV6.
The address value will be ::0
Definition at line 70 of file IPAddressV6.cpp.
Referenced by fromInverseArpaName(), longestCommonPrefix(), mask(), toBinary(), and tryFromString().
|
explicit |
Definition at line 73 of file IPAddressV6.cpp.
References folly::gen::move, and tryFromString().
|
explicitnoexcept |
Definition at line 119 of file IPAddressV6.cpp.
|
explicitnoexcept |
Definition at line 112 of file IPAddressV6.cpp.
|
explicitnoexcept |
Definition at line 115 of file IPAddressV6.cpp.
folly::IPAddressV6::IPAddressV6 | ( | LinkLocalTag | tag, |
MacAddress | mac | ||
) |
Create a link-local IPAddressV6 from the specified ethernet MAC address.
Definition at line 122 of file IPAddressV6.cpp.
|
inlinestatic |
Definition at line 189 of file IPAddressV6.h.
References hash(), inSubnet(), string, and toJson().
Referenced by fetchMask(), getNthLSBit(), mask(), and TEST().
|
inlinestatic |
Definition at line 348 of file IPAddressV6.h.
Referenced by getNthLSByte(), and getNthMSByte().
|
inline |
Definition at line 367 of file IPAddressV6.h.
References addr, addr_, folly::IPAddressV6::AddressStorage::in6Addr_, and inBinarySubnet().
Referenced by createIPv4(), folly::MacAddress::createMulticast(), getIPv4For6To4(), getMacAddressFromEUI64(), getNthMSByte(), getSolicitedNodeAddress(), isIPv4Mapped(), isZero(), str(), toByteArray(), toInverseArpaName(), tryFromBinary(), trySetFromBinary(), and type().
IPAddressV4 folly::IPAddressV6::createIPv4 | ( | ) | const |
Definition at line 227 of file IPAddressV6.cpp.
References bytes(), isIPv4Mapped(), and folly::detail::Bytes::mkAddress4().
Referenced by isLoopback(), isPrivate(), and toBinary().
|
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 501 of file IPAddressV6.cpp.
References folly::Endian::big(), bitCount(), and uint64_t.
Referenced by inSubnet(), mask(), TEST(), and version().
|
static |
Create a new IPAddress instance from the provided binary data.
IPAddressFormatException | if the input length is not 16 bytes. |
Definition at line 168 of file IPAddressV6.cpp.
References folly::Range< Iter >::size(), and tryFromBinary().
Referenced by getSolicitedNodeAddress(), TEST(), TEST_P(), and folly::toAppend().
|
static |
Create a new IPAddress instance from the ip6.arpa representation.
IPAddressFormatException | if the input is not a valid ip6.arpa representation |
Definition at line 199 of file IPAddressV6.cpp.
References count, i, IPAddressV6(), folly::range(), folly::sformat(), and folly::split().
Referenced by TEST().
IPAddressV4 folly::IPAddressV6::getIPv4For6To4 | ( | ) | const |
Return a V4 address if this is a 6To4 address.
TypeError | if not a 6To4 address |
Definition at line 252 of file IPAddressV6.cpp.
References addr, bytes(), is6To4(), folly::sformat(), str(), uint16_t, uint8_t, and folly::unpackInto().
Referenced by folly::toAppend(), and toBinary().
Optional< MacAddress > folly::IPAddressV6::getMacAddressFromEUI64 | ( | ) | const |
Return the mac address if this is an auto-configured IPv6 address based on EUI-64
Definition at line 147 of file IPAddressV6.cpp.
References addr_, bytes(), folly::IPAddressV6::AddressStorage::bytes_, folly::MacAddress::fromBinary(), folly::none, and folly::range().
Referenced by getMacAddressFromLinkLocal(), isNonroutable(), and TEST().
Optional< MacAddress > folly::IPAddressV6::getMacAddressFromLinkLocal | ( | ) | const |
Return the mac address if this is a link-local IPv6 address.
If the address is not a link-local one it will return an empty Optional. You can use Optional::value() to check whether the mac address is not null.
Definition at line 139 of file IPAddressV6.cpp.
References getMacAddressFromEUI64(), isLinkLocal(), and folly::none.
Referenced by isNonroutable(), and TEST().
uint8_t folly::IPAddressV6::getMulticastFlags | ( | ) | const |
Return the flags for a multicast address. This method may only be called on multicast addresses.
Definition at line 390 of file IPAddressV6.cpp.
References addr_, folly::IPAddressV6::AddressStorage::bytes_, isMulticast(), and uint8_t.
Referenced by isNonroutable().
uint8_t folly::IPAddressV6::getMulticastScope | ( | ) | const |
Return the scope for a multicast address. This method may only be called on multicast addresses.
Definition at line 395 of file IPAddressV6.cpp.
References addr_, folly::IPAddressV6::AddressStorage::bytes_, isMulticast(), and uint8_t.
Referenced by isNonroutable(), and isRoutable().
|
inline |
Definition at line 359 of file IPAddressV6.h.
References bitCount(), and getNthMSBit().
|
inline |
Definition at line 363 of file IPAddressV6.h.
References byteCount(), and getNthMSByte().
|
inline |
Definition at line 353 of file IPAddressV6.h.
References folly::detail::getNthMSBitImpl(), getNthMSByte(), and uint8_t.
Referenced by getNthLSBit().
uint8_t folly::IPAddressV6::getNthMSByte | ( | size_t | byteIndex | ) | const |
Definition at line 489 of file IPAddressV6.cpp.
References byteCount(), bytes(), folly::detail::familyNameStr(), and folly::sformat().
Referenced by getNthLSByte(), and getNthMSBit().
|
inline |
IPAddressV6 folly::IPAddressV6::getSolicitedNodeAddress | ( | ) | const |
Return the solicited-node multicast address for this address.
Definition at line 400 of file IPAddressV6.cpp.
References addr_, bytes(), folly::IPAddressV6::AddressStorage::bytes_, fromBinary(), isMulticast(), and uint8_t.
Referenced by version().
size_t folly::IPAddressV6::hash | ( | ) | const |
Definition at line 314 of file IPAddressV6.cpp.
References addr_, folly::hash::SpookyHashV2::Hash128(), folly::hash::hash_combine(), isIPv4Mapped(), seed, and uint64_t.
Referenced by bitCount(), folly::hash_value(), std::hash< folly::IPAddressV6 >::operator()(), and toJson().
|
protected |
Helper that returns true if the address is in the binary subnet specified by addr.
Definition at line 530 of file IPAddressV6.cpp.
References mask().
Referenced by bytes(), isLinkLocal(), isPrivate(), and isRoutable().
bool folly::IPAddressV6::inSubnet | ( | StringPiece | cidrNetwork | ) | const |
Definition at line 329 of file IPAddressV6.cpp.
References addr, fetchMask(), inSubnetWithMask(), and folly::sformat().
Referenced by bitCount().
|
inline |
Definition at line 205 of file IPAddressV6.h.
References fetchMask(), inSubnetWithMask(), isLoopback(), and mask().
bool folly::IPAddressV6::inSubnetWithMask | ( | const IPAddressV6 & | subnet, |
const ByteArray16 & | mask | ||
) | const |
Definition at line 340 of file IPAddressV6.cpp.
References folly::detail::Bytes::mask(), mask(), and toByteArray().
Referenced by inSubnet().
|
inline |
Definition at line 170 of file IPAddressV6.h.
References type().
Referenced by getIPv4For6To4(), and folly::toAppend().
bool folly::IPAddressV6::isIPv4Mapped | ( | ) | const |
Definition at line 273 of file IPAddressV6.cpp.
Referenced by createIPv4(), hash(), isLoopback(), isPrivate(), and isTeredo().
bool folly::IPAddressV6::isLinkLocal | ( | ) | const |
Return true if this is a link-local IPv6 address.
Note that this only returns true for addresses in the fe80::/10 range. It returns false for the loopback address (::1), even though this address is also effectively has link-local scope. It also returns false for link-scope and interface-scope multicast addresses.
Definition at line 382 of file IPAddressV6.cpp.
References inBinarySubnet().
Referenced by getMacAddressFromLinkLocal(), and isNonroutable().
bool folly::IPAddressV6::isLinkLocalBroadcast | ( | ) | const |
bool folly::IPAddressV6::isLoopback | ( | ) | const |
Definition at line 349 of file IPAddressV6.cpp.
References createIPv4(), isIPv4Mapped(), and toSockAddr().
Referenced by inSubnet(), and isPrivate().
bool folly::IPAddressV6::isMulticast | ( | ) | const |
Return true if this is a multicast address.
Definition at line 386 of file IPAddressV6.cpp.
References addr_, and folly::IPAddressV6::AddressStorage::bytes_.
Referenced by folly::MacAddress::createMulticast(), getMulticastFlags(), getMulticastScope(), getSolicitedNodeAddress(), isNonroutable(), and isRoutable().
|
inline |
Definition at line 215 of file IPAddressV6.h.
References getMacAddressFromEUI64(), getMacAddressFromLinkLocal(), getMulticastFlags(), getMulticastScope(), isLinkLocal(), isMulticast(), isPrivate(), isRoutable(), and uint8_t.
bool folly::IPAddressV6::isPrivate | ( | ) | const |
Definition at line 373 of file IPAddressV6.cpp.
References createIPv4(), inBinarySubnet(), isIPv4Mapped(), and isLoopback().
Referenced by isNonroutable().
bool folly::IPAddressV6::isRoutable | ( | ) | const |
Return true if this address is routable.
Definition at line 358 of file IPAddressV6.cpp.
References getMulticastScope(), inBinarySubnet(), and isMulticast().
Referenced by isNonroutable().
|
inline |
|
inline |
Definition at line 275 of file IPAddressV6.h.
References bytes(), isLinkLocalBroadcast(), and mask().
|
static |
Definition at line 521 of file IPAddressV6.cpp.
References IPAddressV6(), folly::detail::Bytes::longestCommonPrefix(), and prefix().
Referenced by folly::operator<(), TEST(), and version().
IPAddressV6 folly::IPAddressV6::mask | ( | size_t | numBits | ) | const |
Definition at line 427 of file IPAddressV6.cpp.
References addr_, bitCount(), folly::IPAddressV6::AddressStorage::bytes_, fetchMask(), IPAddressV6(), folly::detail::Bytes::mask(), and folly::sformat().
Referenced by inBinarySubnet(), inSubnet(), inSubnetWithMask(), and isZero().
|
inline |
string folly::IPAddressV6::str | ( | ) | const |
Definition at line 438 of file IPAddressV6.cpp.
References buffer(), bytes(), folly::errnoStr(), getScopeId(), folly::sformat(), string, toAddr(), and folly::detail::Bytes::toHex().
Referenced by getIPv4For6To4(), folly::operator<<(), TEST(), folly::toAppend(), toByteArray(), toJson(), and tryFromString().
|
inlineprivate |
Definition at line 379 of file IPAddressV6.h.
References addr_, folly::IPAddressV6::AddressStorage::bytes_, and scope_.
|
inline |
Definition at line 286 of file IPAddressV6.h.
References addr_, and folly::IPAddressV6::AddressStorage::in6Addr_.
Referenced by BENCHMARK(), and str().
|
inline |
Returns the address as a Range.
Definition at line 129 of file IPAddressV6.h.
References addr_, createIPv4(), getIPv4For6To4(), folly::IPAddressV6::AddressStorage::in6Addr_, IPAddressV6(), and folly::pushmi::__adl::noexcept().
|
inline |
Definition at line 306 of file IPAddressV6.h.
References bytes(), str(), string, toFullyQualified(), toFullyQualifiedAppend(), and toInverseArpaName().
Referenced by inSubnetWithMask().
string folly::IPAddressV6::toFullyQualified | ( | ) | const |
Definition at line 466 of file IPAddressV6.cpp.
References addr_, folly::detail::fastIpv6ToString(), and folly::IPAddressV6::AddressStorage::in6Addr_.
Referenced by BENCHMARK(), BENCHMARK_RELATIVE(), and toByteArray().
void folly::IPAddressV6::toFullyQualifiedAppend | ( | std::string & | out | ) | const |
Definition at line 471 of file IPAddressV6.cpp.
References addr_, folly::detail::fastIpv6AppendToString(), and folly::IPAddressV6::AddressStorage::in6Addr_.
Referenced by BENCHMARK_RELATIVE(), and toByteArray().
string folly::IPAddressV6::toInverseArpaName | ( | ) | const |
Definition at line 476 of file IPAddressV6.cpp.
References a, bytes(), i, folly::join(), and folly::sformat().
Referenced by toByteArray().
string folly::IPAddressV6::toJson | ( | ) | const |
Definition at line 309 of file IPAddressV6.cpp.
References hash(), folly::sformat(), and str().
Referenced by bitCount().
|
inline |
Definition at line 297 of file IPAddressV6.h.
References addr, addr_, folly::IPAddressV6::AddressStorage::in6Addr_, and scope_.
Referenced by isLoopback(), and TEST().
|
staticnoexcept |
Non-throwing version of fromBinary(). On failure returns IPAddressFormatError.
Definition at line 178 of file IPAddressV6.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 IPAddressV6 instance from provided string and returns it on success. Returns IPAddressFormatError on failure.
Definition at line 82 of file IPAddressV6.cpp.
References folly::INVALID_IP, IPAddressV6(), folly::makeUnexpected(), SCOPE_EXIT, and str().
Referenced by BENCHMARK(), BENCHMARK_RELATIVE(), IPAddressV6(), TEST_P(), and folly::toAppend().
|
privatenoexcept |
Set the current IPAddressV6 object to have the address specified by bytes. Returns IPAddressFormatError if bytes.size() is not 16.
Definition at line 188 of file IPAddressV6.cpp.
References addr_, bytes(), folly::IPAddressV6::AddressStorage::in6Addr_, folly::INVALID_IP, folly::makeUnexpected(), scope_, and folly::unit.
Referenced by tryFromBinary().
IPAddressV6::Type folly::IPAddressV6::type | ( | ) | const |
Definition at line 292 of file IPAddressV6.cpp.
References bytes(), folly::NORMAL, uint16_t, uint32_t, and folly::unpackInto().
Referenced by is6To4(), and isTeredo().
|
staticnoexcept |
Definition at line 65 of file IPAddressV6.cpp.
Referenced by TEST(), and folly::toAppend().
|
inline |
Definition at line 324 of file IPAddressV6.h.
References fetchMask(), getSolicitedNodeAddress(), and longestCommonPrefix().
|
friend |
Definition at line 387 of file IPAddressV6.h.
|
friend |
Definition at line 390 of file IPAddressV6.h.
|
friend |
Definition at line 396 of file IPAddressV6.h.
|
friend |
Definition at line 384 of file IPAddressV6.h.
|
friend |
Definition at line 393 of file IPAddressV6.h.
|
friend |
Definition at line 399 of file IPAddressV6.h.
|
private |
Referenced by folly::IPAddressV6::AddressStorage::AddressStorage(), bytes(), getMacAddressFromEUI64(), getMulticastFlags(), getMulticastScope(), getSolicitedNodeAddress(), hash(), isMulticast(), mask(), tie(), toAddr(), toBinary(), toFullyQualified(), toFullyQualifiedAppend(), toSockAddr(), and trySetFromBinary().
|
static |
Definition at line 93 of file IPAddressV6.h.
Referenced by BENCHMARK_RELATIVE(), and TEST().
|
static |
Definition at line 90 of file IPAddressV6.h.
Referenced by folly::IPAddressV4::getIPv6For6To4().
|
static |
Definition at line 88 of file IPAddressV6.h.
|
private |
Definition at line 417 of file IPAddressV6.h.
Referenced by getScopeId(), setScopeId(), tie(), toSockAddr(), and trySetFromBinary().