From: job Date: Wed, 2 Nov 2022 10:41:43 +0000 (+0000) Subject: Also print IP address of the connection that timed out to aid debugging X-Git-Url: http://artulab.com/gitweb/?a=commitdiff_plain;h=310fe3aba1b3d78dd4e75edea76be42cd7cdb224;p=openbsd Also print IP address of the connection that timed out to aid debugging OK claudio@ --- diff --git a/usr.sbin/rpki-client/http.c b/usr.sbin/rpki-client/http.c index f89a10f59c9..171c330f5a1 100644 --- a/usr.sbin/rpki-client/http.c +++ b/usr.sbin/rpki-client/http.c @@ -1,4 +1,4 @@ -/* $OpenBSD: http.c,v 1.70 2022/10/18 14:03:39 claudio Exp $ */ +/* $OpenBSD: http.c,v 1.71 2022/11/02 10:41:43 job Exp $ */ /* * Copyright (c) 2020 Nils Fisher * Copyright (c) 2020 Claudio Jeker @@ -209,6 +209,32 @@ http_info(const char *uri) return buf; } +/* + * Return IP address in presentation format. + */ +static const char * +ip_info(const struct http_connection *conn) +{ + static char buf[NI_MAXHOST + 3]; + char ipbuf[NI_MAXHOST]; + int ret; + + assert(conn->state == STATE_CONNECT); + + if (conn->res == NULL) + return (" (unknown)"); + + if (getnameinfo(conn->res->ai_addr, conn->res->ai_addrlen, ipbuf, + sizeof(ipbuf), NULL, 0, NI_NUMERICHOST) != 0) + return (" (unknown)"); + + ret = snprintf(buf, sizeof(buf), " (%s)", ipbuf); + if (ret < 0 || (size_t)ret >= sizeof(buf)) + err(1, NULL); + + return buf; +} + /* * Determine whether the character needs encoding, per RFC2396. */ @@ -1930,7 +1956,8 @@ proc_http(char *bind_addr, int fd) http_do(conn, http_handle); else if (conn->io_time <= now) { if (conn->state == STATE_CONNECT) { - warnx("%s: connect timeout", + warnx("%s%s: connect timeout", + ip_info(conn), http_info(conn->host)); http_do(conn, http_connect_failed); } else {