Commit 026ab797 authored by Tatsuhiro Tsujikawa's avatar Tatsuhiro Tsujikawa

src: util::numeric_host: Use inet_pton instead of getaddrinfo

parent 79945c0c
...@@ -636,19 +636,16 @@ void write_uri_field(std::ostream &o, const char *uri, const http_parser_url &u, ...@@ -636,19 +636,16 @@ void write_uri_field(std::ostream &o, const char *uri, const http_parser_url &u,
} }
bool numeric_host(const char *hostname) { bool numeric_host(const char *hostname) {
return numeric_host(hostname, AF_UNSPEC); return numeric_host(hostname, AF_INET) || numeric_host(hostname, AF_INET6);
} }
bool numeric_host(const char *hostname, int family) { bool numeric_host(const char *hostname, int family) {
struct addrinfo *res; int rv;
struct addrinfo hints {}; std::array<uint8_t, sizeof(struct in6_addr)> dst;
hints.ai_family = family;
hints.ai_flags = AI_NUMERICHOST; rv = inet_pton(family, hostname, dst.data());
if (getaddrinfo(hostname, nullptr, &hints, &res)) {
return false; return rv == 1;
}
freeaddrinfo(res);
return true;
} }
std::string numeric_name(const struct sockaddr *sa, socklen_t salen) { std::string numeric_name(const struct sockaddr *sa, socklen_t salen) {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment