summaryrefslogtreecommitdiff
path: root/other/bootstrap_serverdaemon
diff options
context:
space:
mode:
authorirungentoo <irungentoo@gmail.com>2013-08-23 10:26:52 -0400
committerirungentoo <irungentoo@gmail.com>2013-08-23 10:26:52 -0400
commit9d3a8d94f21b584e199fbe04505cf0b259218ac8 (patch)
treea0ad9df07dec90fc929cc735bde5e57cc763b0e8 /other/bootstrap_serverdaemon
parentbcb87139a2d8c5b308cfb82635e9483e867c9dbc (diff)
New API done and tested.
Some stuff needs to be cleaned a bit though.
Diffstat (limited to 'other/bootstrap_serverdaemon')
-rw-r--r--other/bootstrap_serverdaemon/DHT_bootstrap_daemon.c41
1 files changed, 41 insertions, 0 deletions
diff --git a/other/bootstrap_serverdaemon/DHT_bootstrap_daemon.c b/other/bootstrap_serverdaemon/DHT_bootstrap_daemon.c
index 7604b1e0..46409b76 100644
--- a/other/bootstrap_serverdaemon/DHT_bootstrap_daemon.c
+++ b/other/bootstrap_serverdaemon/DHT_bootstrap_daemon.c
@@ -72,6 +72,47 @@ int b16_to_key(char b16_string[], uint8_t *bs_pubkey)
72 return 0; 72 return 0;
73} 73}
74 74
75/*
76 resolve_addr():
77 address should represent IPv4 or a hostname with A record
78
79 returns a data in network byte order that can be used to set IP.i or IP_Port.ip.i
80 returns 0 on failure
81
82 TODO: Fix ipv6 support
83*/
84
85uint32_t resolve_addr(const char *address)
86{
87 struct addrinfo *server = NULL;
88 struct addrinfo hints;
89 int rc;
90 uint32_t addr;
91
92 memset(&hints, 0, sizeof(hints));
93 hints.ai_family = AF_INET; // IPv4 only right now.
94 hints.ai_socktype = SOCK_DGRAM; // type of socket Tox uses.
95
96 rc = getaddrinfo(address, "echo", &hints, &server);
97
98 // Lookup failed.
99 if (rc != 0) {
100 return 0;
101 }
102
103 // IPv4 records only..
104 if (server->ai_family != AF_INET) {
105 freeaddrinfo(server);
106 return 0;
107 }
108
109
110 addr = ((struct sockaddr_in *)server->ai_addr)->sin_addr.s_addr;
111
112 freeaddrinfo(server);
113 return addr;
114}
115
75/* This unction connects to all specified servers 116/* This unction connects to all specified servers
76and connect to them. 117and connect to them.
77returns 1 if the connection to the DHT is up 118returns 1 if the connection to the DHT is up