-/* $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 <nils_fisher@hotmail.com>
* Copyright (c) 2020 Claudio Jeker <claudio@openbsd.org>
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.
*/
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 {