From 026ab797eb49c4e148a266f4d88f5a7ddab14027 Mon Sep 17 00:00:00 2001 From: Tatsuhiro Tsujikawa Date: Mon, 7 Sep 2015 22:40:37 +0900 Subject: [PATCH] src: util::numeric_host: Use inet_pton instead of getaddrinfo --- src/util.cc | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) diff --git a/src/util.cc b/src/util.cc index 9b709dbe..58d6272e 100644 --- a/src/util.cc +++ b/src/util.cc @@ -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) { - 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) { - struct addrinfo *res; - struct addrinfo hints {}; - hints.ai_family = family; - hints.ai_flags = AI_NUMERICHOST; - if (getaddrinfo(hostname, nullptr, &hints, &res)) { - return false; - } - freeaddrinfo(res); - return true; + int rv; + std::array dst; + + rv = inet_pton(family, hostname, dst.data()); + + return rv == 1; } std::string numeric_name(const struct sockaddr *sa, socklen_t salen) {