scope_ = 0;
}
+// static
+IPAddressV6 IPAddressV6::fromInverseArpaName(const std::string& arpaname) {
+ auto piece = StringPiece(arpaname);
+ if (!piece.removeSuffix(".ip6.arpa")) {
+ throw IPAddressFormatException(sformat(
+ "Invalid input. Should end with 'ip6.arpa'. Got '{}'", arpaname));
+ }
+ std::vector<StringPiece> pieces;
+ split(".", piece, pieces);
+ if (pieces.size() != 32) {
+ throw IPAddressFormatException(sformat("Invalid input. Got '{}'", piece));
+ }
+ std::array<char, IPAddressV6::kToFullyQualifiedSize> ip;
+ size_t pos = 0;
+ int count = 0;
+ for (size_t i = 1; i <= pieces.size(); i++) {
+ ip[pos] = pieces[pieces.size() - i][0];
+ pos++;
+ count++;
+ // add ':' every 4 chars
+ if (count == 4 && pos < ip.size()) {
+ ip[pos++] = ':';
+ count = 0;
+ }
+ }
+ return IPAddressV6(folly::range(ip));
+}
+
// public
IPAddressV4 IPAddressV6::createIPv4() const {
if (!isIPv4Mapped()) {
return detail::fastIpv6ToString(addr_.in6Addr_);
}
+// public
+void IPAddressV6::toFullyQualifiedAppend(std::string& out) const {
+ detail::fastIpv6AppendToString(addr_.in6Addr_, out);
+}
+
+// public
+string IPAddressV6::toInverseArpaName() const {
+ constexpr folly::StringPiece lut = "0123456789abcdef";
+ std::array<char, 32> a;
+ int j = 0;
+ for (int i = 15; i >= 0; i--) {
+ a[j] = (lut[bytes()[i] & 0xf]);
+ a[j + 1] = (lut[bytes()[i] >> 4]);
+ j += 2;
+ }
+ return sformat("{}.ip6.arpa", join(".", a));
+}
+
// public
uint8_t IPAddressV6::getNthMSByte(size_t byteIndex) const {
const auto highestIndex = byteCount() - 1;