Skip to content
Snippets Groups Projects
Commit 96ae56bc authored by rswindell's avatar rswindell
Browse files

Created inet_addrmatch() which returns TRUE if 2 xp_sockaddr's are the same

address (family and address value, ignoring ports and other fields).
parent ee159c40
No related branches found
No related tags found
No related merge requests found
......@@ -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;
}
......@@ -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
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment