diff options
Diffstat (limited to 'toxcore/network.c')
-rw-r--r-- | toxcore/network.c | 45 |
1 files changed, 22 insertions, 23 deletions
diff --git a/toxcore/network.c b/toxcore/network.c index 151986d9..aeaf4d79 100644 --- a/toxcore/network.c +++ b/toxcore/network.c | |||
@@ -166,6 +166,28 @@ static int make_socktype(int type); | |||
166 | static int make_family(int tox_family); | 166 | static int make_family(int tox_family); |
167 | static int make_tox_family(int family); | 167 | static int make_tox_family(int family); |
168 | 168 | ||
169 | static void get_ip4(IP4 *result, const struct in_addr *addr) | ||
170 | { | ||
171 | result->uint32 = addr->s_addr; | ||
172 | } | ||
173 | |||
174 | static void get_ip6(IP6 *result, const struct in6_addr *addr) | ||
175 | { | ||
176 | assert(sizeof(result->uint8) == sizeof(addr->s6_addr)); | ||
177 | memcpy(result->uint8, addr->s6_addr, sizeof(result->uint8)); | ||
178 | } | ||
179 | |||
180 | static void fill_addr4(IP4 ip, struct in_addr *addr) | ||
181 | { | ||
182 | addr->s_addr = ip.uint32; | ||
183 | } | ||
184 | |||
185 | static void fill_addr6(IP6 ip, struct in6_addr *addr) | ||
186 | { | ||
187 | assert(sizeof(ip.uint8) == sizeof(addr->s6_addr)); | ||
188 | memcpy(addr->s6_addr, ip.uint8, sizeof(ip.uint8)); | ||
189 | } | ||
190 | |||
169 | /* Check if socket is valid. | 191 | /* Check if socket is valid. |
170 | * | 192 | * |
171 | * return 1 if valid | 193 | * return 1 if valid |
@@ -358,29 +380,6 @@ static void loglogdata(Logger *log, const char *message, const uint8_t *buffer, | |||
358 | } | 380 | } |
359 | } | 381 | } |
360 | 382 | ||
361 | void get_ip4(IP4 *result, const struct in_addr *addr) | ||
362 | { | ||
363 | result->uint32 = addr->s_addr; | ||
364 | } | ||
365 | |||
366 | void get_ip6(IP6 *result, const struct in6_addr *addr) | ||
367 | { | ||
368 | assert(sizeof(result->uint8) == sizeof(addr->s6_addr)); | ||
369 | memcpy(result->uint8, addr->s6_addr, sizeof(result->uint8)); | ||
370 | } | ||
371 | |||
372 | |||
373 | void fill_addr4(IP4 ip, struct in_addr *addr) | ||
374 | { | ||
375 | addr->s_addr = ip.uint32; | ||
376 | } | ||
377 | |||
378 | void fill_addr6(IP6 ip, struct in6_addr *addr) | ||
379 | { | ||
380 | assert(sizeof(ip.uint8) == sizeof(addr->s6_addr)); | ||
381 | memcpy(addr->s6_addr, ip.uint8, sizeof(ip.uint8)); | ||
382 | } | ||
383 | |||
384 | /* Basic network functions: | 383 | /* Basic network functions: |
385 | * Function to send packet(data) of length length to ip_port. | 384 | * Function to send packet(data) of length length to ip_port. |
386 | */ | 385 | */ |