nghttpx: Better logging for DNS resolver

This commit is contained in:
Tatsuhiro Tsujikawa 2016-12-10 23:10:18 +09:00
parent d66d34f9b9
commit 0967ee9cb9
1 changed files with 15 additions and 10 deletions

View File

@ -281,22 +281,17 @@ void DNSResolver::on_result(int status, hostent *hostent) {
if (status != ARES_SUCCESS) { if (status != ARES_SUCCESS) {
if (LOG_ENABLED(INFO)) { if (LOG_ENABLED(INFO)) {
LOG(INFO) << "Address lookup for " << name_ LOG(INFO) << "Name lookup for " << name_
<< " failed: " << ares_strerror(status); << " failed: " << ares_strerror(status);
} }
status_ = DNS_STATUS_ERROR; status_ = DNS_STATUS_ERROR;
return; return;
} }
if (LOG_ENABLED(INFO)) {
LOG(INFO) << "Address lookup for " << name_ << " succeeded";
}
status_ = DNS_STATUS_OK;
switch (hostent->h_addrtype) { switch (hostent->h_addrtype) {
case AF_INET: case AF_INET:
for (auto ap = hostent->h_addr_list; *ap; ++ap) { for (auto ap = hostent->h_addr_list; *ap; ++ap) {
status_ = DNS_STATUS_OK;
result_.len = sizeof(result_.su.in); result_.len = sizeof(result_.su.in);
result_.su.in = {}; result_.su.in = {};
result_.su.in.sin_family = AF_INET; result_.su.in.sin_family = AF_INET;
@ -304,11 +299,12 @@ void DNSResolver::on_result(int status, hostent *hostent) {
result_.su.in.sin_len = sizeof(result_.su.in); result_.su.in.sin_len = sizeof(result_.su.in);
#endif // HAVE_SOCKADDR_IN_SIN_LEN #endif // HAVE_SOCKADDR_IN_SIN_LEN
memcpy(&result_.su.in.sin_addr, *ap, sizeof(result_.su.in.sin_addr)); memcpy(&result_.su.in.sin_addr, *ap, sizeof(result_.su.in.sin_addr));
return; break;
} }
break; break;
case AF_INET6: case AF_INET6:
for (auto ap = hostent->h_addr_list; *ap; ++ap) { for (auto ap = hostent->h_addr_list; *ap; ++ap) {
status_ = DNS_STATUS_OK;
result_.len = sizeof(result_.su.in6); result_.len = sizeof(result_.su.in6);
result_.su.in6 = {}; result_.su.in6 = {};
result_.su.in6.sin6_family = AF_INET6; result_.su.in6.sin6_family = AF_INET6;
@ -316,12 +312,21 @@ void DNSResolver::on_result(int status, hostent *hostent) {
result_.su.in6.sin6_len = sizeof(result_.su.in6); result_.su.in6.sin6_len = sizeof(result_.su.in6);
#endif // HAVE_SOCKADDR_IN6_SIN6_LEN #endif // HAVE_SOCKADDR_IN6_SIN6_LEN
memcpy(&result_.su.in6.sin6_addr, *ap, sizeof(result_.su.in6.sin6_addr)); memcpy(&result_.su.in6.sin6_addr, *ap, sizeof(result_.su.in6.sin6_addr));
return;
}
break; break;
} }
break;
default:
assert(0);
}
if (status_ == DNS_STATUS_OK) {
if (LOG_ENABLED(INFO)) {
LOG(INFO) << "Name lookup succeeded: " << name_ << " -> "
<< util::numeric_name(&result_.su.sa, result_.len);
}
return;
}
// Somehow we got unsupported address family
status_ = DNS_STATUS_ERROR; status_ = DNS_STATUS_ERROR;
} }