mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-11-12 15:09:59 +01:00
Use getnameinfo() to get canonical IPv6 addresses
This commit is contained in:
@@ -711,6 +711,18 @@ enum Network CNetAddr::GetNetwork() const
|
|||||||
|
|
||||||
std::string CNetAddr::ToStringIP() const
|
std::string CNetAddr::ToStringIP() const
|
||||||
{
|
{
|
||||||
|
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())
|
if (IsIPv4())
|
||||||
return strprintf("%u.%u.%u.%u", GetByte(3), GetByte(2), GetByte(1), GetByte(0));
|
return strprintf("%u.%u.%u.%u", GetByte(3), GetByte(2), GetByte(1), GetByte(0));
|
||||||
else
|
else
|
||||||
|
|||||||
Reference in New Issue
Block a user