diff options
Diffstat (limited to 'src/shared/socket-util.c')
-rw-r--r-- | src/shared/socket-util.c | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/src/shared/socket-util.c b/src/shared/socket-util.c index 0a0726d87d..1a04f323ab 100644 --- a/src/shared/socket-util.c +++ b/src/shared/socket-util.c @@ -711,3 +711,19 @@ static const char* const socket_address_bind_ipv6_only_table[_SOCKET_ADDRESS_BIN }; DEFINE_STRING_TABLE_LOOKUP(socket_address_bind_ipv6_only, SocketAddressBindIPv6Only); + +bool sockaddr_equal(const union sockaddr_union *a, const union sockaddr_union *b) { + assert(a); + assert(b); + + if (a->sa.sa_family != b->sa.sa_family) + return false; + + if (a->sa.sa_family == AF_INET) + return a->in.sin_addr.s_addr == b->in.sin_addr.s_addr; + + if (a->sa.sa_family == AF_INET6) + return memcmp(&a->in6.sin6_addr, &b->in6.sin6_addr, sizeof(a->in6.sin6_addr)) == 0; + + return false; +} |