From 497329aeab9778b57dfa8d424d2e6142d164c3bb Mon Sep 17 00:00:00 2001 From: Sebastian Stal Date: Sat, 20 Jul 2013 11:50:54 -0700 Subject: [PATCH 1/2] Make nTox resolve DNS addresses. --- testing/nTox.c | 32 +++++++++++++++++++++++++++++++- testing/nTox.h | 2 ++ 2 files changed, 33 insertions(+), 1 deletion(-) 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[]) return val; } +unsigned int resolve_dnsaddr(char *address, char *port) +{ + in_addr_t resolved = 0; + resolved = inet_addr(address); + if (resolved != -1) + { + return resolved; + } + + struct addrinfo hints; + memset(&hints, 0, sizeof(hints)); + hints.ai_family = AF_INET; + hints.ai_socktype = SOCK_STREAM; + struct addrinfo *server = NULL; + int success = getaddrinfo(address, port, &hints, &server); + if (success != 0) { + printf("failed to resolve %s: %s\n", address, gai_strerror(success)); + return -1; + } else { + resolved = ((struct sockaddr_in*)server->ai_addr)->sin_addr.s_addr; + freeaddrinfo(server); + return resolved; + } +} + void line_eval(char lines[HISTORY][STRING_LENGTH], char *line) { if (line[0] == '/') { @@ -245,7 +270,12 @@ int main(int argc, char *argv[]) strcpy(line, ""); IP_Port bootstrap_ip_port; bootstrap_ip_port.port = htons(atoi(argv[2])); - bootstrap_ip_port.ip.i = inet_addr(argv[1]); + unsigned int resolved_address = resolve_dnsaddr(argv[1], argv[2]); + if (resolved_address != -1) { + bootstrap_ip_port.ip.i = resolved_address; + } else { + exit(1); + } DHT_bootstrap(bootstrap_ip_port, hex_string_to_bin(argv[3])); nodelay(stdscr, TRUE); 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 @@ #include #include #include +#include +#include #include "../core/Messenger.h" #define STRING_LENGTH 256 #define HISTORY 50 From e0b6e7c8bb151f08e157c0151f8460946ecb82f0 Mon Sep 17 00:00:00 2001 From: Sebastian Stal Date: Sat, 20 Jul 2013 12:01:19 -0700 Subject: [PATCH 2/2] Fix sign on function --- testing/nTox.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/testing/nTox.c b/testing/nTox.c index b117dbae..5fdbfd21 100644 --- a/testing/nTox.c +++ b/testing/nTox.c @@ -35,7 +35,7 @@ unsigned char * hex_string_to_bin(char hex_string[]) return val; } -unsigned int resolve_dnsaddr(char *address, char *port) +int resolve_dnsaddr(char *address, char *port) { in_addr_t resolved = 0; resolved = inet_addr(address); @@ -270,7 +270,7 @@ int main(int argc, char *argv[]) strcpy(line, ""); IP_Port bootstrap_ip_port; bootstrap_ip_port.port = htons(atoi(argv[2])); - unsigned int resolved_address = resolve_dnsaddr(argv[1], argv[2]); + int resolved_address = resolve_dnsaddr(argv[1], argv[2]); if (resolved_address != -1) { bootstrap_ip_port.ip.i = resolved_address; } else {