[<prev] [next>] [day] [month] [year] [list]
Message-Id: <1515780219-31055-1-git-send-email-serhe.popovych@gmail.com>
Date: Fri, 12 Jan 2018 20:03:39 +0200
From: Serhey Popovych <serhe.popovych@...il.com>
To: netdev@...r.kernel.org
Subject: [PATCH iproute2] ipaddress: Use family_name() for better code reuse
Signed-off-by: Serhey Popovych <serhe.popovych@...il.com>
---
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
Powered by blists - more mailing lists