summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorfadhil riyanto <me@fadev.org>2024-09-24 09:26:13 +0700
committerfadhil riyanto <me@fadev.org>2024-09-24 09:26:13 +0700
commit3634d33ab5b48535b850bc21652d1ea3a2d7be6c (patch)
treec8a3d3eb2e986668a7f661e031fcd6780ca0e81a
parentc4ffc63134d906868e78864aff48ff2cd8a13fa1 (diff)
getopt_long add mode
-rw-r--r--main.c36
1 files changed, 31 insertions, 5 deletions
diff --git a/main.c b/main.c
index 4efc086..7307d64 100644
--- a/main.c
+++ b/main.c
@@ -1,27 +1,49 @@
-
-#include <stdio.h>
+#include <string.h>
#include <getopt.h>
#include "submodule/log.c-patched/src/log.h"
#define dbgchr(x) log_info("%c", x)
-static int parseopt(int argc, char **argv)
+enum tcpf_mode {
+ TCPF_SERVER,
+ TCPF_CLIENT
+};
+
+struct runtime_opts {
+ enum tcpf_mode mode;
+};
+
+static int parseopt(int argc, char **argv, struct runtime_opts *r_opts)
{
int optcounter = 0;
int c = 0;
static struct option opt_table[] = {
{"mode", required_argument, 0, 'm'},
+ // {"mode", required_argument, 0, 'm'},4
{0, 0, 0, 0}
};
while(1) {
c = getopt_long(argc, argv, "m:", opt_table, &optcounter);
- dbgchr(c);
+ // dbgchr(c);
if (c == -1)
break;
+ switch (c) {
+ case 'm':
+ if (strcmp(optarg, "server") == 0) {
+ r_opts->mode = TCPF_SERVER;
+ }
+
+ if (strcmp(optarg, "client") == 0) {
+ r_opts->mode = TCPF_CLIENT;
+ }
+ break;
+ }
+
+
}
@@ -29,5 +51,9 @@ static int parseopt(int argc, char **argv)
int main(int argc, char **argv)
{
- parseopt(argc, argv);
+
+ struct runtime_opts runtime_opts;
+ parseopt(argc, argv, &runtime_opts);
+
+ return 0;
} \ No newline at end of file