From 96ae56bc199f60efac6de8c911c5fd9bd498cfd3 Mon Sep 17 00:00:00 2001 From: rswindell <> Date: Sat, 21 May 2016 02:21:40 +0000 Subject: [PATCH] Created inet_addrmatch() which returns TRUE if 2 xp_sockaddr's are the same address (family and address value, ignoring ports and other fields). --- src/xpdev/sockwrap.c | 17 ++++++++++++++++- src/xpdev/sockwrap.h | 3 ++- 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/src/xpdev/sockwrap.c b/src/xpdev/sockwrap.c index f1eedf23f7..84557df73a 100644 --- a/src/xpdev/sockwrap.c +++ b/src/xpdev/sockwrap.c @@ -8,7 +8,7 @@ * @format.tab-size 4 (Plain Text/Source Code File Header) * * @format.use-tabs true (see http://www.synchro.net/ptsc_hdr.html) * * * - * CopyrightRob Swindell - http://www.synchro.net/copyright.html * + * Copyright Rob Swindell - http://www.synchro.net/copyright.html * * * * This library is free software; you can redistribute it and/or * * modify it under the terms of the GNU Lesser General Public License * @@ -481,3 +481,18 @@ void DLLCALL inet_setaddrport(union xp_sockaddr *addr, uint16_t port) break; } } + +/* Return TRUE if the 2 addresses are the same host (type and address) */ +BOOL DLLCALL inet_addrmatch(union xp_sockaddr* addr1, union xp_sockaddr* addr2) +{ + if(addr1->addr.sa_family != addr2->addr.sa_family) + return FALSE; + + switch(addr1->addr.sa_family) { + case AF_INET: + return memcmp(&addr1->in.sin_addr, &addr2->in.sin_addr, sizeof(addr1->in.sin_addr)) == 0; + case AF_INET6: + return memcmp(&addr1->in6.sin6_addr, &addr2->in6.sin6_addr, sizeof(addr1->in6.sin6_addr)) == 0; + } + return FALSE; +} diff --git a/src/xpdev/sockwrap.h b/src/xpdev/sockwrap.h index f3d67afde6..33163525b3 100644 --- a/src/xpdev/sockwrap.h +++ b/src/xpdev/sockwrap.h @@ -8,7 +8,7 @@ * @format.tab-size 4 (Plain Text/Source Code File Header) * * @format.use-tabs true (see http://www.synchro.net/ptsc_hdr.html) * * * - * Copyright 2010 Rob Swindell - http://www.synchro.net/copyright.html * + * Copyright Rob Swindell - http://www.synchro.net/copyright.html * * * * This library is free software; you can redistribute it and/or * * modify it under the terms of the GNU Lesser General Public License * @@ -233,6 +233,7 @@ DLLEXPORT union xp_sockaddr* DLLCALL inet_ptoaddr(char *addr_str, union xp_socka DLLEXPORT const char* DLLCALL inet_addrtop(union xp_sockaddr *addr, char *dest, size_t size); DLLEXPORT uint16_t DLLCALL inet_addrport(union xp_sockaddr *addr); DLLEXPORT void DLLCALL inet_setaddrport(union xp_sockaddr *addr, uint16_t port); +DLLEXPORT BOOL DLLCALL inet_addrmatch(union xp_sockaddr* addr1, union xp_sockaddr* addr2); #ifdef __cplusplus } -- GitLab