| 714 | } |
| 715 | |
| 716 | string CNetAddr::ToStringIP() const { |
| 717 | if (IsTor()) |
| 718 | return EncodeBase32(&ip[6], 10) + ".onion"; |
| 719 | CService serv(*this, 0); |
| 720 | struct sockaddr_storage sockaddr; |
| 721 | socklen_t socklen = sizeof(sockaddr); |
| 722 | if (serv.GetSockAddr((struct sockaddr*)&sockaddr, &socklen)) { |
| 723 | char name[1025] = ""; |
| 724 | if (!getnameinfo((const struct sockaddr*)&sockaddr, socklen, name, sizeof(name), nullptr, 0, NI_NUMERICHOST)) |
| 725 | return string(name); |
| 726 | } |
| 727 | if (IsIPv4()) |
| 728 | return strprintf("%u.%u.%u.%u", GetByte(3), GetByte(2), GetByte(1), GetByte(0)); |
| 729 | else |
| 730 | return strprintf("%x:%x:%x:%x:%x:%x:%x:%x", GetByte(15) << 8 | GetByte(14), GetByte(13) << 8 | GetByte(12), |
| 731 | GetByte(11) << 8 | GetByte(10), GetByte(9) << 8 | GetByte(8), GetByte(7) << 8 | GetByte(6), |
| 732 | GetByte(5) << 8 | GetByte(4), GetByte(3) << 8 | GetByte(2), GetByte(1) << 8 | GetByte(0)); |
| 733 | } |
| 734 | |
| 735 | string CNetAddr::ToString() const { return ToStringIP(); } |
| 736 | |