Mercurial > dovecot > core-2.2
changeset 7520:85203e817f90 HEAD
net_is_in_network(): Fixed to work with big endian machines.
author | Timo Sirainen <tss@iki.fi> |
---|---|
date | Thu, 15 May 2008 08:31:44 +0300 |
parents | 4ba3de34eaa4 |
children | cb1c6c942768 |
files | src/lib/network.c |
diffstat | 1 files changed, 7 insertions(+), 5 deletions(-) [+] |
line wrap: on
line diff
--- 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 @@ 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 @@ 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;