From: Eli Lindsey Date: Thu, 13 Jul 2017 00:47:29 +0000 (-0700) Subject: Revert D5408572: replace getnameinfo with inet_ntop in v6 string formatting X-Git-Tag: v2017.07.17.00~16 X-Git-Url: http://demsky.eecs.uci.edu/git/?a=commitdiff_plain;h=4ac665a688925f19e1ccebd01672cf7cb30034d1;p=folly.git Revert D5408572: replace getnameinfo with inet_ntop in v6 string formatting Summary: This reverts commit 69b0171a9a54738045f9041381aea5512b17eb13 Differential Revision: D5408572 fbshipit-source-id: 3ec8ce96575b632fb134be99cc0d2538a01a7d85 --- 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))); } }