Use the protocol name of a socket as a hint for peer address resolution

To resolve the peer address of socket, all combinations of families
(AF_INET, AF_INET6) and protocols(IPPROTO_TCP, IPPROTO_UDP) were tried.
This change utilizes the protocol name obtained via getxattr to specify
the right combination.

* socketutils.c (inet_print): New helper function.
(print_sockaddr_by_inode): Use it.  Utilize the protocol name
associated with the given inode for resolving the peer socket
address.  If the protocol name is NULL, resolve the address
by trying combinations of families and protocols as before.
* defs.h (print_sockaddr_by_inode): Update prototype.
* util.c (printfd): Pass the protocol name associated with
the given path to print_sockaddr_by_inode as the 2nd argument.

Signed-off-by: Masatake YAMATO <yamato@redhat.com>
Signed-off-by: Dmitry V. Levin <ldv@altlinux.org>
diff --git a/util.c b/util.c
index fb5476f..b7476cf 100644
--- a/util.c
+++ b/util.c
@@ -482,14 +482,13 @@
 		    strncmp(path, socket_prefix, socket_prefix_len) == 0 &&
 		    path[(path_len = strlen(path)) - 1] == ']') {
 			unsigned long inodenr;
+#define PROTO_NAME_LEN 32
+			char proto_buf[PROTO_NAME_LEN];
+			const char *proto =
+				getfdproto(tcp, fd, proto_buf, PROTO_NAME_LEN);
 			inodenr = strtoul(path + socket_prefix_len, NULL, 10);
 			tprintf("%d<", fd);
-			if (!print_sockaddr_by_inode(inodenr)) {
-#define PROTO_NAME_LEN 32
-				char proto_buf[PROTO_NAME_LEN];
-				const char *proto =
-					getfdproto(tcp, fd, proto_buf, PROTO_NAME_LEN);
-
+			if (!print_sockaddr_by_inode(inodenr, proto)) {
 				if (proto)
 					tprintf("%s:[%lu]", proto, inodenr);
 				else