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

Method GetClientAddressDetails

lib/base/socket.cpp:147–180  ·  view source on GitHub ↗

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

Source from the content-addressed store, hash-verified

145 * @returns A pair describing the local host and service.
146 */
147std::pair<String, String> Socket::GetClientAddressDetails()
148{
149 std::unique_lock<std::mutex> lock(m_SocketMutex);
150
151 sockaddr_storage sin;
152 socklen_t len = sizeof(sin);
153
154 if (getsockname(GetFD(), (sockaddr *)&sin, &len) < 0) {
155#ifndef _WIN32
156 Log(LogCritical, "Socket")
157 << "getsockname() failed with error code " << errno << ", \"" << Utility::FormatErrorNumber(errno) << "\"";
158
159 BOOST_THROW_EXCEPTION(socket_error()
160 << boost::errinfo_api_function("getsockname")
161 << boost::errinfo_errno(errno));
162#else /* _WIN32 */
163 Log(LogCritical, "Socket")
164 << "getsockname() failed with error code " << WSAGetLastError() << ", \"" << Utility::FormatErrorNumber(WSAGetLastError()) << "\"";
165
166 BOOST_THROW_EXCEPTION(socket_error()
167 << boost::errinfo_api_function("getsockname")
168 << errinfo_win32_error(WSAGetLastError()));
169#endif /* _WIN32 */
170 }
171
172 std::pair<String, String> details;
173 try {
174 details = GetDetailsFromSockaddr((sockaddr *)&sin, len);
175 } catch (const std::exception&) {
176 /* already logged */
177 }
178
179 return details;
180}
181
182/**
183 * Returns a String describing the local address of the socket.

Callers

nothing calls this directly

Calls 2

LogClass · 0.85
socket_errorClass · 0.85

Tested by

no test coverage detected