From: Michael Tremer Date: Mon, 25 Jan 2021 13:06:41 +0000 (+0000) Subject: Make port configurable X-Git-Tag: 0.1.0~57 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=c39b0dc4ca068c99f4ecd69f21d685b33e6aaf02;p=fireperf.git Make port configurable Signed-off-by: Michael Tremer --- diff --git a/configure.ac b/configure.ac index b519fc6..35feb9b 100644 --- a/configure.ac +++ b/configure.ac @@ -66,6 +66,7 @@ AC_CHECK_HEADERS_ONCE([ getopt.h \ netinet/in.h \ stdio.h \ + stdlib.h \ string.h \ ]) diff --git a/src/main.c b/src/main.c index c31e2c4..0cc8578 100644 --- a/src/main.c +++ b/src/main.c @@ -20,12 +20,14 @@ #include #include +#include #include "main.h" static int parse_argv(int argc, char* argv[], struct fireperf_config* conf) { static struct option long_options[] = { {"client", required_argument, 0, 'c'}, + {"port", required_argument, 0, 'p'}, {"server", no_argument, 0, 's'}, {0, 0, 0, 0}, }; @@ -34,7 +36,7 @@ static int parse_argv(int argc, char* argv[], struct fireperf_config* conf) { int done = 0; while (!done) { - int c = getopt_long(argc, argv, "c:s", long_options, &option_index); + int c = getopt_long(argc, argv, "c:p:s", long_options, &option_index); // End if (c == -1) @@ -61,6 +63,16 @@ static int parse_argv(int argc, char* argv[], struct fireperf_config* conf) { conf->mode = FIREPERF_MODE_CLIENT; break; + case 'p': + conf->port = atoi(optarg); + + // Validate input + if (conf->port <= 0 || conf->port >= 65536) { + fprintf(stderr, "Invalid port number: %u\n", conf->port); + return 2; + } + break; + case 's': conf->mode = FIREPERF_MODE_SERVER; break; diff --git a/src/main.h b/src/main.h index 22c900f..4a84771 100644 --- a/src/main.h +++ b/src/main.h @@ -24,4 +24,5 @@ struct fireperf_config { FIREPERF_MODE_CLIENT, FIREPERF_MODE_SERVER, } mode; + int port; };