29 std::string_view a_service,
32 : m_node(a_node), m_service(a_service) {
33 TRACE2(
this,
" Construct CAddrinfo() with extra service")
38 m_hints.ai_flags = a_flags;
39 m_hints.ai_socktype = a_socktype;
90 TRACE2(
this,
" Executing CAddrinfo::get_first()")
93 std::string node, service;
95 if (m_service.empty())
99 }
catch (
const std::range_error& ex) {
101 UPnPsdk_LOGWHAT
"MSG1128: catched next line ...\n" + ex.what();
108 ::addrinfo* new_res{
nullptr};
109 const int ret = umock::netdb_h.getaddrinfo(
110 (node.empty() ?
nullptr : node.c_str()),
111 (service.empty() ? nullptr : service.c_str()), &m_hints, &new_res);
114 TRACE2(
this,
" syscall ::getaddrinfo(" + node +
", " + service +
115 ") with new_res = " +
116 std::format(
"{:#x}",
reinterpret_cast<uintptr_t
>(new_res)))
120 char addrStr[INET6_ADDRSTRLEN]{};
121 char servStr[NI_MAXSERV]{};
123 ::getnameinfo(new_res->ai_addr,
124 static_cast<socklen_t
>(new_res->ai_addrlen), addrStr,
125 sizeof(addrStr), servStr,
sizeof(servStr),
126 NI_NUMERICHOST | NI_NUMERICSERV);
128 UPnPsdk_LOGINFO(
"MSG1111")
"syscall ::getaddrinfo("
129 << (node.empty() ?
"nullptr, " :
"\"" + node +
"\", ")
130 << (service.empty() ?
"nullptr, " :
"\"" + service +
"\", ")
131 << &m_hints <<
", " << &new_res
132 <<
") node=\"" << m_node <<
"\", "
133 << (m_hints.ai_flags & AI_NUMERICHOST ?
"AI_NUMERICHOST, " :
"")
134 << (m_hints.ai_flags & AI_NUMERICSERV ?
"AI_NUMERICSERV, " :
"")
135 << (m_hints.ai_flags & AI_PASSIVE ?
"AI_PASSIVE, " :
"")
136 << (m_hints.ai_family == AF_INET6 ?
"AF_INET6" :
137 (m_hints.ai_family == AF_INET ?
"AF_INET" :
138 (m_hints.ai_family == AF_UNSPEC ?
"AF_UNSPEC" :
139 "m_hints.ai_family=" + std::to_string(m_hints.ai_family))))
141 << (m_hints.ai_socktype == SOCK_STREAM ?
"SOCK_STREAM" :
142 (m_hints.ai_socktype == SOCK_DGRAM ?
"SOCK_DGRAM" :
143 (m_hints.ai_socktype == SOCK_RAW ?
"SOCK_RAW" :
144 "socktype=" + std::to_string(m_hints.ai_socktype))))
146 ?
". Get EAI_ERROR(" + std::to_string(ret) +
")"
147 :
". Get first \"" + std::string(addrStr) +
"\" port "
148 + std::string(servStr)
149 + (new_res->ai_next ==
nullptr ?
", no more entries." :
", more entries..."))
161 m_error_msg = UPnPsdk_LOGWHAT +
"MSG1112: errid(" +
162 std::to_string(ret) +
")=\"" + ::gai_strerror(ret) +
"\", " +
163 ((m_hints.ai_family == AF_UNSPEC) ?
"IPv?_" :
164 ((m_hints.ai_family == AF_INET6) ?
"IPv6_" :
"IPv4_")) +
165 ((m_hints.ai_flags & AI_NUMERICHOST) ?
"numeric_host=\"" :
"alphanum_name=\"") +
166 m_node +
"\", service=\"" +
168 ((m_hints.ai_flags & AI_PASSIVE) ?
", passive_listen" :
"") +
169 ((m_hints.ai_flags & AI_NUMERICHOST) ?
"" :
", (maybe DNS query temporary failed?)") +
170 ", ai_socktype=" + std::to_string(m_hints.ai_socktype);
171 UPnPsdk_LOGERR(
"?????") << m_error_msg <<
'\n';
177 for (::addrinfo* res{new_res}; res !=
nullptr; res = res->ai_next) {
180 res->ai_protocol = m_hints.ai_protocol;
184 res->ai_flags = m_hints.ai_flags;
190 this->free_addrinfo();
194 m_res_current = new_res;
CAddrinfo(std::string_view a_node, std::string_view a_service, const int a_flags=0, const int a_socktype=SOCK_STREAM)
Constructor for getting an address information with service name.