add the getnameinfo error code and v6 scope id to exception text
authorEli Lindsey <elindsey@fb.com>
Mon, 10 Jul 2017 15:54:21 +0000 (08:54 -0700)
committerFacebook Github Bot <facebook-github-bot@users.noreply.github.com>
Mon, 10 Jul 2017 16:05:46 +0000 (09:05 -0700)
Summary: Making the exception text more useful by adding getnameinfo's error code and the v6 scope id

Reviewed By: yangchi

Differential Revision: D5389137

fbshipit-source-id: e6b9b4edd7dd1859e0ed4d784b2f89a60a701955

folly/IPAddressV6.cpp

index 038a68f9b88661767487f25651395930cab53234..1cb2ce6e5e6f9c008904436e48d6d9adab16cbf4 100644 (file)
@@ -405,10 +405,15 @@ IPAddressV6 IPAddressV6::mask(size_t numBits) const {
 string IPAddressV6::str() const {
   char buffer[INET6_ADDRSTRLEN] = {0};
   sockaddr_in6 sock = toSockAddr();
-  if (!getnameinfo(
-        (sockaddr*)&sock, sizeof(sock),
-        buffer, INET6_ADDRSTRLEN,
-        nullptr, 0, NI_NUMERICHOST)) {
+  int error = getnameinfo(
+      (sockaddr*)&sock,
+      sizeof(sock),
+      buffer,
+      INET6_ADDRSTRLEN,
+      nullptr,
+      0,
+      NI_NUMERICHOST);
+  if (!error) {
     string ip(buffer);
     return ip;
   } else {
@@ -416,7 +421,11 @@ string IPAddressV6::str() const {
         "Invalid address with hex ",
         "'",
         detail::Bytes::toHex(bytes(), 16),
-        "'"));
+        "%",
+        sock.sin6_scope_id,
+        "'",
+        " , with error ",
+        gai_strerror(error)));
   }
 }