| 841 | } |
| 842 | |
| 843 | std::string CNetAddr::ToStringIP() const |
| 844 | { |
| 845 | if (IsTor()) |
| 846 | return EncodeBase32(&ip[6], 10) + ".onion"; |
| 847 | CService serv(*this, 0); |
| 848 | struct sockaddr_storage sockaddr; |
| 849 | socklen_t socklen = sizeof(sockaddr); |
| 850 | if (serv.GetSockAddr((struct sockaddr*)&sockaddr, &socklen)) { |
| 851 | char name[1025] = ""; |
| 852 | if (!getnameinfo((const struct sockaddr*)&sockaddr, socklen, name, sizeof(name), NULL, 0, NI_NUMERICHOST)) |
| 853 | return std::string(name); |
| 854 | } |
| 855 | if (IsIPv4()) |
| 856 | return strprintf("%u.%u.%u.%u", GetByte(3), GetByte(2), GetByte(1), GetByte(0)); |
| 857 | else |
| 858 | return strprintf("%x:%x:%x:%x:%x:%x:%x:%x", |
| 859 | GetByte(15) << 8 | GetByte(14), GetByte(13) << 8 | GetByte(12), |
| 860 | GetByte(11) << 8 | GetByte(10), GetByte(9) << 8 | GetByte(8), |
| 861 | GetByte(7) << 8 | GetByte(6), GetByte(5) << 8 | GetByte(4), |
| 862 | GetByte(3) << 8 | GetByte(2), GetByte(1) << 8 | GetByte(0)); |
| 863 | } |
| 864 | |
| 865 | std::string CNetAddr::ToString() const |
| 866 | { |