summaryrefslogtreecommitdiff
path: root/testing/misc_tools.c
diff options
context:
space:
mode:
Diffstat (limited to 'testing/misc_tools.c')
-rw-r--r--testing/misc_tools.c33
1 files changed, 33 insertions, 0 deletions
diff --git a/testing/misc_tools.c b/testing/misc_tools.c
index c4dce1bb..824200d8 100644
--- a/testing/misc_tools.c
+++ b/testing/misc_tools.c
@@ -46,3 +46,36 @@ unsigned char *hex_string_to_bin(char hex_string[])
46 46
47 return val; 47 return val;
48} 48}
49
50
51int cmdline_parsefor_ipv46(int argc, char **argv, uint8_t *ipv6enabled)
52{
53 int argvoffset = 0, argi;
54 for(argi = 1; argi < argc; argi++)
55 if (!strncasecmp(argv[argi], "--ipv", 5)) {
56 if (argv[argi][5] && !argv[argi][6]) {
57 char c = argv[argi][5];
58 if (c == '4')
59 *ipv6enabled = 0;
60 else if (c == '6')
61 *ipv6enabled = 1;
62 else {
63 printf("Invalid argument: %s. Try --ipv4 or --ipv6!\n", argv[argi]);
64 return -1;
65 }
66 }
67 else {
68 printf("Invalid argument: %s. Try --ipv4 or --ipv6!\n", argv[argi]);
69 return -1;
70 }
71
72 if (argvoffset != argi - 1) {
73 printf("Argument must come first: %s.\n", argv[argi]);
74 return -1;
75 }
76
77 argvoffset++;
78 }
79
80 return argvoffset;
81};