ctdb-protocol: Factor out static function ctdb_sock_addr_cmp_family()
authorMartin Schwenke <martin@meltin.net>
Wed, 13 Sep 2017 06:18:29 +0000 (16:18 +1000)
committerMartin Schwenke <martins@samba.org>
Tue, 19 Sep 2017 11:30:26 +0000 (13:30 +0200)
Signed-off-by: Martin Schwenke <martin@meltin.net>
Reviewed-by: Amitay Isaacs <amitay@gmail.com>
ctdb/protocol/protocol_util.c

index 3c8c21a472a6c5108b0d92b35d48a84a40be3158..b42cf47fbc33e96c2801f662d9955f2256ac3105 100644 (file)
@@ -328,11 +328,9 @@ void ctdb_sock_addr_set_port(ctdb_sock_addr *addr, unsigned int port)
        }
 }
 
-int ctdb_sock_addr_cmp_ip(const ctdb_sock_addr *addr1,
-                         const ctdb_sock_addr *addr2)
+static int ctdb_sock_addr_cmp_family(const ctdb_sock_addr *addr1,
+                                    const ctdb_sock_addr *addr2)
 {
-       int ret = 0;
-
        /* This is somewhat arbitrary.  However, when used for sorting
         * it just needs to be consistent.
         */
@@ -343,6 +341,19 @@ int ctdb_sock_addr_cmp_ip(const ctdb_sock_addr *addr1,
                return 1;
        }
 
+       return 0;
+}
+
+int ctdb_sock_addr_cmp_ip(const ctdb_sock_addr *addr1,
+                         const ctdb_sock_addr *addr2)
+{
+       int ret;
+
+       ret = ctdb_sock_addr_cmp_family(addr1, addr2);
+       if (ret != 0) {
+               return ret;
+       }
+
        switch (addr1->sa.sa_family) {
        case AF_INET:
                ret = memcmp(&addr1->ip.sin_addr.s_addr,