summaryrefslogtreecommitdiff
path: root/testing/nTox.c
diff options
context:
space:
mode:
authorSebastian Stal <stal@pyboard.net>2013-07-20 11:50:54 -0700
committerSebastian Stal <stal@pyboard.net>2013-07-20 11:50:54 -0700
commit497329aeab9778b57dfa8d424d2e6142d164c3bb (patch)
treef897e84d336abd1259c30eeaf0bbebdc83a05da0 /testing/nTox.c
parentae8814ce69d4b4e9696f204c6e8d2b937a0ec4f6 (diff)
Make nTox resolve DNS addresses.
Diffstat (limited to 'testing/nTox.c')
-rw-r--r--testing/nTox.c32
1 files changed, 31 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) {