mirror of
https://gitlab.isc.org/isc-projects/bind9
synced 2025-08-31 14:35:26 +00:00
Added isc_sockaddr_eqaddr and its protoype: compares only the addresses
(and not the port values) of two isc_sockaddr_t.
This commit is contained in:
@@ -37,6 +37,9 @@ typedef struct isc_sockaddr {
|
||||
isc_boolean_t
|
||||
isc_sockaddr_equal(isc_sockaddr_t *a, isc_sockaddr_t *b);
|
||||
|
||||
isc_boolean_t
|
||||
isc_sockaddr_eqaddr(isc_sockaddr_t *a, isc_sockaddr_t *b);
|
||||
|
||||
unsigned int
|
||||
isc_sockaddr_hash(isc_sockaddr_t *sockaddr, isc_boolean_t address_only);
|
||||
|
||||
|
@@ -65,6 +65,43 @@ isc_sockaddr_equal(isc_sockaddr_t *a, isc_sockaddr_t *b)
|
||||
return (ISC_TRUE);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* compare just the addresses (ignore ports)
|
||||
*/
|
||||
isc_boolean_t
|
||||
isc_sockaddr_eqaddr(isc_sockaddr_t *a, isc_sockaddr_t *b)
|
||||
{
|
||||
REQUIRE(a != NULL && b != NULL);
|
||||
|
||||
if (a->length != b->length)
|
||||
return (ISC_FALSE);
|
||||
|
||||
/*
|
||||
* We don't just memcmp because the sin_zero field isn't always
|
||||
* zero.
|
||||
*/
|
||||
|
||||
if (a->type.sa.sa_family != b->type.sa.sa_family)
|
||||
return (ISC_FALSE);
|
||||
switch (a->type.sa.sa_family) {
|
||||
case AF_INET:
|
||||
if (memcmp(&a->type.sin.sin_addr, &b->type.sin.sin_addr,
|
||||
sizeof a->type.sin.sin_addr) != 0)
|
||||
return (ISC_FALSE);
|
||||
break;
|
||||
case AF_INET6:
|
||||
if (memcmp(&a->type.sin6.sin6_addr, &b->type.sin6.sin6_addr,
|
||||
sizeof a->type.sin6.sin6_addr) != 0)
|
||||
return (ISC_FALSE);
|
||||
break;
|
||||
default:
|
||||
if (memcmp(&a->type, &b->type, a->length) != 0)
|
||||
return (ISC_FALSE);
|
||||
}
|
||||
return (ISC_TRUE);
|
||||
}
|
||||
|
||||
char *
|
||||
isc_sockaddr_totext(isc_sockaddr_t *sockaddr, isc_mem_t *mctx) {
|
||||
char abuf[sizeof "xxxx:xxxx:xxxx:xxxx:xxxx:xxxx:255.255.255.255"];
|
||||
|
Reference in New Issue
Block a user