MCPcopy Create free account
hub / github.com/Icinga/icinga2 / GetPeerAddressDetails

Method GetPeerAddressDetails

lib/base/socket.cpp:197–230  ·  view source on GitHub ↗

* Returns a pair describing the peer host and service of the socket. * * @returns A pair describing the peer host and service. */

Source from the content-addressed store, hash-verified

195 * @returns A pair describing the peer host and service.
196 */
197std::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.

Callers

nothing calls this directly

Calls 2

LogClass · 0.85
socket_errorClass · 0.85

Tested by

no test coverage detected