From ea836c09048453babda517e6a440d7266304ca02 Mon Sep 17 00:00:00 2001 From: David Härdeman Date: Thu, 11 Jun 2020 23:21:37 +0200 Subject: Use struct connect for the client connection as well in proxy --- utils.c | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) (limited to 'utils.c') diff --git a/utils.c b/utils.c index 8749c75..05fe124 100644 --- a/utils.c +++ b/utils.c @@ -187,16 +187,24 @@ socket_set_low_latency(struct cfg *cfg, int sfd) perror("setsockopt"); } -static void -connection_set_local_addr(struct cfg *cfg, struct connection *conn, int fd) +void +connection_set_local(struct cfg *cfg, struct connection *conn, int fd) { - if (fd < 0 || getsockname(fd, (struct sockaddr *)&conn->local.storage, + if (fd < 0 || getsockname(fd, + (struct sockaddr *)&conn->local.storage, &conn->local.addrlen) < 0) sprintf(conn->localstr, ""); else sockaddr_to_str(&conn->local, conn->localstr, sizeof(conn->localstr)); } +void +connection_set_remote(struct cfg *cfg, struct connection *conn, struct sockaddr_in46 *remote) +{ + conn->remote = *remote; + sockaddr_to_str(&conn->remote, &conn->remotestr, sizeof(conn->remotestr)); +} + static void connect_next(struct cfg *cfg, struct uring_task *task, struct connection *conn); static void @@ -212,7 +220,7 @@ connect_cb(struct cfg *cfg, struct uring_task *task, int res) return; } - connection_set_local_addr(cfg, conn, task->fd); + connection_set_local(cfg, conn, task->fd); fprintf(stderr, "%s: (%s) connection established %s -> %s\n", __func__, task->name, conn->localstr, conn->remotestr); @@ -245,8 +253,7 @@ again: } conn->next_addr++; - conn->remote = *remote; - sockaddr_to_str(&conn->remote, conn->remotestr, sizeof(conn->remotestr)); + connection_set_remote(cfg, conn, remote); fprintf(stderr, "%s: attempting to connect to %s\n", task->name, conn->remotestr); -- cgit v1.2.3