dovecot-2.0: liblib: Added net_ip_cmp().

dovecot at dovecot.org dovecot at dovecot.org
Sat Feb 20 17:17:28 EET 2010


details:   http://hg.dovecot.org/dovecot-2.0/rev/a4666cc8cb7b
changeset: 10789:a4666cc8cb7b
user:      Timo Sirainen <tss at iki.fi>
date:      Sat Feb 20 16:19:19 2010 +0200
description:
liblib: Added net_ip_cmp().

diffstat:

 src/lib/network.c |  15 +++++++++------
 src/lib/network.h |   4 +++-
 2 files changed, 12 insertions(+), 7 deletions(-)

diffs (45 lines):

diff -r 81537f59512a -r a4666cc8cb7b src/lib/network.c
--- a/src/lib/network.c	Sat Feb 20 16:19:00 2010 +0200
+++ b/src/lib/network.c	Sat Feb 20 16:19:19 2010 +0200
@@ -30,17 +30,20 @@
 
 bool net_ip_compare(const struct ip_addr *ip1, const struct ip_addr *ip2)
 {
+	return net_ip_cmp(ip1, ip2) == 0;
+}
+
+int net_ip_cmp(const struct ip_addr *ip1, const struct ip_addr *ip2)
+{
 	if (ip1->family != ip2->family)
-		return 0;
+		return ip1->family - ip2->family;
 
 #ifdef HAVE_IPV6
-	if (ip1->family == AF_INET6) {
-		return memcmp(&ip1->u.ip6, &ip2->u.ip6,
-			      sizeof(ip1->u.ip6)) == 0;
-	}
+	if (ip1->family == AF_INET6)
+		return memcmp(&ip1->u.ip6, &ip2->u.ip6, sizeof(ip1->u.ip6));
 #endif
 
-	return memcmp(&ip1->u.ip4, &ip2->u.ip4, sizeof(ip1->u.ip4)) == 0;
+	return memcmp(&ip1->u.ip4, &ip2->u.ip4, sizeof(ip1->u.ip4));
 }
 
 unsigned int net_ip_hash(const struct ip_addr *ip)
diff -r 81537f59512a -r a4666cc8cb7b src/lib/network.h
--- a/src/lib/network.h	Sat Feb 20 16:19:00 2010 +0200
+++ b/src/lib/network.h	Sat Feb 20 16:19:19 2010 +0200
@@ -40,8 +40,10 @@
 #define IPADDR_IS_V4(ip) ((ip)->family == AF_INET)
 #define IPADDR_IS_V6(ip) ((ip)->family == AF_INET6)
 
-/* returns 1 if IPADDRs are the same */
+/* Returns TRUE if IPs are the same */
 bool net_ip_compare(const struct ip_addr *ip1, const struct ip_addr *ip2);
+/* Returns 0 if IPs are the same, -1 or 1 otherwise. */
+int net_ip_cmp(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 */


More information about the dovecot-cvs mailing list