From 7618e079f516fde0636756d29247ed8bb3a1709e Mon Sep 17 00:00:00 2001 From: Simon Tatham Date: Sat, 29 Jun 2024 11:48:48 +0100 Subject: [PATCH] Log outgoing address + port numbers in the Event Log. This is the payoff from the previous three commits. If you run 'netstat' or 'ss' or equivalent, and see multiple outgoing SSH connections from your machine, and you want to match them up to the instances of PuTTY you can see on your desktop, how would you do it? On Linux you can trace each socket to an owning pid via 'ss -p', but tracing the pid in turn to a window isn't so easy. On Windows even the first step is hard. Now it shouldn't be too hard, because the Event Log mentions the IP address and ephemeral port number of the local end of a connection, after that connection is established, if that information is available. So now you can connect the local port numbers shown in the 'netstat' or 'ss' output with the ones in the GUI's Event Log. (This might be useful if, for example, one connection was showing a backlog in netstat, and you wanted to investigate the corresponding GUI.) --- utils/backend_socket_log.c | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/utils/backend_socket_log.c b/utils/backend_socket_log.c index 9036065a..b8bc9905 100644 --- a/utils/backend_socket_log.c +++ b/utils/backend_socket_log.c @@ -30,6 +30,16 @@ void backend_socket_log(Seat *seat, LogContext *logctx, Socket *sock, else /* fallback if address unavailable */ sprintf(addrbuf, "remote host"); msg = dupprintf("Connected to %s", addrbuf); + if (sock) { + SocketEndpointInfo *local_end = sk_endpoint_info(sock, false); + if (local_end) { + char *newmsg = dupprintf("%s (from %s)", msg, + local_end->log_text); + sfree(msg); + msg = newmsg; + sk_free_endpoint_info(local_end); + } + } break; case PLUGLOG_PROXY_MSG: { /* Proxy-related log messages have their own identifying