diff options
author | Coren[m] <Break@Ocean> | 2013-09-10 22:59:33 +0200 |
---|---|---|
committer | Coren[m] <Break@Ocean> | 2013-09-10 22:59:33 +0200 |
commit | 64ca4b5db23dbb68d1b01e307837c9fb89283256 (patch) | |
tree | b8544dbb4146415dc48caa37946e6651c37ce519 /testing | |
parent | e89dda5cea04f217d7981d567de963cc8f2e76c7 (diff) |
tox.*, DHT.*:
- return to the caller if the string could be resolved into an IP
other/DHT_bootstrap.c, testing/*_test.c, testing/nTox.c:
- parse cmdline for --ipv4/--ipv6 switch to allow user a choice
util.h:
- proper old-style C-comment
Diffstat (limited to 'testing')
-rw-r--r-- | testing/DHT_test.c | 52 | ||||
-rw-r--r-- | testing/Lossless_UDP_testclient.c | 48 | ||||
-rw-r--r-- | testing/Lossless_UDP_testserver.c | 41 | ||||
-rw-r--r-- | testing/Messenger_test.c | 55 | ||||
-rw-r--r-- | testing/nTox.c | 73 |
5 files changed, 214 insertions, 55 deletions
diff --git a/testing/DHT_test.c b/testing/DHT_test.c index caa0cde2..61762162 100644 --- a/testing/DHT_test.c +++ b/testing/DHT_test.c | |||
@@ -133,8 +133,40 @@ void printpacket(uint8_t *data, uint32_t length, IP_Port ip_port) | |||
133 | 133 | ||
134 | int main(int argc, char *argv[]) | 134 | int main(int argc, char *argv[]) |
135 | { | 135 | { |
136 | /* let use decide by cmdline: TODO */ | 136 | if (argc < 4) { |
137 | uint8_t ipv6enabled = TOX_ENABLE_IPV6_DEFAULT; | 137 | printf("Usage: %s [--ipv4|--ipv6] ip port public_key\n", argv[0]); |
138 | exit(0); | ||
139 | } | ||
140 | |||
141 | /* let user override default by cmdline */ | ||
142 | uint8_t ipv6enabled = TOX_ENABLE_IPV6_DEFAULT; /* x */ | ||
143 | |||
144 | int argvoffset = 0, argi; | ||
145 | for(argi = 1; argi < argc; argi++) | ||
146 | if (!strncasecmp(argv[argi], "--ipv", 5)) { | ||
147 | if (argv[argi][5] && !argv[argi][6]) { | ||
148 | char c = argv[argi][5]; | ||
149 | if (c == '4') | ||
150 | ipv6enabled = 0; | ||
151 | else if (c == '6') | ||
152 | ipv6enabled = 1; | ||
153 | else { | ||
154 | printf("Invalid argument: %s. Try --ipv4 or --ipv6!\n", argv[argi]); | ||
155 | exit(1); | ||
156 | } | ||
157 | } | ||
158 | else { | ||
159 | printf("Invalid argument: %s. Try --ipv4 or --ipv6!\n", argv[argi]); | ||
160 | exit(1); | ||
161 | } | ||
162 | |||
163 | if (argvoffset != argi - 1) { | ||
164 | printf("Argument must come first: %s.\n", argv[argi]); | ||
165 | exit(1); | ||
166 | } | ||
167 | |||
168 | argvoffset++; | ||
169 | } | ||
138 | 170 | ||
139 | //memcpy(self_client_id, "qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqq", 32); | 171 | //memcpy(self_client_id, "qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqq", 32); |
140 | /* initialize networking */ | 172 | /* initialize networking */ |
@@ -144,11 +176,6 @@ int main(int argc, char *argv[]) | |||
144 | 176 | ||
145 | DHT *dht = new_DHT(new_net_crypto(new_networking(ip, PORT))); | 177 | DHT *dht = new_DHT(new_net_crypto(new_networking(ip, PORT))); |
146 | 178 | ||
147 | if (argc < 4) { | ||
148 | printf("usage %s ip port public_key\n", argv[0]); | ||
149 | exit(0); | ||
150 | } | ||
151 | |||
152 | new_keys(dht->c); | 179 | new_keys(dht->c); |
153 | printf("OUR ID: "); | 180 | printf("OUR ID: "); |
154 | uint32_t i; | 181 | uint32_t i; |
@@ -168,9 +195,16 @@ int main(int argc, char *argv[]) | |||
168 | 195 | ||
169 | DHT_addfriend(dht, hex_string_to_bin(temp_id)); | 196 | DHT_addfriend(dht, hex_string_to_bin(temp_id)); |
170 | 197 | ||
171 | |||
172 | perror("Initialization"); | 198 | perror("Initialization"); |
173 | DHT_bootstrap_ex(dht, argv[1], ipv6enabled, htons(atoi(argv[2])), hex_string_to_bin(argv[3])); | 199 | |
200 | uint16_t port = htons(atoi(argv[argvoffset + 2])); | ||
201 | unsigned char *binary_string = hex_string_to_bin(argv[argvoffset + 3]); | ||
202 | int res = DHT_bootstrap_ex(dht, argv[argvoffset + 1], ipv6enabled, port, binary_string); | ||
203 | free(binary_string); | ||
204 | if (!res) { | ||
205 | printf("Failed to convert \"%s\" into an IP address. Exiting...\n", argv[argvoffset + 1]); | ||
206 | return 1; | ||
207 | } | ||
174 | 208 | ||
175 | /* | 209 | /* |
176 | IP_Port ip_port; | 210 | IP_Port ip_port; |
diff --git a/testing/Lossless_UDP_testclient.c b/testing/Lossless_UDP_testclient.c index 564b2ecf..5d4c8547 100644 --- a/testing/Lossless_UDP_testclient.c +++ b/testing/Lossless_UDP_testclient.c | |||
@@ -151,21 +151,50 @@ void printconnection(int connection_id) | |||
151 | 151 | ||
152 | int main(int argc, char *argv[]) | 152 | int main(int argc, char *argv[]) |
153 | { | 153 | { |
154 | /* let use decide by cmdline: TODO */ | 154 | /* let user override default by cmdline */ |
155 | uint8_t ipv6enabled = TOX_ENABLE_IPV6_DEFAULT; | 155 | uint8_t ipv6enabled = TOX_ENABLE_IPV6_DEFAULT; /* x */ |
156 | |||
157 | int argvoffset = 0, argi; | ||
158 | for(argi = 1; argi < argc; argi++) | ||
159 | if (!strncasecmp(argv[argi], "--ipv", 5)) { | ||
160 | if (argv[argi][5] && !argv[argi][6]) { | ||
161 | char c = argv[argi][5]; | ||
162 | if (c == '4') | ||
163 | ipv6enabled = 0; | ||
164 | else if (c == '6') | ||
165 | ipv6enabled = 1; | ||
166 | else { | ||
167 | printf("Invalid argument: %s. Try --ipv4 or --ipv6!\n", argv[argi]); | ||
168 | exit(1); | ||
169 | } | ||
170 | } | ||
171 | else { | ||
172 | printf("Invalid argument: %s. Try --ipv4 or --ipv6!\n", argv[argi]); | ||
173 | exit(1); | ||
174 | } | ||
175 | |||
176 | if (argvoffset != argi - 1) { | ||
177 | printf("Argument must come first: %s.\n", argv[argi]); | ||
178 | exit(1); | ||
179 | } | ||
156 | 180 | ||
157 | if (argc < 4) { | 181 | argvoffset++; |
158 | printf("usage: %s ip port filename\n", argv[0]); | 182 | } |
183 | |||
184 | if (argc < argvoffset + 4) { | ||
185 | printf("Usage: %s [--ipv4|--ipv6] ip port filename\n", argv[0]); | ||
159 | exit(0); | 186 | exit(0); |
160 | } | 187 | } |
161 | 188 | ||
162 | uint8_t buffer[512]; | 189 | uint8_t buffer[512]; |
163 | int read; | 190 | int read; |
164 | 191 | ||
165 | FILE *file = fopen(argv[3], "rb"); | 192 | FILE *file = fopen(argv[argvoffset + 3], "rb"); |
166 | 193 | ||
167 | if (file == NULL) | 194 | if (file == NULL) { |
195 | printf("Failed to open file \"%s\".\n", argv[argvoffset + 3]); | ||
168 | return 1; | 196 | return 1; |
197 | } | ||
169 | 198 | ||
170 | 199 | ||
171 | /* initialize networking */ | 200 | /* initialize networking */ |
@@ -178,8 +207,11 @@ int main(int argc, char *argv[]) | |||
178 | 207 | ||
179 | IP_Port serverip; | 208 | IP_Port serverip; |
180 | ip_init(&serverip.ip, ipv6enabled); | 209 | ip_init(&serverip.ip, ipv6enabled); |
181 | addr_resolve(argv[1], &serverip.ip); | 210 | if (!addr_resolve(argv[argvoffset + 1], &serverip.ip)) { |
182 | serverip.port = htons(atoi(argv[2])); | 211 | printf("Failed to convert \"%s\" into an IP address.\n", argv[argvoffset + 1]); |
212 | return 1; | ||
213 | } | ||
214 | serverip.port = htons(atoi(argv[argvoffset + 2])); | ||
183 | printip(serverip); | 215 | printip(serverip); |
184 | 216 | ||
185 | int connection = new_connection(ludp, serverip); | 217 | int connection = new_connection(ludp, serverip); |
diff --git a/testing/Lossless_UDP_testserver.c b/testing/Lossless_UDP_testserver.c index 3e54e9be..52dbcc80 100644 --- a/testing/Lossless_UDP_testserver.c +++ b/testing/Lossless_UDP_testserver.c | |||
@@ -147,21 +147,50 @@ void printconnection(int connection_id) | |||
147 | 147 | ||
148 | int main(int argc, char *argv[]) | 148 | int main(int argc, char *argv[]) |
149 | { | 149 | { |
150 | /* let use decide by cmdline: TODO */ | 150 | /* let user override default by cmdline */ |
151 | uint8_t ipv6enabled = TOX_ENABLE_IPV6_DEFAULT; | 151 | uint8_t ipv6enabled = TOX_ENABLE_IPV6_DEFAULT; /* x */ |
152 | |||
153 | int argvoffset = 0, argi; | ||
154 | for(argi = 1; argi < argc; argi++) | ||
155 | if (!strncasecmp(argv[argi], "--ipv", 5)) { | ||
156 | if (argv[argi][5] && !argv[argi][6]) { | ||
157 | char c = argv[argi][5]; | ||
158 | if (c == '4') | ||
159 | ipv6enabled = 0; | ||
160 | else if (c == '6') | ||
161 | ipv6enabled = 1; | ||
162 | else { | ||
163 | printf("Invalid argument: %s. Try --ipv4 or --ipv6!\n", argv[argi]); | ||
164 | exit(1); | ||
165 | } | ||
166 | } | ||
167 | else { | ||
168 | printf("Invalid argument: %s. Try --ipv4 or --ipv6!\n", argv[argi]); | ||
169 | exit(1); | ||
170 | } | ||
171 | |||
172 | if (argvoffset != argi - 1) { | ||
173 | printf("Argument must come first: %s.\n", argv[argi]); | ||
174 | exit(1); | ||
175 | } | ||
152 | 176 | ||
153 | if (argc < 2) { | 177 | argvoffset++; |
154 | printf("usage: %s filename\n", argv[0]); | 178 | } |
179 | |||
180 | if (argc < argvoffset + 2) { | ||
181 | printf("Usage: %s [--ipv4|--ipv6] filename\n", argv[0]); | ||
155 | exit(0); | 182 | exit(0); |
156 | } | 183 | } |
157 | 184 | ||
158 | uint8_t buffer[512]; | 185 | uint8_t buffer[512]; |
159 | int read; | 186 | int read; |
160 | 187 | ||
161 | FILE *file = fopen(argv[1], "wb"); | 188 | FILE *file = fopen(argv[argvoffset + 1], "wb"); |
162 | 189 | ||
163 | if (file == NULL) | 190 | if (file == NULL) { |
191 | printf("Failed to open file \"%s\".\n", argv[argvoffset + 1]); | ||
164 | return 1; | 192 | return 1; |
193 | } | ||
165 | 194 | ||
166 | 195 | ||
167 | //initialize networking | 196 | //initialize networking |
diff --git a/testing/Messenger_test.c b/testing/Messenger_test.c index 73d44efb..e7a75c8c 100644 --- a/testing/Messenger_test.c +++ b/testing/Messenger_test.c | |||
@@ -95,13 +95,44 @@ void print_message(Messenger *m, int friendnumber, uint8_t *string, uint16_t len | |||
95 | 95 | ||
96 | int main(int argc, char *argv[]) | 96 | int main(int argc, char *argv[]) |
97 | { | 97 | { |
98 | if (argc < 4 && argc != 2) { | 98 | /* let user override default by cmdline */ |
99 | printf("usage %s ip port public_key (of the DHT bootstrap node)\n or\n %s Save.bak\n", argv[0], argv[0]); | 99 | uint8_t ipv6enabled = TOX_ENABLE_IPV6_DEFAULT; /* x */ |
100 | |||
101 | int argvoffset = 0, argi; | ||
102 | for(argi = 1; argi < argc; argi++) | ||
103 | if (!strncasecmp(argv[argi], "--ipv", 5)) { | ||
104 | if (argv[argi][5] && !argv[argi][6]) { | ||
105 | char c = argv[argi][5]; | ||
106 | if (c == '4') | ||
107 | ipv6enabled = 0; | ||
108 | else if (c == '6') | ||
109 | ipv6enabled = 1; | ||
110 | else { | ||
111 | printf("Invalid argument: %s. Try --ipv4 or --ipv6!\n", argv[argi]); | ||
112 | exit(1); | ||
113 | } | ||
114 | } | ||
115 | else { | ||
116 | printf("Invalid argument: %s. Try --ipv4 or --ipv6!\n", argv[argi]); | ||
117 | exit(1); | ||
118 | } | ||
119 | |||
120 | if (argvoffset != argi - 1) { | ||
121 | printf("Argument must come first: %s.\n", argv[argi]); | ||
122 | exit(1); | ||
123 | } | ||
124 | |||
125 | argvoffset++; | ||
126 | } | ||
127 | |||
128 | /* with optional --ipvx, now it can be 1-4 arguments... */ | ||
129 | if ((argc != argvoffset + 2) && (argc != argvoffset + 4)) { | ||
130 | printf("Usage: %s [--ipv4|--ipv6] ip port public_key (of the DHT bootstrap node)\n", argv[0]); | ||
131 | printf("or\n"); | ||
132 | printf(" %s [--ipv4|--ipv6] Save.bak (to read Save.bak as state file)\n", argv[0], argv[0]); | ||
100 | exit(0); | 133 | exit(0); |
101 | } | 134 | } |
102 | 135 | ||
103 | /* IPv6: maybe allow from cmdline --ipv6? sticking to IPv4 for now */ | ||
104 | uint8_t ipv6enabled = TOX_ENABLE_IPV6_DEFAULT; | ||
105 | m = initMessenger(ipv6enabled); | 136 | m = initMessenger(ipv6enabled); |
106 | 137 | ||
107 | if ( !m ) { | 138 | if ( !m ) { |
@@ -109,13 +140,19 @@ int main(int argc, char *argv[]) | |||
109 | exit(0); | 140 | exit(0); |
110 | } | 141 | } |
111 | 142 | ||
112 | if (argc > 3) { | 143 | if (argc == argvoffset + 4) { |
113 | uint16_t port = htons(atoi(argv[2])); | 144 | uint16_t port = htons(atoi(argv[argvoffset + 2])); |
114 | DHT_bootstrap_ex(m->dht, argv[1], ipv6enabled, port, hex_string_to_bin(argv[3])); | 145 | uint8_t *bootstrap_key = hex_string_to_bin(argv[argvoffset + 3]); |
146 | int res = DHT_bootstrap_ex(m->dht, argv[argvoffset + 1], ipv6enabled, port, bootstrap_key); | ||
147 | free(bootstrap_key); | ||
148 | if (!res) { | ||
149 | printf("Failed to convert \"%s\" into an IP address. Exiting...\n", argv[argvoffset + 1]); | ||
150 | exit(1); | ||
151 | } | ||
115 | } else { | 152 | } else { |
116 | FILE *file = fopen(argv[1], "rb"); | 153 | FILE *file = fopen(argv[argvoffset + 1], "rb"); |
117 | |||
118 | if ( file == NULL ) { | 154 | if ( file == NULL ) { |
155 | printf("Failed to open \"%s\" - does it exist?\n", argv[argvoffset + 1]); | ||
119 | return 1; | 156 | return 1; |
120 | } | 157 | } |
121 | 158 | ||
diff --git a/testing/nTox.c b/testing/nTox.c index 6084aeda..6eeec5d3 100644 --- a/testing/nTox.c +++ b/testing/nTox.c | |||
@@ -537,8 +537,40 @@ void print_help(void) | |||
537 | 537 | ||
538 | int main(int argc, char *argv[]) | 538 | int main(int argc, char *argv[]) |
539 | { | 539 | { |
540 | /* let use decide by cmdline: TODO */ | 540 | if (argc < 4) { |
541 | uint8_t ipv6enabled = TOX_ENABLE_IPV6_DEFAULT; | 541 | printf("Usage: %s [--ipv4|--ipv6] IP PORT KEY [-f keyfile]\n", argv[0]); |
542 | exit(0); | ||
543 | } | ||
544 | |||
545 | /* let user override default by cmdline */ | ||
546 | uint8_t ipv6enabled = TOX_ENABLE_IPV6_DEFAULT; /* x */ | ||
547 | |||
548 | int argvoffset = 0, argi; | ||
549 | for(argi = 1; argi < argc; argi++) | ||
550 | if (!strncasecmp(argv[argi], "--ipv", 5)) { | ||
551 | if (argv[argi][5] && !argv[argi][6]) { | ||
552 | char c = argv[argi][5]; | ||
553 | if (c == '4') | ||
554 | ipv6enabled = 0; | ||
555 | else if (c == '6') | ||
556 | ipv6enabled = 1; | ||
557 | else { | ||
558 | printf("Invalid argument: %s. Try --ipv4 or --ipv6!\n", argv[argi]); | ||
559 | exit(1); | ||
560 | } | ||
561 | } | ||
562 | else { | ||
563 | printf("Invalid argument: %s. Try --ipv4 or --ipv6!\n", argv[argi]); | ||
564 | exit(1); | ||
565 | } | ||
566 | |||
567 | if (argvoffset != argi - 1) { | ||
568 | printf("Argument must come first: %s.\n", argv[argi]); | ||
569 | exit(1); | ||
570 | } | ||
571 | |||
572 | argvoffset++; | ||
573 | } | ||
542 | 574 | ||
543 | int on = 0; | 575 | int on = 0; |
544 | int c = 0; | 576 | int c = 0; |
@@ -547,27 +579,16 @@ int main(int argc, char *argv[]) | |||
547 | char idstring[200] = {0}; | 579 | char idstring[200] = {0}; |
548 | Tox *m; | 580 | Tox *m; |
549 | 581 | ||
550 | if (argc < 4) { | 582 | if ((argc == 2) && !strcmp(argv[1], "-h")) { |
551 | printf("[!] Usage: %s [IP] [port] [public_key] <keyfile>\n", argv[0]); | 583 | print_help(); |
552 | exit(0); | 584 | exit(0); |
553 | } | 585 | } |
554 | 586 | ||
555 | for (i = 0; i < argc; i++) { | 587 | /* [-f keyfile] MUST be last two arguments, no point in walking over the list |
556 | if (argv[i] == NULL) { | 588 | * especially not a good idea to accept it anywhere in the middle */ |
557 | break; | 589 | if (argc > argvoffset + 3) |
558 | } else if (argv[i][0] == '-') { | 590 | if (!strcmp(argv[argc - 2], "-f")) |
559 | if (argv[i][1] == 'h') { | 591 | filename = argv[argc - 1]; |
560 | print_help(); | ||
561 | exit(0); | ||
562 | } else if (argv[i][1] == 'f') { | ||
563 | if (argv[i + 1] != NULL) | ||
564 | filename = argv[i + 1]; | ||
565 | else { | ||
566 | fputs("[!] you passed '-f' without giving an argument!\n", stderr); | ||
567 | } | ||
568 | } | ||
569 | } | ||
570 | } | ||
571 | 592 | ||
572 | m = tox_new_ex(ipv6enabled); | 593 | m = tox_new_ex(ipv6enabled); |
573 | 594 | ||
@@ -593,11 +614,17 @@ int main(int argc, char *argv[]) | |||
593 | new_lines(idstring); | 614 | new_lines(idstring); |
594 | strcpy(line, ""); | 615 | strcpy(line, ""); |
595 | 616 | ||
596 | uint16_t port = htons(atoi(argv[2])); | 617 | uint16_t port = htons(atoi(argv[argvoffset + 2])); |
597 | unsigned char *binary_string = hex_string_to_bin(argv[3]); | 618 | unsigned char *binary_string = hex_string_to_bin(argv[argvoffset + 3]); |
598 | tox_bootstrap_ex(m, argv[1], ipv6enabled, port, binary_string); | 619 | int res = tox_bootstrap_ex(m, argv[argvoffset + 1], ipv6enabled, port, binary_string); |
599 | free(binary_string); | 620 | free(binary_string); |
600 | 621 | ||
622 | if (!res) { | ||
623 | printf("Failed to convert \"%s\" into an IP address. Exiting...\n", argv[argvoffset + 1]); | ||
624 | endwin(); | ||
625 | exit(1); | ||
626 | } | ||
627 | |||
601 | nodelay(stdscr, TRUE); | 628 | nodelay(stdscr, TRUE); |
602 | while (1) { | 629 | while (1) { |
603 | if (on == 0 && tox_isconnected(m)) { | 630 | if (on == 0 && tox_isconnected(m)) { |