summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--testing/nTox.c64
1 files changed, 2 insertions, 62 deletions
diff --git a/testing/nTox.c b/testing/nTox.c
index 02b93d6f..bf12f5b2 100644
--- a/testing/nTox.c
+++ b/testing/nTox.c
@@ -175,74 +175,14 @@ int add_filesender(Tox *m, uint16_t friendnum, char *filename)
175 return filenum; 175 return filenum;
176} 176}
177 177
178/*
179 resolve_addr():
180 address should represent IPv4 or a hostname with A record
181
182 returns a data in network byte order that can be used to set IP.i or IP_Port.ip.i
183 returns 0 on failure
184
185 TODO: Fix ipv6 support
186*/
187
188uint32_t resolve_addr(const char *address)
189{
190 struct addrinfo *server = NULL;
191 struct addrinfo hints;
192 int rc;
193 uint32_t addr;
194
195 memset(&hints, 0, sizeof(hints));
196 hints.ai_family = AF_INET; // IPv4 only right now.
197 hints.ai_socktype = SOCK_DGRAM; // type of socket Tox uses.
198
199#ifdef __WIN32__
200 int res;
201 WSADATA wsa_data;
202
203 res = WSAStartup(MAKEWORD(2, 2), &wsa_data);
204
205 if (res != 0) {
206 return 0;
207 }
208
209#endif
210
211 rc = getaddrinfo(address, "echo", &hints, &server);
212 178
213 // Lookup failed.
214 if (rc != 0) {
215#ifdef __WIN32__
216 WSACleanup();
217#endif
218 return 0;
219 }
220
221 // IPv4 records only..
222 if (server->ai_family != AF_INET) {
223 freeaddrinfo(server);
224#ifdef __WIN32__
225 WSACleanup();
226#endif
227 return 0;
228 }
229
230
231 addr = ((struct sockaddr_in *)server->ai_addr)->sin_addr.s_addr;
232
233 freeaddrinfo(server);
234#ifdef __WIN32__
235 WSACleanup();
236#endif
237 return addr;
238}
239 179
240#define FRADDR_TOSTR_CHUNK_LEN 8 180#define FRADDR_TOSTR_CHUNK_LEN 8
241#define FRADDR_TOSTR_BUFSIZE (TOX_FRIEND_ADDRESS_SIZE * 2 + TOX_FRIEND_ADDRESS_SIZE / FRADDR_TOSTR_CHUNK_LEN + 1) 181#define FRADDR_TOSTR_BUFSIZE (TOX_FRIEND_ADDRESS_SIZE * 2 + TOX_FRIEND_ADDRESS_SIZE / FRADDR_TOSTR_CHUNK_LEN + 1)
242 182
243static void fraddr_to_str(uint8_t *id_bin, char *id_str) 183static void fraddr_to_str(uint8_t *id_bin, char *id_str)
244{ 184{
245 uint i, delta = 0, pos_extra, sum_extra = 0; 185 uint32_t i, delta = 0, pos_extra, sum_extra = 0;
246 186
247 for (i = 0; i < TOX_FRIEND_ADDRESS_SIZE; i++) { 187 for (i = 0; i < TOX_FRIEND_ADDRESS_SIZE; i++) {
248 sprintf(&id_str[2 * i + delta], "%02hhX", id_bin[i]); 188 sprintf(&id_str[2 * i + delta], "%02hhX", id_bin[i]);
@@ -320,7 +260,7 @@ void print_friendlist(Tox *m)
320 /* account for the longest name and the longest "base" string and number (int) and id_str */ 260 /* account for the longest name and the longest "base" string and number (int) and id_str */
321 char fstring[TOX_MAX_NAME_LENGTH + strlen(ptrn_friend) + 21 + id_str_len]; 261 char fstring[TOX_MAX_NAME_LENGTH + strlen(ptrn_friend) + 21 + id_str_len];
322 262
323 uint i = 0; 263 uint32_t i = 0;
324 264
325 while (getfriendname_terminated(m, i, name) != -1) { 265 while (getfriendname_terminated(m, i, name) != -1) {
326 if (!tox_get_client_id(m, i, fraddr_bin)) 266 if (!tox_get_client_id(m, i, fraddr_bin))