summaryrefslogtreecommitdiff
path: root/toxcore
diff options
context:
space:
mode:
authorCoren[m] <Break@Ocean>2013-09-11 00:14:20 +0200
committerCoren[m] <Break@Ocean>2013-09-11 00:14:20 +0200
commit4cf0d857bcf87ba271178e7b1734958fb93b018a (patch)
tree415ac36bb195c319418c942ffa31e8a67616818e /toxcore
parent8ba6a5ff5b05d027bc4c131b208015ea4019026b (diff)
cmdline parsing of --ipv4/6 plucked into util
Diffstat (limited to 'toxcore')
-rw-r--r--toxcore/util.c32
-rw-r--r--toxcore/util.h2
2 files changed, 34 insertions, 0 deletions
diff --git a/toxcore/util.c b/toxcore/util.c
index 19d464d4..7b5ddc49 100644
--- a/toxcore/util.c
+++ b/toxcore/util.c
@@ -43,6 +43,38 @@ void id_cpy(uint8_t *dest, uint8_t *src)
43 memcpy(dest, src, CLIENT_ID_SIZE); 43 memcpy(dest, src, CLIENT_ID_SIZE);
44} 44}
45 45
46int cmdline_parsefor_ipv46(int argc, char **argv, uint8_t *ipv6enabled)
47{
48 int argvoffset = 0, argi;
49 for(argi = 1; argi < argc; argi++)
50 if (!strncasecmp(argv[argi], "--ipv", 5)) {
51 if (argv[argi][5] && !argv[argi][6]) {
52 char c = argv[argi][5];
53 if (c == '4')
54 *ipv6enabled = 0;
55 else if (c == '6')
56 *ipv6enabled = 1;
57 else {
58 printf("Invalid argument: %s. Try --ipv4 or --ipv6!\n", argv[argi]);
59 return -1;
60 }
61 }
62 else {
63 printf("Invalid argument: %s. Try --ipv4 or --ipv6!\n", argv[argi]);
64 return -1;
65 }
66
67 if (argvoffset != argi - 1) {
68 printf("Argument must come first: %s.\n", argv[argi]);
69 return -1;
70 }
71
72 argvoffset++;
73 }
74
75 return argvoffset;
76};
77
46#ifdef LOGGING 78#ifdef LOGGING
47char logbuffer[512]; 79char logbuffer[512];
48static FILE *logfile = NULL; 80static FILE *logfile = NULL;
diff --git a/toxcore/util.h b/toxcore/util.h
index 71be84ca..e7be2d51 100644
--- a/toxcore/util.h
+++ b/toxcore/util.h
@@ -16,6 +16,8 @@ uint64_t random_64b();
16bool id_eq(uint8_t *dest, uint8_t *src); 16bool id_eq(uint8_t *dest, uint8_t *src);
17void id_cpy(uint8_t *dest, uint8_t *src); 17void id_cpy(uint8_t *dest, uint8_t *src);
18 18
19int cmdline_parsefor_ipv46(int argc, char **argv, uint8_t *ipv6enabled);
20
19#undef LOGGING 21#undef LOGGING
20/* #define LOGGING */ 22/* #define LOGGING */
21#ifdef LOGGING 23#ifdef LOGGING