| 864 | } |
| 865 | |
| 866 | std::string CNetAddr::ToStringIP() const |
| 867 | { |
| 868 | if (IsTor()) |
| 869 | return EncodeBase32(&ip[6], 10) + ".onion"; |
| 870 | CService serv(*this, 0); |
| 871 | struct sockaddr_storage sockaddr; |
| 872 | socklen_t socklen = sizeof(sockaddr); |
| 873 | if (serv.GetSockAddr((struct sockaddr*)&sockaddr, &socklen)) { |
| 874 | char name[1025] = ""; |
| 875 | if (!getnameinfo((const struct sockaddr*)&sockaddr, socklen, name, sizeof(name), NULL, 0, NI_NUMERICHOST)) |
| 876 | return std::string(name); |
| 877 | } |
| 878 | if (IsIPv4()) |
| 879 | return strprintf("%u.%u.%u.%u", GetByte(3), GetByte(2), GetByte(1), GetByte(0)); |
| 880 | else |
| 881 | return strprintf("%x:%x:%x:%x:%x:%x:%x:%x", |
| 882 | GetByte(15) << 8 | GetByte(14), GetByte(13) << 8 | GetByte(12), |
| 883 | GetByte(11) << 8 | GetByte(10), GetByte(9) << 8 | GetByte(8), |
| 884 | GetByte(7) << 8 | GetByte(6), GetByte(5) << 8 | GetByte(4), |
| 885 | GetByte(3) << 8 | GetByte(2), GetByte(1) << 8 | GetByte(0)); |
| 886 | } |
| 887 | |
| 888 | std::string CNetAddr::ToString() const |
| 889 | { |