MINOR: tcp/udp/unix: make use of proto->addrcmp() to compare addresses

The new addrcmp() protocol member points to the function to be used to
compare two addresses of the same family.

When picking an FD from a previous process, we can now use the address
specific address comparison functions instead of having to rely on a
local implementation. This will help move that code to a more central
place.
diff --git a/src/proto_tcp.c b/src/proto_tcp.c
index 5d1bc1e..17da403 100644
--- a/src/proto_tcp.c
+++ b/src/proto_tcp.c
@@ -40,6 +40,7 @@
 #include <haproxy/protocol.h>
 #include <haproxy/proxy-t.h>
 #include <haproxy/sock.h>
+#include <haproxy/sock_inet.h>
 #include <haproxy/tools.h>
 
 
@@ -67,6 +68,7 @@
 	.get_dst = tcp_get_dst,
 	.pause = tcp_pause_listener,
 	.add = tcpv4_add_listener,
+	.addrcmp = sock_inet4_addrcmp,
 	.listeners = LIST_HEAD_INIT(proto_tcpv4.listeners),
 	.nb_listeners = 0,
 };
@@ -92,6 +94,7 @@
 	.get_dst = tcp_get_dst,
 	.pause = tcp_pause_listener,
 	.add = tcpv6_add_listener,
+	.addrcmp = sock_inet6_addrcmp,
 	.listeners = LIST_HEAD_INIT(proto_tcpv6.listeners),
 	.nb_listeners = 0,
 };
@@ -610,35 +613,6 @@
 	}
 }
 
-/* XXX: Should probably be elsewhere */
-static int compare_sockaddr(struct sockaddr_storage *a, struct sockaddr_storage *b)
-{
-	if (a->ss_family != b->ss_family) {
-		return (-1);
-	}
-	switch (a->ss_family) {
-	case AF_INET:
-		{
-			struct sockaddr_in *a4 = (void *)a, *b4 = (void *)b;
-			if (a4->sin_port != b4->sin_port)
-				return (-1);
-			return (memcmp(&a4->sin_addr, &b4->sin_addr,
-			    sizeof(a4->sin_addr)));
-		}
-	case AF_INET6:
-		{
-			struct sockaddr_in6 *a6 = (void *)a, *b6 = (void *)b;
-			if (a6->sin6_port != b6->sin6_port)
-				return (-1);
-			return (memcmp(&a6->sin6_addr, &b6->sin6_addr,
-			    sizeof(a6->sin6_addr)));
-		}
-	default:
-		return (-1);
-	}
-
-}
-
 /* Returns true if the passed FD corresponds to a socket bound with LI_O_FOREIGN
  * according to the various supported socket options. The socket's address family
  * must be passed in <family>.
@@ -747,7 +721,7 @@
 	options &= ~LI_O_V4V6;
 
 	while (xfer_sock) {
-		if (!compare_sockaddr(&xfer_sock->addr, &l->addr)) {
+		if (!l->proto->addrcmp(&xfer_sock->addr, &l->addr)) {
 			if ((l->interface == NULL && xfer_sock->iface == NULL) ||
 			    (l->interface != NULL && xfer_sock->iface != NULL &&
 			     !strcmp(l->interface, xfer_sock->iface))) {