summaryrefslogtreecommitdiff
path: root/other/DHT_bootstrap.c
diff options
context:
space:
mode:
authorCoren[m] <Break@Ocean>2013-09-10 22:59:33 +0200
committerCoren[m] <Break@Ocean>2013-09-10 22:59:33 +0200
commit64ca4b5db23dbb68d1b01e307837c9fb89283256 (patch)
treeb8544dbb4146415dc48caa37946e6651c37ce519 /other/DHT_bootstrap.c
parente89dda5cea04f217d7981d567de963cc8f2e76c7 (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 'other/DHT_bootstrap.c')
-rw-r--r--other/DHT_bootstrap.c51
1 files changed, 45 insertions, 6 deletions
diff --git a/other/DHT_bootstrap.c b/other/DHT_bootstrap.c
index 7355ca10..795e24ac 100644
--- a/other/DHT_bootstrap.c
+++ b/other/DHT_bootstrap.c
@@ -81,11 +81,44 @@ void manage_keys(DHT *dht)
81 81
82int main(int argc, char *argv[]) 82int main(int argc, char *argv[])
83{ 83{
84 /* let use decide by cmdline: TODO */ 84 if (argc == 2 && !strncasecmp(argv[1], "-h", 3)) {
85 uint8_t ipv6enabled = TOX_ENABLE_IPV6_DEFAULT; 85 printf("Usage (connected) : %s [--ipv4|--ipv6] IP PORT KEY\n", argv[0]);
86 printf("Usage (unconnected): %s [--ipv4|--ipv6]\n", argv[0]);
87 exit(0);
88 }
89
90 /* let user override default by cmdline */
91 uint8_t ipv6enabled = TOX_ENABLE_IPV6_DEFAULT; /* x */
92
93 int argvoffset = 0, argi;
94 for(argi = 1; argi < argc; argi++)
95 if (!strncasecmp(argv[argi], "--ipv", 5)) {
96 if (argv[argi][5] && !argv[argi][6]) {
97 char c = argv[argi][5];
98 if (c == '4')
99 ipv6enabled = 0;
100 else if (c == '6')
101 ipv6enabled = 1;
102 else {
103 printf("Invalid argument: %s. Try --ipv4 or --ipv6!\n", argv[argi]);
104 exit(1);
105 }
106 }
107 else {
108 printf("Invalid argument: %s. Try --ipv4 or --ipv6!\n", argv[argi]);
109 exit(1);
110 }
111
112 if (argvoffset != argi - 1) {
113 printf("Argument must come first: %s.\n", argv[argi]);
114 exit(1);
115 }
116
117 argvoffset++;
118 }
86 119
87 /* Initialize networking - 120 /* Initialize networking -
88 Bind to ip 0.0.0.0:PORT */ 121 Bind to ip 0.0.0.0 / [::] : PORT */
89 IP ip; 122 IP ip;
90 ip_init(&ip, ipv6enabled); 123 ip_init(&ip, ipv6enabled);
91 124
@@ -112,11 +145,17 @@ int main(int argc, char *argv[])
112 145
113 perror("Initialization."); 146 perror("Initialization.");
114 147
115 if (argc > 3) { 148 if (argc > argvoffset + 3) {
116 printf("Trying to bootstrap into the network...\n"); 149 printf("Trying to bootstrap into the network...\n");
117 uint8_t *bootstrap_key = hex_string_to_bin(argv[3]); 150 uint16_t port = htons(atoi(argv[argvoffset + 2]));
118 DHT_bootstrap_ex(dht, argv[1], ipv6enabled, htons(atoi(argv[2])), bootstrap_key); 151 uint8_t *bootstrap_key = hex_string_to_bin(argv[argvoffset + 3]);
152 int res = DHT_bootstrap_ex(dht, argv[argvoffset + 1], ipv6enabled, port, bootstrap_key);
119 free(bootstrap_key); 153 free(bootstrap_key);
154
155 if (!res) {
156 printf("Failed to convert \"%s\" into an IP address. Exiting...\n", argv[argvoffset + 1]);
157 exit(1);
158 }
120 } 159 }
121 160
122 int is_waiting_for_dht_connection = 1; 161 int is_waiting_for_dht_connection = 1;