Commit 9c8a905c authored by jehan's avatar jehan

add function to compare sockaddr

parent 61c9bc68
......@@ -382,6 +382,8 @@ BCTBX_PUBLIC struct addrinfo * bctbx_ip_address_to_addrinfo(int family, int sock
**/
BCTBX_PUBLIC struct addrinfo * bctbx_name_to_addrinfo(int family, int socktype, const char *name, int port);
/*return TRUE if both families, ports and addresses are equals*/
BCTBX_PUBLIC bool_t bctbx_sockaddr_equals(const struct sockaddr * sa, const struct sockaddr * sb) ;
/* portable named pipes and shared memory*/
#if !defined(_WIN32_WCE)
......
......@@ -1191,3 +1191,28 @@ char * bctbx_concat (const char *str, ...) {
return result;
}
/*
return true if both, family, port and addr are equals
*/
bool_t bctbx_sockaddr_equals(const struct sockaddr * sa, const struct sockaddr * sb) {
if (sa->sa_family != sb->sa_family)
return FALSE;
if (sa->sa_family == AF_INET) {
if ((((struct sockaddr_in*)sa)->sin_addr.s_addr != ((struct sockaddr_in*)sb)->sin_addr.s_addr
|| ((struct sockaddr_in*)sa)->sin_port != ((struct sockaddr_in*)sb)->sin_port))
return FALSE;
} else if (sa->sa_family == AF_INET6) {
if (memcmp(&((struct sockaddr_in6*)sa)->sin6_addr
, &((struct sockaddr_in6*)sb)->sin6_addr
, sizeof(struct in6_addr)) !=0
|| ((struct sockaddr_in6*)sa)->sin6_port != ((struct sockaddr_in6*)sb)->sin6_port)
return FALSE;
} else {
bctbx_warning ("Cannot compare family type [%d]", sa->sa_family);
return FALSE;
}
return TRUE;
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment