1
0
mirror of https://github.com/samba-team/samba.git synced 2024-12-22 13:34:15 +03:00

lib/socket: rearrange iface_comp() to use NUMERIC_CMP

We rearrange rather than just replacing the subtraction, because that
would call ntohl() more than necessary, and I think the flow is a bit
clearer this way.

BUG: https://bugzilla.samba.org/show_bug.cgi?id=15625

Signed-off-by: Douglas Bagnall <douglas.bagnall@catalyst.net.nz>
Reviewed-by: Andrew Bartlett <abartlet@samba.org>
(cherry picked from commit 7ba6fcb936)
This commit is contained in:
Douglas Bagnall 2024-04-08 17:06:57 +12:00 committed by Jule Anger
parent 1d527c49df
commit de865f6c8b

View File

@ -386,18 +386,18 @@ static int iface_comp(struct iface_struct *i1, struct iface_struct *i2)
if (((struct sockaddr *)&i1->ip)->sa_family == AF_INET) {
struct sockaddr_in *s1 = (struct sockaddr_in *)&i1->ip;
struct sockaddr_in *s2 = (struct sockaddr_in *)&i2->ip;
r = ntohl(s1->sin_addr.s_addr) -
ntohl(s2->sin_addr.s_addr);
if (r) {
return r;
uint32_t a1 = ntohl(s1->sin_addr.s_addr);
uint32_t a2 = ntohl(s2->sin_addr.s_addr);
r = NUMERIC_CMP(a1, a2);
if (r == 0) {
/* compare netmasks as a tiebreaker */
s1 = (struct sockaddr_in *)&i1->netmask;
s2 = (struct sockaddr_in *)&i2->netmask;
a1 = ntohl(s1->sin_addr.s_addr);
a2 = ntohl(s2->sin_addr.s_addr);
r = NUMERIC_CMP(a1, a2);
}
s1 = (struct sockaddr_in *)&i1->netmask;
s2 = (struct sockaddr_in *)&i2->netmask;
return ntohl(s1->sin_addr.s_addr) -
ntohl(s2->sin_addr.s_addr);
return r;
}
return 0;
}