dovecot-1.1: net_is_in_network(): Fixed to work with big endian ...
dovecot at dovecot.org
dovecot at dovecot.org
Thu May 15 08:31:48 EEST 2008
details: http://hg.dovecot.org/dovecot-1.1/rev/85203e817f90
changeset: 7520:85203e817f90
user: Timo Sirainen <tss at iki.fi>
date: Thu May 15 08:31:44 2008 +0300
description:
net_is_in_network(): Fixed to work with big endian machines.
diffstat:
1 file changed, 7 insertions(+), 5 deletions(-)
src/lib/network.c | 12 +++++++-----
diffs (36 lines):
diff -r 4ba3de34eaa4 -r 85203e817f90 src/lib/network.c
--- a/src/lib/network.c Thu May 15 08:31:20 2008 +0300
+++ b/src/lib/network.c Thu May 15 08:31:44 2008 +0300
@@ -708,7 +708,7 @@ bool net_is_in_network(const struct ip_a
const struct ip_addr *net_ip, unsigned int bits)
{
const uint32_t *ip1, *ip2;
- uint32_t mask;
+ uint32_t mask, i1, i2;
unsigned int pos, i;
if (IPADDR_IS_V4(ip) != IPADDR_IS_V4(net_ip)) {
@@ -735,17 +735,19 @@ bool net_is_in_network(const struct ip_a
if (ip1[i] != ip2[i])
return FALSE;
}
+ i1 = htonl(ip1[i]);
+ i2 = htonl(ip2[i]);
/* check the last full bytes */
- for (mask = 0xff; pos + 8 <= bits; pos += 8, mask <<= 8) {
- if ((ip1[i] & mask) != (ip2[i] & mask))
+ for (mask = 0xff000000; pos + 8 <= bits; pos += 8, mask >>= 8) {
+ if ((i1 & mask) != (i2 & mask))
return FALSE;
}
/* check the last bits, they're reversed in bytes */
bits -= pos;
- for (mask = 0x80 << (pos % 32); bits > 0; bits--, mask >>= 1) {
- if ((ip1[i] & mask) != (ip2[i] & mask))
+ for (mask = 0x80000000 >> (pos % 32); bits > 0; bits--, mask >>= 1) {
+ if ((i1 & mask) != (i2 & mask))
return FALSE;
}
return TRUE;
More information about the dovecot-cvs
mailing list