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.c34
1 files changed, 34 insertions, 0 deletions
diff --git a/testing/misc_tools.c b/testing/misc_tools.c
index c4dce1bb..81f5ed8a 100644
--- a/testing/misc_tools.c
+++ b/testing/misc_tools.c
@@ -46,3 +46,37 @@ 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
55 for (argi = 1; argi < argc; argi++)
56 if (!strncasecmp(argv[argi], "--ipv", 5)) {
57 if (argv[argi][5] && !argv[argi][6]) {
58 char c = argv[argi][5];
59
60 if (c == '4')
61 *ipv6enabled = 0;
62 else if (c == '6')
63 *ipv6enabled = 1;
64 else {
65 printf("Invalid argument: %s. Try --ipv4 or --ipv6!\n", argv[argi]);
66 return -1;
67 }
68 } else {
69 printf("Invalid argument: %s. Try --ipv4 or --ipv6!\n", argv[argi]);
70 return -1;
71 }
72
73 if (argvoffset != argi - 1) {
74 printf("Argument must come first: %s.\n", argv[argi]);
75 return -1;
76 }
77
78 argvoffset++;
79 }
80
81 return argvoffset;
82};