DORMANTno replies

[PATCH iproute2] ipaddress: Use family_name() for better code reuse

From: Serhey Popovych <hidden>
Date: 2018-01-12 18:03:45
Subsystem: the rest · Maintainer: Linus Torvalds

Signed-off-by: Serhey Popovych <redacted>
---
 ip/ipaddress.c |   23 +++++++++--------------
 1 file changed, 9 insertions(+), 14 deletions(-)
diff --git a/ip/ipaddress.c b/ip/ipaddress.c
index f150d91..a3595c1 100644
--- a/ip/ipaddress.c
+++ b/ip/ipaddress.c
@@ -1558,6 +1558,8 @@ int print_addrinfo(const struct sockaddr_nl *who, struct nlmsghdr *n,
 		print_bool(PRINT_ANY, "deleted", "Deleted ", true);
 
 	if (!brief) {
+		const char *name;
+
 		if (filter.oneline || filter.flushb) {
 			const char *dev = ll_index_to_name(ifa->ifa_index);
 
@@ -1570,20 +1572,13 @@ int print_addrinfo(const struct sockaddr_nl *who, struct nlmsghdr *n,
 			}
 		}
 
-		int family = ifa->ifa_family;
-
-		if (ifa->ifa_family == AF_INET)
-			print_string(PRINT_ANY, "family", "    %s ", "inet");
-		else if (ifa->ifa_family == AF_INET6)
-			print_string(PRINT_ANY, "family", "    %s ", "inet6");
-		else if (ifa->ifa_family == AF_DECnet)
-			print_string(PRINT_ANY, "family", "    %s ", "dnet");
-		else if (ifa->ifa_family == AF_IPX)
-			print_string(PRINT_ANY, "family", "     %s ", "ipx");
-		else
-			print_int(PRINT_ANY,
-				  "family_index",
-				  "    family %d ", family);
+		name = family_name(ifa->ifa_family);
+		if (*name != '?') {
+			print_string(PRINT_ANY, "family", "    %s ", name);
+		} else {
+			print_int(PRINT_ANY, "family_index", "    family %d ",
+				  ifa->ifa_family);
+		}
 	}
 
 	if (rta_tb[IFA_LOCAL]) {
-- 
1.7.10.4
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help