summaryrefslogtreecommitdiff
path: root/utils.c
diff options
context:
space:
mode:
authorDavid Härdeman <david@hardeman.nu>2020-06-11 23:21:37 +0200
committerDavid Härdeman <david@hardeman.nu>2020-06-11 23:21:37 +0200
commitea836c09048453babda517e6a440d7266304ca02 (patch)
tree8607a39388df4bbf647495090470222b806ff542 /utils.c
parent76e6067e13831569deca05dbb557d921998e3eb2 (diff)
Use struct connect for the client connection as well in proxy
Diffstat (limited to 'utils.c')
-rw-r--r--utils.c19
1 files changed, 13 insertions, 6 deletions
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, "<unknown>");
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);