diff options
-rw-r--r-- | testing/toxic/main.c | 14 |
1 files changed, 8 insertions, 6 deletions
diff --git a/testing/toxic/main.c b/testing/toxic/main.c index 3db963b4..d7d375a3 100644 --- a/testing/toxic/main.c +++ b/testing/toxic/main.c | |||
@@ -140,6 +140,7 @@ static void init_tox() | |||
140 | } | 140 | } |
141 | 141 | ||
142 | #define MAXLINE 90 /* Approx max number of chars in a sever line (IP + port + key) */ | 142 | #define MAXLINE 90 /* Approx max number of chars in a sever line (IP + port + key) */ |
143 | #define MINLINE 70 | ||
143 | #define MAXSERVERS 50 | 144 | #define MAXSERVERS 50 |
144 | 145 | ||
145 | /* Connects to a random DHT server listed in the DHTservers file */ | 146 | /* Connects to a random DHT server listed in the DHTservers file */ |
@@ -149,7 +150,7 @@ int init_connection(void) | |||
149 | return 0; | 150 | return 0; |
150 | 151 | ||
151 | FILE *fp = fopen("../../../other/DHTservers", "r"); | 152 | FILE *fp = fopen("../../../other/DHTservers", "r"); |
152 | if (fp == NULL) | 153 | if (!fp) |
153 | return 1; | 154 | return 1; |
154 | 155 | ||
155 | char servers[MAXSERVERS][MAXLINE]; | 156 | char servers[MAXSERVERS][MAXLINE]; |
@@ -157,7 +158,7 @@ int init_connection(void) | |||
157 | int linecnt = 0; | 158 | int linecnt = 0; |
158 | while (fgets(line, sizeof(line), fp) && linecnt < MAXSERVERS) { | 159 | while (fgets(line, sizeof(line), fp) && linecnt < MAXSERVERS) { |
159 | int len = strlen(line); | 160 | int len = strlen(line); |
160 | if (len > 74 && len < MAXLINE) | 161 | if (len > MINLINE && len < MAXLINE) |
161 | strcpy(servers[linecnt++], line); | 162 | strcpy(servers[linecnt++], line); |
162 | } | 163 | } |
163 | if (linecnt < 1) { | 164 | if (linecnt < 1) { |
@@ -166,17 +167,18 @@ int init_connection(void) | |||
166 | } | 167 | } |
167 | fclose(fp); | 168 | fclose(fp); |
168 | 169 | ||
169 | int servnum = rand() % linecnt; | 170 | char *server = servers[rand() % linecnt]; |
170 | char *server = servers[servnum]; | ||
171 | char *ip = strtok(server, " "); | 171 | char *ip = strtok(server, " "); |
172 | char *port = strtok(NULL, " "); | 172 | char *port = strtok(NULL, " "); |
173 | char *key = strtok(NULL, " "); | 173 | char *key = strtok(NULL, " "); |
174 | if (!ip || !port || !key) | ||
175 | return 3; | ||
174 | 176 | ||
175 | IP_Port dht; | 177 | IP_Port dht; |
176 | dht.port = htons(atoi(port)); | 178 | dht.port = htons(atoi(port)); |
177 | uint32_t resolved_address = resolve_addr(ip); | 179 | uint32_t resolved_address = resolve_addr(ip); |
178 | if (resolved_address == 0) | 180 | if (resolved_address == 0) |
179 | return 3; | 181 | return 4; |
180 | dht.ip.i = resolved_address; | 182 | dht.ip.i = resolved_address; |
181 | unsigned char *binary_string = hex_string_to_bin(key); | 183 | unsigned char *binary_string = hex_string_to_bin(key); |
182 | DHT_bootstrap(dht, binary_string); | 184 | DHT_bootstrap(dht, binary_string); |
@@ -432,7 +434,7 @@ int main(int argc, char *argv[]) | |||
432 | init_tox(); | 434 | init_tox(); |
433 | init_windows(); | 435 | init_windows(); |
434 | init_window_status(); | 436 | init_window_status(); |
435 | 437 | ||
436 | if(f_loadfromfile) | 438 | if(f_loadfromfile) |
437 | load_data(DATA_FILE); | 439 | load_data(DATA_FILE); |
438 | free(DATA_FILE); | 440 | free(DATA_FILE); |