dovecot: Added net_ip_hash().
dovecot at dovecot.org
dovecot at dovecot.org
Mon Jul 2 23:11:52 EEST 2007
details: http://hg.dovecot.org/dovecot/rev/22b300677807
changeset: 5865:22b300677807
user: Timo Sirainen <tss at iki.fi>
date: Mon Jul 02 23:11:46 2007 +0300
description:
Added net_ip_hash().
diffstat:
2 files changed, 23 insertions(+)
src/lib/network.c | 22 ++++++++++++++++++++++
src/lib/network.h | 1 +
diffs (43 lines):
diff -r c554a52f1b3d -r 22b300677807 src/lib/network.c
--- a/src/lib/network.c Mon Jul 02 22:48:01 2007 +0300
+++ b/src/lib/network.c Mon Jul 02 23:11:46 2007 +0300
@@ -39,6 +39,28 @@ bool net_ip_compare(const struct ip_addr
return memcmp(&ip1->ip, &ip2->ip, 4) == 0;
}
+unsigned int net_ip_hash(const struct ip_addr *ip)
+{
+ const unsigned char *p = (const unsigned char *)&ip->ip;
+ unsigned int len, g, h = 0;
+
+#ifdef HAVE_IPV6
+ if (ip->family == AF_INET6)
+ len = sizeof(ip->ip);
+ else
+#endif
+ len = 4;
+
+ for (; len > 0; len--, p++) {
+ h = (h << 4) + *p;
+ if ((g = h & 0xf0000000UL)) {
+ h = h ^ (g >> 24);
+ h = h ^ g;
+ }
+ }
+
+ return h;
+}
/* copy IP to sockaddr */
static inline void
diff -r c554a52f1b3d -r 22b300677807 src/lib/network.h
--- a/src/lib/network.h Mon Jul 02 22:48:01 2007 +0300
+++ b/src/lib/network.h Mon Jul 02 23:11:46 2007 +0300
@@ -41,6 +41,7 @@ struct ip_addr {
/* returns 1 if IPADDRs are the same */
bool net_ip_compare(const struct ip_addr *ip1, const struct ip_addr *ip2);
+unsigned int net_ip_hash(const struct ip_addr *ip);
/* Connect to socket with ip address */
int net_connect_ip(const struct ip_addr *ip, unsigned int port,
More information about the dovecot-cvs
mailing list