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>
This commit is contained in:
parent
acaa1323d0
commit
7ba6fcb936
@ -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) {
|
if (((struct sockaddr *)&i1->ip)->sa_family == AF_INET) {
|
||||||
struct sockaddr_in *s1 = (struct sockaddr_in *)&i1->ip;
|
struct sockaddr_in *s1 = (struct sockaddr_in *)&i1->ip;
|
||||||
struct sockaddr_in *s2 = (struct sockaddr_in *)&i2->ip;
|
struct sockaddr_in *s2 = (struct sockaddr_in *)&i2->ip;
|
||||||
|
uint32_t a1 = ntohl(s1->sin_addr.s_addr);
|
||||||
r = ntohl(s1->sin_addr.s_addr) -
|
uint32_t a2 = ntohl(s2->sin_addr.s_addr);
|
||||||
ntohl(s2->sin_addr.s_addr);
|
r = NUMERIC_CMP(a1, a2);
|
||||||
if (r) {
|
if (r == 0) {
|
||||||
return r;
|
/* 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);
|
||||||
}
|
}
|
||||||
|
return r;
|
||||||
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 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user