aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorPieter Wuille <pieter.wuille@gmail.com>2012-05-14 00:43:21 +0200
committerPieter Wuille <pieter.wuille@gmail.com>2012-05-14 01:41:15 +0200
commitca81464697ca49452ab3e399c70d450f8d3b4028 (patch)
treee3b6f8dd8ca9573336c28be75ad368f287bd12a8 /src
parent09b4e26a446c302f0cce176bf572da956bb2515e (diff)
Use getnameinfo() to get canonical IPv6 addresses
Diffstat (limited to 'src')
-rw-r--r--src/netbase.cpp14
1 files changed, 13 insertions, 1 deletions
diff --git a/src/netbase.cpp b/src/netbase.cpp
index 2131bdf75b..3fe42a7a74 100644
--- a/src/netbase.cpp
+++ b/src/netbase.cpp
@@ -711,7 +711,19 @@ enum Network CNetAddr::GetNetwork() const
std::string CNetAddr::ToStringIP() const
{
- if (IsIPv4())
+ CService serv(*this, 0);
+#ifdef USE_IPV6
+ struct sockaddr_storage sockaddr;
+#else
+ struct sockaddr sockaddr;
+#endif
+ socklen_t socklen = sizeof(sockaddr);
+ if (serv.GetSockAddr((struct sockaddr*)&sockaddr, &socklen)) {
+ char name[1025] = "";
+ if (!getnameinfo((const struct sockaddr*)&sockaddr, socklen, name, sizeof(name), NULL, 0, NI_NUMERICHOST))
+ return std::string(name);
+ }
+ if (IsIPv4())
return strprintf("%u.%u.%u.%u", GetByte(3), GetByte(2), GetByte(1), GetByte(0));
else
return strprintf("%x:%x:%x:%x:%x:%x:%x:%x",