* Returns a pair describing the peer host and service of the socket. * * @returns A pair describing the peer host and service. */
| 195 | * @returns A pair describing the peer host and service. |
| 196 | */ |
| 197 | std::pair<String, String> Socket::GetPeerAddressDetails() |
| 198 | { |
| 199 | std::unique_lock<std::mutex> lock(m_SocketMutex); |
| 200 | |
| 201 | sockaddr_storage sin; |
| 202 | socklen_t len = sizeof(sin); |
| 203 | |
| 204 | if (getpeername(GetFD(), (sockaddr *)&sin, &len) < 0) { |
| 205 | #ifndef _WIN32 |
| 206 | Log(LogCritical, "Socket") |
| 207 | << "getpeername() failed with error code " << errno << ", \"" << Utility::FormatErrorNumber(errno) << "\""; |
| 208 | |
| 209 | BOOST_THROW_EXCEPTION(socket_error() |
| 210 | << boost::errinfo_api_function("getpeername") |
| 211 | << boost::errinfo_errno(errno)); |
| 212 | #else /* _WIN32 */ |
| 213 | Log(LogCritical, "Socket") |
| 214 | << "getpeername() failed with error code " << WSAGetLastError() << ", \"" << Utility::FormatErrorNumber(WSAGetLastError()) << "\""; |
| 215 | |
| 216 | BOOST_THROW_EXCEPTION(socket_error() |
| 217 | << boost::errinfo_api_function("getpeername") |
| 218 | << errinfo_win32_error(WSAGetLastError())); |
| 219 | #endif /* _WIN32 */ |
| 220 | } |
| 221 | |
| 222 | std::pair<String, String> details; |
| 223 | try { |
| 224 | details = GetDetailsFromSockaddr((sockaddr *)&sin, len); |
| 225 | } catch (const std::exception&) { |
| 226 | /* already logged */ |
| 227 | } |
| 228 | |
| 229 | return details; |
| 230 | } |
| 231 | |
| 232 | /** |
| 233 | * Returns a String describing the peer address of the socket. |
nothing calls this directly
no test coverage detected