diff options
author | irungentoo <irungentoo@gmail.com> | 2013-08-23 15:45:34 -0400 |
---|---|---|
committer | irungentoo <irungentoo@gmail.com> | 2013-08-23 15:45:34 -0400 |
commit | f8f550e2f0604fd4491c9ff01f9843573a5a9b43 (patch) | |
tree | 533c91f47d10a5bfde3b1e4eb4de4eddee0c4189 /other/bootstrap_serverdaemon | |
parent | 05f3ae17346d7bcdd799346cab696d52bafe3a3a (diff) | |
parent | a71361d8905f10d0dc8325f060134d135b486f60 (diff) |
Merge branch 'new-api'
New, cleaner public API added. see: core/tox.h
This does not break anything because the old API is still there.
You are however encouraged to switch to the new API.
Diffstat (limited to 'other/bootstrap_serverdaemon')
-rw-r--r-- | other/bootstrap_serverdaemon/DHT_bootstrap_daemon.c | 41 |
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 | |||
85 | uint32_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 |
76 | and connect to them. | 117 | and connect to them. |
77 | returns 1 if the connection to the DHT is up | 118 | returns 1 if the connection to the DHT is up |