summaryrefslogtreecommitdiff
path: root/toxcore/network.c
diff options
context:
space:
mode:
Diffstat (limited to 'toxcore/network.c')
-rw-r--r--toxcore/network.c37
1 files changed, 37 insertions, 0 deletions
diff --git a/toxcore/network.c b/toxcore/network.c
index 31da833c..1fb5b77a 100644
--- a/toxcore/network.c
+++ b/toxcore/network.c
@@ -235,6 +235,43 @@ void kill_networking(Networking_Core *net)
235 return; 235 return;
236} 236}
237 237
238/* ip_equal
239 * compares two IPAny structures
240 * unset means unequal
241 *
242 * returns 0 when not equal or when uninitialized
243 */
244int ip_equal(IPAny *a, IPAny *b)
245{
246 if (!a || !b)
247 return 0;
248
249 if (a->family == AF_INET)
250 return (a->ip4.in_addr.s_addr == b->ip4.in_addr.s_addr);
251
252 if (a->family == AF_INET6)
253 return IN6_ARE_ADDR_EQUAL(&a->ip6, &b->ip6);
254
255 return 0;
256};
257
258/* ipport_equal
259 * compares two IPAny_Port structures
260 * unset means unequal
261 *
262 * returns 0 when not equal or when uninitialized
263 */
264int ipport_equal(IPAny_Port *a, IPAny_Port *b)
265{
266 if (!a || !b)
267 return 0;
268
269 if (!a->port || (a->port != b->port))
270 return 0;
271
272 return ip_equal(&a->ip, &b->ip);
273};
274
238/* ipany_ntoa 275/* ipany_ntoa
239 * converts ip into a string 276 * converts ip into a string
240 * uses a static buffer, so mustn't used multiple times in the same output 277 * uses a static buffer, so mustn't used multiple times in the same output