diff options
Diffstat (limited to 'utils.c')
-rw-r--r-- | utils.c | 19 |
1 files changed, 13 insertions, 6 deletions
@@ -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); |