summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--testing/nTox.c32
-rw-r--r--testing/nTox.h2
2 files changed, 33 insertions, 1 deletions
diff --git a/testing/nTox.c b/testing/nTox.c
index 83fe9e34..b117dbae 100644
--- a/testing/nTox.c
+++ b/testing/nTox.c
@@ -35,6 +35,31 @@ unsigned char * hex_string_to_bin(char hex_string[])
35 return val; 35 return val;
36} 36}
37 37
38unsigned int resolve_dnsaddr(char *address, char *port)
39{
40 in_addr_t resolved = 0;
41 resolved = inet_addr(address);
42 if (resolved != -1)
43 {
44 return resolved;
45 }
46
47 struct addrinfo hints;
48 memset(&hints, 0, sizeof(hints));
49 hints.ai_family = AF_INET;
50 hints.ai_socktype = SOCK_STREAM;
51 struct addrinfo *server = NULL;
52 int success = getaddrinfo(address, port, &hints, &server);
53 if (success != 0) {
54 printf("failed to resolve %s: %s\n", address, gai_strerror(success));
55 return -1;
56 } else {
57 resolved = ((struct sockaddr_in*)server->ai_addr)->sin_addr.s_addr;
58 freeaddrinfo(server);
59 return resolved;
60 }
61}
62
38void line_eval(char lines[HISTORY][STRING_LENGTH], char *line) 63void line_eval(char lines[HISTORY][STRING_LENGTH], char *line)
39{ 64{
40 if (line[0] == '/') { 65 if (line[0] == '/') {
@@ -245,7 +270,12 @@ int main(int argc, char *argv[])
245 strcpy(line, ""); 270 strcpy(line, "");
246 IP_Port bootstrap_ip_port; 271 IP_Port bootstrap_ip_port;
247 bootstrap_ip_port.port = htons(atoi(argv[2])); 272 bootstrap_ip_port.port = htons(atoi(argv[2]));
248 bootstrap_ip_port.ip.i = inet_addr(argv[1]); 273 unsigned int resolved_address = resolve_dnsaddr(argv[1], argv[2]);
274 if (resolved_address != -1) {
275 bootstrap_ip_port.ip.i = resolved_address;
276 } else {
277 exit(1);
278 }
249 DHT_bootstrap(bootstrap_ip_port, hex_string_to_bin(argv[3])); 279 DHT_bootstrap(bootstrap_ip_port, hex_string_to_bin(argv[3]));
250 nodelay(stdscr, TRUE); 280 nodelay(stdscr, TRUE);
251 while(true) { 281 while(true) {
diff --git a/testing/nTox.h b/testing/nTox.h
index 432e0274..8f8a07d0 100644
--- a/testing/nTox.h
+++ b/testing/nTox.h
@@ -10,6 +10,8 @@
10#include <sys/socket.h> 10#include <sys/socket.h>
11#include <netinet/in.h> 11#include <netinet/in.h>
12#include <arpa/inet.h> 12#include <arpa/inet.h>
13#include <sys/types.h>
14#include <netdb.h>
13#include "../core/Messenger.h" 15#include "../core/Messenger.h"
14#define STRING_LENGTH 256 16#define STRING_LENGTH 256
15#define HISTORY 50 17#define HISTORY 50