| 251 | } |
| 252 | |
| 253 | std::string CNetAddr::ToStringIP() const |
| 254 | { |
| 255 | if (IsTor()) |
| 256 | return EncodeBase32(&ip[6], 10) + ".onion"; |
| 257 | if (IsInternal()) |
| 258 | return EncodeBase32(ip + sizeof(g_internal_prefix), sizeof(ip) - sizeof(g_internal_prefix)) + ".internal"; |
| 259 | CService serv(*this, 0); |
| 260 | struct sockaddr_storage sockaddr; |
| 261 | socklen_t socklen = sizeof(sockaddr); |
| 262 | if (serv.GetSockAddr((struct sockaddr*)&sockaddr, &socklen)) { |
| 263 | char name[1025] = ""; |
| 264 | if (!getnameinfo((const struct sockaddr*)&sockaddr, socklen, name, sizeof(name), nullptr, 0, NI_NUMERICHOST)) |
| 265 | return std::string(name); |
| 266 | } |
| 267 | if (IsIPv4()) |
| 268 | return strprintf("%u.%u.%u.%u", GetByte(3), GetByte(2), GetByte(1), GetByte(0)); |
| 269 | else |
| 270 | return strprintf("%x:%x:%x:%x:%x:%x:%x:%x", |
| 271 | GetByte(15) << 8 | GetByte(14), GetByte(13) << 8 | GetByte(12), |
| 272 | GetByte(11) << 8 | GetByte(10), GetByte(9) << 8 | GetByte(8), |
| 273 | GetByte(7) << 8 | GetByte(6), GetByte(5) << 8 | GetByte(4), |
| 274 | GetByte(3) << 8 | GetByte(2), GetByte(1) << 8 | GetByte(0)); |
| 275 | } |
| 276 | |
| 277 | std::string CNetAddr::ToString() const |
| 278 | { |