]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
liblib: Added net_ip_cmp().
authorTimo Sirainen <tss@iki.fi>
Sat, 20 Feb 2010 14:19:19 +0000 (16:19 +0200)
committerTimo Sirainen <tss@iki.fi>
Sat, 20 Feb 2010 14:19:19 +0000 (16:19 +0200)
--HG--
branch : HEAD

src/lib/network.c
src/lib/network.h

index 9faf3a42386dfd4a884fde4b669dddcfbe449675..adf9d55751f08e7693f8ac786b9b21be42026ff1 100644 (file)
@@ -29,18 +29,21 @@ union sockaddr_union {
 #endif
 
 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)
index 4cb6abdecdf51bb4b2884a0300197a3bc831ab32..45f8e89310124489b33433ce2f36b4a862c0e2a2 100644 (file)
@@ -40,8 +40,10 @@ struct ip_addr {
 #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 */