| 239 | } |
| 240 | |
| 241 | TString GetAddressAsString(const TUdpAddress& addr) { |
| 242 | char buf[1000]; |
| 243 | if (addr.IsIPv4()) { |
| 244 | int ip = addr.GetIPv4(); |
| 245 | snprintf(buf, sizeof(buf), "%d.%d.%d.%d:%d", |
| 246 | (ip >> 0) & 0xff, (ip >> 8) & 0xff, |
| 247 | (ip >> 16) & 0xff, (ip >> 24) & 0xff, |
| 248 | addr.Port); |
| 249 | } else { |
| 250 | ui16 ipv6[8]; |
| 251 | *BreakAliasing<ui64>(ipv6) = addr.Network; |
| 252 | *BreakAliasing<ui64>(ipv6 + 4) = addr.Interface; |
| 253 | char suffix[100] = ""; |
| 254 | if (addr.Scope != 0) { |
| 255 | snprintf(suffix, sizeof(suffix), "%%%d", addr.Scope); |
| 256 | } |
| 257 | snprintf(buf, sizeof(buf), "[%x:%x:%x:%x:%x:%x:%x:%x%s]:%d", |
| 258 | ntohs(ipv6[0]), ntohs(ipv6[1]), ntohs(ipv6[2]), ntohs(ipv6[3]), |
| 259 | ntohs(ipv6[4]), ntohs(ipv6[5]), ntohs(ipv6[6]), ntohs(ipv6[7]), |
| 260 | suffix, addr.Port); |
| 261 | } |
| 262 | return buf; |
| 263 | } |
| 264 | } |