summaryrefslogtreecommitdiff
path: root/core/network.c
diff options
context:
space:
mode:
Diffstat (limited to 'core/network.c')
-rw-r--r--core/network.c43
1 files changed, 2 insertions, 41 deletions
diff --git a/core/network.c b/core/network.c
index 7880eae6..2bcf7d61 100644
--- a/core/network.c
+++ b/core/network.c
@@ -144,8 +144,9 @@ static void at_shutdown(void)
144 returns NULL if there are problems */ 144 returns NULL if there are problems */
145Networking_Core *new_networking(IP ip, uint16_t port) 145Networking_Core *new_networking(IP ip, uint16_t port)
146{ 146{
147 if(at_startup() != 0) 147 if (at_startup() != 0)
148 return NULL; 148 return NULL;
149
149 /* initialize our socket */ 150 /* initialize our socket */
150 Networking_Core *temp = calloc(1, sizeof(Networking_Core)); 151 Networking_Core *temp = calloc(1, sizeof(Networking_Core));
151 152
@@ -215,43 +216,3 @@ void kill_networking(Networking_Core *net)
215 free(net); 216 free(net);
216 return; 217 return;
217} 218}
218
219/*
220 resolve_addr():
221 address should represent IPv4 or a hostname with A record
222
223 returns a data in network byte order that can be used to set IP.i or IP_Port.ip.i
224 returns 0 on failure
225
226 TODO: Fix ipv6 support
227*/
228uint32_t resolve_addr(const char *address)
229{
230 struct addrinfo *server = NULL;
231 struct addrinfo hints;
232 int rc;
233 uint32_t addr;
234
235 memset(&hints, 0, sizeof(hints));
236 hints.ai_family = AF_INET; // IPv4 only right now.
237 hints.ai_socktype = SOCK_DGRAM; // type of socket Tox uses.
238
239 rc = getaddrinfo(address, "echo", &hints, &server);
240
241 // Lookup failed.
242 if (rc != 0) {
243 return 0;
244 }
245
246 // IPv4 records only..
247 if (server->ai_family != AF_INET) {
248 freeaddrinfo(server);
249 return 0;
250 }
251
252
253 addr = ((struct sockaddr_in *)server->ai_addr)->sin_addr.s_addr;
254
255 freeaddrinfo(server);
256 return addr;
257}