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
This commit is contained in:
Andreas Eversberg 2024-02-09 15:44:49 +01:00 committed by laforge
parent 15dcf5e743
commit a7b687b121
2 changed files with 14 additions and 7 deletions

View File

@ -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);

View File

@ -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);