From 1bdf664f4d87bb8a2c2633beab94912ff4357cc1 Mon Sep 17 00:00:00 2001 From: Brian Card Date: Thu, 26 Feb 2015 08:59:25 -0500 Subject: [PATCH] Changing signature of numeric_name from numeric_name(addrinfo *addr) to numeric_name(const struct sockaddr *sa, socklen_t salen) to remove dependency on addrinfo struct. --- src/HttpServer.cc | 2 +- src/nghttp.cc | 4 ++-- src/util.cc | 4 ++-- src/util.h | 2 +- 4 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/HttpServer.cc b/src/HttpServer.cc index 1c986410..ce649be8 100644 --- a/src/HttpServer.cc +++ b/src/HttpServer.cc @@ -1536,7 +1536,7 @@ int start_listen(struct ev_loop *loop, Sessions *sessions, new ListenEventHandler(sessions, fd, acceptor); if (config->verbose) { - std::string s = util::numeric_name(rp); + std::string s = util::numeric_name(rp->ai_addr, rp->ai_addrlen); std::cout << (rp->ai_family == AF_INET ? "IPv4" : "IPv6") << ": listen " << s << ":" << config->port << std::endl; } diff --git a/src/nghttp.cc b/src/nghttp.cc index ccff2567..24a8dd7f 100644 --- a/src/nghttp.cc +++ b/src/nghttp.cc @@ -674,13 +674,13 @@ int HttpClient::noop() { return 0; } void HttpClient::on_connect_fail() { if (state == STATE_IDLE) { std::cerr << "[ERROR] Could not connect to the address " - << util::numeric_name(cur_addr) << std::endl; + << util::numeric_name(cur_addr->ai_addr, cur_addr->ai_addrlen) << std::endl; } auto cur_state = state; disconnect(); if (cur_state == STATE_IDLE) { if (initiate_connection() == 0) { - std::cerr << "Trying next address " << util::numeric_name(cur_addr) + std::cerr << "Trying next address " << util::numeric_name(cur_addr->ai_addr, cur_addr->ai_addrlen) << std::endl; } } diff --git a/src/util.cc b/src/util.cc index 8dea595b..9ae07965 100644 --- a/src/util.cc +++ b/src/util.cc @@ -688,9 +688,9 @@ bool numeric_host(const char *hostname) { // Returns numeric address string of |addr|. If getnameinfo() is // failed, "unknown" is returned. -std::string numeric_name(addrinfo *addr) { +std::string numeric_name(const struct sockaddr *sa, socklen_t salen) { char host[NI_MAXHOST]; - auto rv = getnameinfo(addr->ai_addr, addr->ai_addrlen, host, sizeof(host), + auto rv = getnameinfo(sa, salen, host, sizeof(host), nullptr, 0, NI_NUMERICHOST); if (rv != 0) { return "unknown"; diff --git a/src/util.h b/src/util.h index f4246d40..b111dca2 100644 --- a/src/util.h +++ b/src/util.h @@ -418,7 +418,7 @@ void write_uri_field(std::ostream &o, const char *uri, const http_parser_url &u, bool numeric_host(const char *hostname); -std::string numeric_name(addrinfo *addr); +std::string numeric_name(const struct sockaddr *sa, socklen_t salen); // Opens |path| with O_APPEND enabled. If file does not exist, it is // created first. This function returns file descriptor referring the