mirror of
https://github.com/samba-team/samba.git
synced 2025-01-22 22:04:08 +03:00
ctdb-protocol: Add function to compare ctdb_sock_addr
Signed-off-by: Amitay Isaacs <amitay@gmail.com> Reviewed-by: Martin Schwenke <martin@meltin.net>
This commit is contained in:
parent
ad0286c744
commit
e35ffb06bc
@ -687,5 +687,6 @@ const char *ctdb_event_to_string(enum ctdb_event event);
|
||||
enum ctdb_event ctdb_event_from_string(const char *event_str);
|
||||
|
||||
const char *ctdb_sock_addr_to_string(TALLOC_CTX *mem_ctx, ctdb_sock_addr *addr);
|
||||
bool ctdb_sock_addr_same(ctdb_sock_addr *addr1, ctdb_sock_addr *addr2);
|
||||
|
||||
#endif /* __CTDB_PROTOCOL_API_H__ */
|
||||
|
@ -140,3 +140,36 @@ const char *ctdb_sock_addr_to_string(TALLOC_CTX *mem_ctx, ctdb_sock_addr *addr)
|
||||
|
||||
return cip;
|
||||
}
|
||||
|
||||
bool ctdb_sock_addr_same(ctdb_sock_addr *addr1, ctdb_sock_addr *addr2)
|
||||
{
|
||||
if (addr1->sa.sa_family != addr2->sa.sa_family) {
|
||||
return false;
|
||||
}
|
||||
|
||||
switch (addr1->sa.sa_family) {
|
||||
case AF_INET:
|
||||
if (addr1->ip.sin_addr.s_addr != addr2->ip.sin_addr.s_addr) {
|
||||
return false;
|
||||
}
|
||||
if (addr1->ip.sin_port != addr2->ip.sin_port) {
|
||||
return false;
|
||||
}
|
||||
break;
|
||||
|
||||
case AF_INET6:
|
||||
if (memcmp(addr1->ip6.sin6_addr.s6_addr,
|
||||
addr2->ip6.sin6_addr.s6_addr, 16) != 0) {
|
||||
return false;
|
||||
}
|
||||
if (addr1->ip6.sin6_port != addr2->ip6.sin6_port) {
|
||||
return false;
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user