1
0
mirror of https://git.tartarus.org/simon/putty.git synced 2025-07-01 03:22:48 -05:00

FdSocket, HandleSocket: store a notional peer address.

In the case where these socket types are constructed because of a
local proxy command, we do actually have a SockAddr representing the
logical host we were trying to make a connection to. So we might as
well store it in the socket implementation, and then we can include it
in the PLUGLOG_CONNECT_SUCCESS call to make the log message more
informative.
This commit is contained in:
Simon Tatham
2021-09-13 14:34:46 +01:00
parent 8f5e9a4f8d
commit a4b8ff911b
10 changed files with 32 additions and 18 deletions

View File

@ -23,6 +23,8 @@ typedef struct FdSocket {
int pending_error;
SockAddr *addr;
int port;
Plug *plug;
Socket sock;
@ -134,6 +136,9 @@ static void fdsocket_close(Socket *s)
bufchain_clear(&fds->pending_input_data);
bufchain_clear(&fds->pending_output_data);
if (fds->addr)
sk_addr_free(fds->addr);
delete_callbacks_for_context(fds);
sfree(fds);
@ -318,15 +323,19 @@ static const SocketVtable FdSocket_sockvt = {
static void fdsocket_connect_success_callback(void *ctx)
{
FdSocket *fds = (FdSocket *)ctx;
plug_log(fds->plug, PLUGLOG_CONNECT_SUCCESS, NULL, 0, NULL, 0);
plug_log(fds->plug, PLUGLOG_CONNECT_SUCCESS, fds->addr, fds->port,
NULL, 0);
}
Socket *make_fd_socket(int infd, int outfd, int inerrfd, Plug *plug)
Socket *make_fd_socket(int infd, int outfd, int inerrfd,
SockAddr *addr, int port, Plug *plug)
{
FdSocket *fds;
fds = snew(FdSocket);
fds->sock.vt = &FdSocket_sockvt;
fds->addr = addr;
fds->port = port;
fds->plug = plug;
fds->outgoingeof = EOF_NO;
fds->pending_error = 0;

View File

@ -98,8 +98,5 @@ Socket *platform_new_connection(SockAddr *addr, const char *hostname,
inerrfd = -1;
}
/* We are responsible for this and don't need it any more */
sk_addr_free(addr);
return make_fd_socket(infd, outfd, inerrfd, plug);
return make_fd_socket(infd, outfd, inerrfd, addr, port, plug);
}

View File

@ -380,7 +380,8 @@ bool so_peercred(int fd, int *pid, int *uid, int *gid);
/*
* uxfdsock.c.
*/
Socket *make_fd_socket(int infd, int outfd, int inerrfd, Plug *plug);
Socket *make_fd_socket(int infd, int outfd, int inerrfd,
SockAddr *addr, int port, Plug *plug);
/*
* Default font setting, which can vary depending on NOT_X_WINDOWS.

View File

@ -411,7 +411,7 @@ int main(int argc, char **argv)
} else {
struct server_instance *inst;
Plug *plug = server_conn_plug(&scfg, &inst);
ssh_server_start(plug, make_fd_socket(0, 1, -1, plug));
ssh_server_start(plug, make_fd_socket(0, 1, -1, NULL, 0, plug));
log_to_stderr(inst->id, "running directly on stdio");
}

View File

@ -869,7 +869,7 @@ int main(int argc, char **argv)
} else {
struct server_instance *inst;
Plug *plug = server_conn_plug(&scfg, &inst);
ssh_server_start(plug, make_fd_socket(0, 1, -1, plug));
ssh_server_start(plug, make_fd_socket(0, 1, -1, NULL, 0, plug));
log_to_stderr(inst->id, "speaking SSH on stdio");
}