summaryrefslogtreecommitdiff
path: root/testing/nTox.c
diff options
context:
space:
mode:
Diffstat (limited to 'testing/nTox.c')
-rw-r--r--testing/nTox.c56
1 files changed, 27 insertions, 29 deletions
diff --git a/testing/nTox.c b/testing/nTox.c
index 438468bd..750970f9 100644
--- a/testing/nTox.c
+++ b/testing/nTox.c
@@ -537,6 +537,17 @@ void print_help(void)
537 537
538int main(int argc, char *argv[]) 538int main(int argc, char *argv[])
539{ 539{
540 if (argc < 4) {
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 int argvoffset = cmdline_parsefor_ipv46(argc, argv, &ipv6enabled);
548 if (argvoffset < 0)
549 exit(1);
550
540 int on = 0; 551 int on = 0;
541 int c = 0; 552 int c = 0;
542 int i = 0; 553 int i = 0;
@@ -544,29 +555,18 @@ int main(int argc, char *argv[])
544 char idstring[200] = {0}; 555 char idstring[200] = {0};
545 Tox *m; 556 Tox *m;
546 557
547 if (argc < 4) { 558 if ((argc == 2) && !strcmp(argv[1], "-h")) {
548 printf("[!] Usage: %s [IP] [port] [public_key] <keyfile>\n", argv[0]); 559 print_help();
549 exit(0); 560 exit(0);
550 } 561 }
551 562
552 for (i = 0; i < argc; i++) { 563 /* [-f keyfile] MUST be last two arguments, no point in walking over the list
553 if (argv[i] == NULL) { 564 * especially not a good idea to accept it anywhere in the middle */
554 break; 565 if (argc > argvoffset + 3)
555 } else if (argv[i][0] == '-') { 566 if (!strcmp(argv[argc - 2], "-f"))
556 if (argv[i][1] == 'h') { 567 filename = argv[argc - 1];
557 print_help();
558 exit(0);
559 } else if (argv[i][1] == 'f') {
560 if (argv[i + 1] != NULL)
561 filename = argv[i + 1];
562 else {
563 fputs("[!] you passed '-f' without giving an argument!\n", stderr);
564 }
565 }
566 }
567 }
568 568
569 m = tox_new(); 569 m = tox_new_ex(ipv6enabled);
570 570
571 if ( !m ) { 571 if ( !m ) {
572 fputs("Failed to allocate Messenger datastructure", stderr); 572 fputs("Failed to allocate Messenger datastructure", stderr);
@@ -590,20 +590,18 @@ int main(int argc, char *argv[])
590 new_lines(idstring); 590 new_lines(idstring);
591 strcpy(line, ""); 591 strcpy(line, "");
592 592
593 tox_IP_Port bootstrap_ip_port; 593 uint16_t port = htons(atoi(argv[argvoffset + 2]));
594 bootstrap_ip_port.port = htons(atoi(argv[2])); 594 unsigned char *binary_string = hex_string_to_bin(argv[argvoffset + 3]);
595 int resolved_address = resolve_addr(argv[1]); 595 int res = tox_bootstrap_ex(m, argv[argvoffset + 1], ipv6enabled, port, binary_string);
596 free(binary_string);
596 597
597 if (resolved_address != 0) 598 if (!res) {
598 bootstrap_ip_port.ip.i = resolved_address; 599 printf("Failed to convert \"%s\" into an IP address. Exiting...\n", argv[argvoffset + 1]);
599 else 600 endwin();
600 exit(1); 601 exit(1);
602 }
601 603
602 unsigned char *binary_string = hex_string_to_bin(argv[3]);
603 tox_bootstrap(m, bootstrap_ip_port, binary_string);
604 free(binary_string);
605 nodelay(stdscr, TRUE); 604 nodelay(stdscr, TRUE);
606
607 while (1) { 605 while (1) {
608 if (on == 0 && tox_isconnected(m)) { 606 if (on == 0 && tox_isconnected(m)) {
609 new_lines("[i] connected to DHT\n[i] define username with /n"); 607 new_lines("[i] connected to DHT\n[i] define username with /n");