From 4ac665a688925f19e1ccebd01672cf7cb30034d1 Mon Sep 17 00:00:00 2001 From: Eli Lindsey Date: Wed, 12 Jul 2017 17:47:29 -0700 Subject: [PATCH] Revert D5408572: replace getnameinfo with inet_ntop in v6 string formatting Summary: This reverts commit 69b0171a9a54738045f9041381aea5512b17eb13 Differential Revision: D5408572 fbshipit-source-id: 3ec8ce96575b632fb134be99cc0d2538a01a7d85 --- folly/IPAddressV6.cpp | 25 +++++++++++++++---------- 1 file changed, 15 insertions(+), 10 deletions(-) diff --git a/folly/IPAddressV6.cpp b/folly/IPAddressV6.cpp index 71765e76..29450f4b 100644 --- a/folly/IPAddressV6.cpp +++ b/folly/IPAddressV6.cpp @@ -19,8 +19,6 @@ #include #include -#include - #include #include #include @@ -406,21 +404,28 @@ IPAddressV6 IPAddressV6::mask(size_t numBits) const { // public string IPAddressV6::str() const { char buffer[INET6_ADDRSTRLEN] = {0}; - - if (inet_ntop(AF_INET6, toAddr().s6_addr, buffer, INET6_ADDRSTRLEN)) { + sockaddr_in6 sock = toSockAddr(); + int error = getnameinfo( + (sockaddr*)&sock, + sizeof(sock), + buffer, + INET6_ADDRSTRLEN, + nullptr, + 0, + NI_NUMERICHOST); + if (!error) { string ip(buffer); - char ifname[IFNAMSIZ] = {0}; - if (if_indextoname(getScopeId(), ifname)) { - ip += "%"; - ip += ifname; - } return ip; } else { throw IPAddressFormatException(to( "Invalid address with hex ", "'", detail::Bytes::toHex(bytes(), 16), - "'")); + "%", + sock.sin6_scope_id, + "'", + " , with error ", + gai_strerror(error))); } } -- 2.34.1