#include <getopt.h>
#include <stdio.h>
+#include <stdlib.h>
#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},
};
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)
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;