From 0927433344efc799f41e1c427caca4a04ea999fa Mon Sep 17 00:00:00 2001 From: Quentin Dufour Date: Thu, 14 Jan 2021 13:23:40 +0100 Subject: [PATCH] Fix tcp port bug --- src/meas_lat.c | 22 ++++++++++------------ 1 file changed, 10 insertions(+), 12 deletions(-) diff --git a/src/meas_lat.c b/src/meas_lat.c index 0fdee95..91bb9f6 100644 --- a/src/meas_lat.c +++ b/src/meas_lat.c @@ -418,11 +418,11 @@ void spawn_tcp_client(struct evt_core_ctx* evts) { register_timer (evts, mctx, &ms, NULL); } -void spawn_tcp_server(struct evt_core_ctx* evts, uint16_t *ports) { +void spawn_tcp_server(struct evt_core_ctx* evts, uint16_t port) { char buffer[1024]; int tcp_serv_sock, err; - sprintf(buffer, "%d", ports[0]); + sprintf(buffer, "%d", port); tcp_serv_sock = create_tcp_server ("0.0.0.0", buffer); err = listen(tcp_serv_sock, SOMAXCONN); @@ -432,13 +432,13 @@ void spawn_tcp_server(struct evt_core_ctx* evts, uint16_t *ports) { fdinfo.url = buffer; fdinfo.fd = tcp_serv_sock; - sprintf(buffer, "tcp:co:127.0.0.1:%d", ports[0]); + sprintf(buffer, "tcp:co:127.0.0.1:%d", port); fdinfo.cat->name = "tcp-co"; evt_core_add_fd(evts, &fdinfo); printf("--- TCP server is listening\n"); } -void measlat_create_onion_services(struct tor_os_str* tos, struct tor_ctl* tctl, uint16_t* ports, int ports_count, enum TOR_ONION_FLAGS tof) { +void measlat_create_onion_services(struct tor_os_str* tos, struct tor_ctl* tctl, uint16_t port, enum TOR_ONION_FLAGS tof) { tor_os_create (tos, "onion_services.pub", "onion_services.txt", 1); tor_os_read (tos); @@ -448,7 +448,7 @@ void measlat_create_onion_services(struct tor_os_str* tos, struct tor_ctl* tctl, fprintf(stderr, "Unable to open Tor Socket\n"); exit(EXIT_FAILURE); } - err = tor_ctl_add_onion (tctl, tos, ports, ports_count, tof); + err = tor_ctl_add_onion (tctl, tos, &port, 1, tof); if (err != 0) { fprintf(stderr, "Unable to create Onion Services (error: %d)\n", err); exit(EXIT_FAILURE); @@ -456,9 +456,9 @@ void measlat_create_onion_services(struct tor_os_str* tos, struct tor_ctl* tctl, printf("--- Onion services created\n"); } -void spawn_onion_server(struct evt_core_ctx* evts, uint16_t *ports, int ports_count, struct tor_os_str* tos, struct tor_ctl* tctl, struct measlat_ctx* mctx) { - spawn_tcp_server(evts, ports); - measlat_create_onion_services (tos, tctl, ports, ports_count, mctx->tor_flags); +void spawn_onion_server(struct evt_core_ctx* evts, uint16_t port, struct tor_os_str* tos, struct tor_ctl* tctl, struct measlat_ctx* mctx) { + spawn_tcp_server(evts, port); + measlat_create_onion_services (tos, tctl, port, mctx->tor_flags); } int main(int argc, char** argv) { @@ -470,8 +470,6 @@ int main(int argc, char** argv) { struct evt_core_ctx evts = {0}; struct tor_os_str tos = {0}; struct tor_ctl tctl = {0}; - uint16_t ports[] = {7500}; - int ports_count = sizeof(ports) / sizeof(ports[0]); // 1. Parse parameters while ((opt = getopt(argc, argv, "vh:p:c:s:i:t:ln")) != -1) { @@ -525,8 +523,8 @@ int main(int argc, char** argv) { // 4. Register services if (mctx.role == MEASLAT_SERVER) { if (streq(mctx.transport, "udp")) spawn_udp_server (&evts); - else if (streq(mctx.transport, "tcp")) spawn_tcp_server(&evts, ports); - else if (streq(mctx.transport, "tor")) spawn_onion_server (&evts, ports, ports_count, &tos, &tctl, &mctx); + else if (streq(mctx.transport, "tcp")) spawn_tcp_server(&evts, atoi(mctx.port)); + else if (streq(mctx.transport, "tor")) spawn_onion_server (&evts, atoi(mctx.port), &tos, &tctl, &mctx); } else if (mctx.role == MEASLAT_CLIENT) { if (streq(mctx.transport, "udp")) spawn_udp_client(&evts);