aboutsummaryrefslogtreecommitdiffstats
path: root/examples
diff options
context:
space:
mode:
authorAndreas Eversberg <jolly@eversberg.eu>2024-02-09 15:44:49 +0100
committerlaforge <laforge@osmocom.org>2024-02-28 08:47:34 +0000
commita7b687b121ed942cf0f42094b7f530985aba0ea1 (patch)
tree40056dc7c5bc1b68e9daf110647809bf72d72408 /examples
parent15dcf5e743d83814242eda3980ee668877852f7b (diff)
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 <peer>" to the command line, to set the address of the remote peer. The server may add "-l <peer>" to the command line, to select address of local peer. By default "127.0.0.1" is used. Change-Id: Ie6da55ef248436e521c5d8f21f8053356c46a114
Diffstat (limited to 'examples')
-rw-r--r--examples/stream-client.c11
-rw-r--r--examples/stream-server.c10
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);