diff options
author | Sebastian Stal <stal@pyboard.net> | 2013-07-20 11:50:54 -0700 |
---|---|---|
committer | Sebastian Stal <stal@pyboard.net> | 2013-07-20 11:50:54 -0700 |
commit | 497329aeab9778b57dfa8d424d2e6142d164c3bb (patch) | |
tree | f897e84d336abd1259c30eeaf0bbebdc83a05da0 /testing | |
parent | ae8814ce69d4b4e9696f204c6e8d2b937a0ec4f6 (diff) |
Make nTox resolve DNS addresses.
Diffstat (limited to 'testing')
-rw-r--r-- | testing/nTox.c | 32 | ||||
-rw-r--r-- | testing/nTox.h | 2 |
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 | ||
38 | unsigned 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 | |||
38 | void line_eval(char lines[HISTORY][STRING_LENGTH], char *line) | 63 | void 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 |