From a7b687b121ed942cf0f42094b7f530985aba0ea1 Mon Sep 17 00:00:00 2001 From: Andreas Eversberg Date: Fri, 9 Feb 2024 15:44:49 +0100 Subject: [PATCH] examples/stream-*: Add options, to set local/remote peer This helps to test connections via a network and failing connections. The client may add "-r " to the command line, to set the address of the remote peer. The server may add "-l " to the command line, to select address of local peer. By default "127.0.0.1" is used. Change-Id: Ie6da55ef248436e521c5d8f21f8053356c46a114 --- examples/stream-client.c | 11 +++++++---- examples/stream-server.c | 10 +++++++--- 2 files changed, 14 insertions(+), 7 deletions(-) diff --git a/examples/stream-client.c b/examples/stream-client.c index e42748f..535804e 100644 --- a/examples/stream-client.c +++ b/examples/stream-client.c @@ -94,15 +94,19 @@ int main(int argc, char **argv) { struct osmo_fd *kbd_ofd; bool use_sctp = false; + const char *use_remote_addr = "127.0.0.1"; int opt, rc; - while ((opt = getopt(argc, argv, "s")) != -1) { + while ((opt = getopt(argc, argv, "sr:")) != -1) { switch (opt) { case 's': use_sctp = true; break; - default: + case 'r': + use_remote_addr = optarg; break; + default: + exit(0); } } @@ -121,11 +125,10 @@ int main(int argc, char **argv) exit(EXIT_FAILURE); } osmo_stream_cli_set_name(conn, "stream_client"); - osmo_stream_cli_set_addr(conn, "127.0.0.1"); + osmo_stream_cli_set_addr(conn, use_remote_addr); osmo_stream_cli_set_port(conn, 10000); if (use_sctp) osmo_stream_cli_set_proto(conn, IPPROTO_SCTP); - osmo_stream_cli_set_connect_cb(conn, connect_cb); osmo_stream_cli_set_disconnect_cb(conn, disconnect_cb); osmo_stream_cli_set_read_cb2(conn, read_cb); diff --git a/examples/stream-server.c b/examples/stream-server.c index 9faf307..bfbde6d 100644 --- a/examples/stream-server.c +++ b/examples/stream-server.c @@ -121,15 +121,19 @@ int main(int argc, char **argv) { struct osmo_fd *kbd_ofd; bool use_sctp = false; + const char *use_local_addr = "127.0.0.1"; int opt; - while ((opt = getopt(argc, argv, "s")) != -1) { + while ((opt = getopt(argc, argv, "sl:")) != -1) { switch (opt) { case 's': use_sctp = true; break; - default: + case 'l': + use_local_addr = optarg; break; + default: + exit(0); } } @@ -147,7 +151,7 @@ int main(int argc, char **argv) fprintf(stderr, "cannot create server link\n"); exit(EXIT_FAILURE); } - osmo_stream_srv_link_set_addr(srv, "127.0.0.1"); + osmo_stream_srv_link_set_addr(srv, use_local_addr); osmo_stream_srv_link_set_port(srv, 10000); if (use_sctp) osmo_stream_srv_link_set_proto(srv, IPPROTO_SCTP);