| 16 | |
| 17 | template <bool printPort> |
| 18 | static inline void PrintAddr(IOutputStream& out, const IRemoteAddr& addr) { |
| 19 | const sockaddr* a = addr.Addr(); |
| 20 | char buf[INET6_ADDRSTRLEN + 10]; |
| 21 | |
| 22 | switch (a->sa_family) { |
| 23 | case AF_INET: { |
| 24 | const TIpAddress sa(*(const sockaddr_in*)a); |
| 25 | |
| 26 | out << IpToString(sa.Host(), buf, sizeof(buf)); |
| 27 | |
| 28 | if (printPort) { |
| 29 | out << ":" << sa.Port(); |
| 30 | } |
| 31 | |
| 32 | break; |
| 33 | } |
| 34 | |
| 35 | case AF_INET6: { |
| 36 | const sockaddr_in6* sa = (const sockaddr_in6*)a; |
| 37 | |
| 38 | if (!inet_ntop(AF_INET6, (void*)&sa->sin6_addr.s6_addr, buf, sizeof(buf))) { |
| 39 | ythrow TSystemError() << "inet_ntop() failed"; |
| 40 | } |
| 41 | |
| 42 | if (printPort) { |
| 43 | out << "[" << buf << "]" |
| 44 | << ":" << InetToHost(sa->sin6_port); |
| 45 | } else { |
| 46 | out << buf; |
| 47 | } |
| 48 | |
| 49 | break; |
| 50 | } |
| 51 | |
| 52 | #if defined(AF_UNIX) |
| 53 | case AF_UNIX: { |
| 54 | const sockaddr_un* sa = (const sockaddr_un*)a; |
| 55 | |
| 56 | out << TStringBuf(sa->sun_path); |
| 57 | |
| 58 | break; |
| 59 | } |
| 60 | #endif |
| 61 | |
| 62 | default: { |
| 63 | size_t len = addr.Len(); |
| 64 | |
| 65 | const char* b = (const char*)a; |
| 66 | const char* e = b + len; |
| 67 | |
| 68 | bool allZeros = true; |
| 69 | for (size_t i = 0; i < len; ++i) { |
| 70 | if (b[i] != 0) { |
| 71 | allZeros = false; |
| 72 | break; |
| 73 | } |
| 74 | } |
| 75 |
nothing calls this directly
no test coverage detected