Skip to content

Commit

Permalink
Add a version (-v) command line argument
Browse files Browse the repository at this point in the history
  • Loading branch information
rationalsa committed Sep 22, 2021
1 parent 5d729a4 commit 55bf456
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 3 deletions.
3 changes: 2 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
CFLAGS=-g -O2 -Wall
VERSION=$(shell git rev-parse --short HEAD)
CFLAGS=-g -O2 -Wall -DVERSION=\"$(VERSION)\"

all: srtla_send srtla_rec

Expand Down
8 changes: 7 additions & 1 deletion srtla_rec.c
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,9 @@ Misc helper functions
*/
void print_help() {
fprintf(stderr, "Syntax: srtla_rec SRTLA_LISTEN_PORT SRT_HOST SRT_PORT\n");
fprintf(stderr,
"Syntax: srtla_rec [-v] SRTLA_LISTEN_PORT SRT_HOST SRT_PORT\n\n"
"-v Print the version and exit\n");
}

int const_time_cmp(const void *a, const void *b, int len) {
Expand Down Expand Up @@ -626,6 +628,10 @@ int resolve_srt_addr(char *host, char *port) {
#define ARG_SRT_PORT (argv[3])
int main(int argc, char **argv) {
// Command line argument parsing
if (argc == 2 && strcmp(argv[1], "-v") == 0) {
printf(VERSION "\n");
exit(0);
}
if (argc != 4) exit_help();

struct sockaddr_in listen_addr;
Expand Down
8 changes: 7 additions & 1 deletion srtla_send.c
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,9 @@ Misc helper functions
*/
void print_help() {
fprintf(stderr, "Syntax: srtla_send SRT_LISTEN_PORT SRTLA_HOST SRTLA_PORT BIND_IPS_FILE\n");
fprintf(stderr,
"Syntax: srtla_send SRT_LISTEN_PORT SRTLA_HOST SRTLA_PORT BIND_IPS_FILE\n\n"
"-v Print the version and exit\n");
}


Expand Down Expand Up @@ -644,6 +646,10 @@ void connection_housekeeping() {
#define ARG_SRTLA_PORT (argv[3])
#define ARG_IPS_FILE (argv[4])
int main(int argc, char **argv) {
if (argc == 2 && strcmp(argv[1], "-v") == 0) {
printf(VERSION "\n");
exit(0);
}
if (argc != 5) exit_help();

source_ip_file = ARG_IPS_FILE;
Expand Down

0 comments on commit 55bf456

Please sign in to comment.