* Returns host and service as pair. * * @returns A pair with host and service. */
| 113 | * @returns A pair with host and service. |
| 114 | */ |
| 115 | std::pair<String, String> Socket::GetDetailsFromSockaddr(sockaddr *address, socklen_t len) |
| 116 | { |
| 117 | char host[NI_MAXHOST]; |
| 118 | char service[NI_MAXSERV]; |
| 119 | |
| 120 | if (getnameinfo(address, len, host, sizeof(host), service, |
| 121 | sizeof(service), NI_NUMERICHOST | NI_NUMERICSERV) < 0) { |
| 122 | #ifndef _WIN32 |
| 123 | Log(LogCritical, "Socket") |
| 124 | << "getnameinfo() failed with error code " << errno << ", \"" << Utility::FormatErrorNumber(errno) << "\""; |
| 125 | |
| 126 | BOOST_THROW_EXCEPTION(socket_error() |
| 127 | << boost::errinfo_api_function("getnameinfo") |
| 128 | << boost::errinfo_errno(errno)); |
| 129 | #else /* _WIN32 */ |
| 130 | Log(LogCritical, "Socket") |
| 131 | << "getnameinfo() failed with error code " << WSAGetLastError() << ", \"" << Utility::FormatErrorNumber(WSAGetLastError()) << "\""; |
| 132 | |
| 133 | BOOST_THROW_EXCEPTION(socket_error() |
| 134 | << boost::errinfo_api_function("getnameinfo") |
| 135 | << errinfo_win32_error(WSAGetLastError())); |
| 136 | #endif /* _WIN32 */ |
| 137 | } |
| 138 | |
| 139 | return std::make_pair(host, service); |
| 140 | } |
| 141 | |
| 142 | /** |
| 143 | * Returns a pair describing the local host and service of the socket. |
nothing calls this directly
no test coverage detected