| 275 | } |
| 276 | |
| 277 | TString GetAddressAsString(const TUdpAddress& addr) { |
| 278 | char buf[1000]; |
| 279 | if (addr.IsIPv4()) { |
| 280 | int ip = addr.GetIPv4(); |
| 281 | snprintf(buf, sizeof(buf), "%d.%d.%d.%d:%d", |
| 282 | (ip >> 0) & 0xff, (ip >> 8) & 0xff, |
| 283 | (ip >> 16) & 0xff, (ip >> 24) & 0xff, |
| 284 | addr.Port); |
| 285 | } else { |
| 286 | ui16 ipv6[8]; |
| 287 | *BreakAliasing<ui64>(ipv6) = addr.Network; |
| 288 | *BreakAliasing<ui64>(ipv6 + 4) = addr.Interface; |
| 289 | char suffix[100] = ""; |
| 290 | if (addr.Scope != 0) { |
| 291 | snprintf(suffix, sizeof(suffix), "%%%d", addr.Scope); |
| 292 | } |
| 293 | snprintf(buf, sizeof(buf), "[%x:%x:%x:%x:%x:%x:%x:%x%s]:%d", |
| 294 | ntohs(ipv6[0]), ntohs(ipv6[1]), ntohs(ipv6[2]), ntohs(ipv6[3]), |
| 295 | ntohs(ipv6[4]), ntohs(ipv6[5]), ntohs(ipv6[6]), ntohs(ipv6[7]), |
| 296 | suffix, addr.Port); |
| 297 | } |
| 298 | return buf; |
| 299 | } |
| 300 | } |