Commit 4ac665a6 authored by Eli Lindsey's avatar Eli Lindsey Committed by Facebook Github Bot

Revert D5408572: replace getnameinfo with inet_ntop in v6 string formatting

Summary: This reverts commit 69b0171a9a54738045f9041381aea5512b17eb13

Differential Revision: D5408572

fbshipit-source-id: 3ec8ce96575b632fb134be99cc0d2538a01a7d85
parent 0d38f577
...@@ -19,8 +19,6 @@ ...@@ -19,8 +19,6 @@
#include <ostream> #include <ostream>
#include <string> #include <string>
#include <net/if.h>
#include <folly/Format.h> #include <folly/Format.h>
#include <folly/IPAddress.h> #include <folly/IPAddress.h>
#include <folly/IPAddressV4.h> #include <folly/IPAddressV4.h>
...@@ -406,21 +404,28 @@ IPAddressV6 IPAddressV6::mask(size_t numBits) const { ...@@ -406,21 +404,28 @@ IPAddressV6 IPAddressV6::mask(size_t numBits) const {
// public // public
string IPAddressV6::str() const { string IPAddressV6::str() const {
char buffer[INET6_ADDRSTRLEN] = {0}; char buffer[INET6_ADDRSTRLEN] = {0};
sockaddr_in6 sock = toSockAddr();
if (inet_ntop(AF_INET6, toAddr().s6_addr, buffer, INET6_ADDRSTRLEN)) { int error = getnameinfo(
(sockaddr*)&sock,
sizeof(sock),
buffer,
INET6_ADDRSTRLEN,
nullptr,
0,
NI_NUMERICHOST);
if (!error) {
string ip(buffer); string ip(buffer);
char ifname[IFNAMSIZ] = {0};
if (if_indextoname(getScopeId(), ifname)) {
ip += "%";
ip += ifname;
}
return ip; return ip;
} else { } else {
throw IPAddressFormatException(to<std::string>( throw IPAddressFormatException(to<std::string>(
"Invalid address with hex ", "Invalid address with hex ",
"'", "'",
detail::Bytes::toHex(bytes(), 16), detail::Bytes::toHex(bytes(), 16),
"'")); "%",
sock.sin6_scope_id,
"'",
" , with error ",
gai_strerror(error)));
} }
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment