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

Message ID 1515780219-31055-1-git-send-email-serhe.popovych@gmail.com
State New
Delegated to: stephen hemminger
Headers show
Series
  • [iproute2] ipaddress: Use family_name() for better code reuse
Related show

Commit Message

Serhey Popovych Jan. 12, 2018, 6:03 p.m.
Signed-off-by: Serhey Popovych <serhe.popovych@gmail.com>
---
 ip/ipaddress.c |   23 +++++++++--------------
 1 file changed, 9 insertions(+), 14 deletions(-)

Patch

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]) {