]> git.ipfire.org Git - thirdparty/iproute2.git/commitdiff
ipaddress: colorize peer, broadcast and anycast addresses as well
authorPhil Sutter <phil@nwl.cc>
Tue, 22 Mar 2016 18:35:14 +0000 (19:35 +0100)
committerStephen Hemminger <stephen@networkplumber.org>
Sun, 27 Mar 2016 17:37:34 +0000 (10:37 -0700)
Signed-off-by: Phil Sutter <phil@nwl.cc>
ip/ipaddress.c

index 7aab8e781eae8c44752c57d194846accf98200a9..90d7b1096c3aa6e7d378a3cb27cd8418b91ea0f5 100644 (file)
@@ -862,7 +862,8 @@ int print_linkinfo(const struct sockaddr_nl *who,
                                fprintf(fp, " peer ");
                        else
                                fprintf(fp, " brd ");
-                       fprintf(fp, "%s", ll_addr_n2a(RTA_DATA(tb[IFLA_BROADCAST]),
+                       color_fprintf(fp, COLOR_MAC, "%s",
+                                       ll_addr_n2a(RTA_DATA(tb[IFLA_BROADCAST]),
                                                      RTA_PAYLOAD(tb[IFLA_BROADCAST]),
                                                      ifi->ifi_type,
                                                      b1, sizeof(b1)));
@@ -1062,32 +1063,34 @@ int print_addrinfo(const struct sockaddr_nl *who, struct nlmsghdr *n,
                                          RTA_PAYLOAD(rta_tb[IFA_LOCAL]),
                                          RTA_DATA(rta_tb[IFA_LOCAL]),
                                          abuf, sizeof(abuf)));
-               if (rta_tb[IFA_ADDRESS] == NULL ||
-                   memcmp(RTA_DATA(rta_tb[IFA_ADDRESS]), RTA_DATA(rta_tb[IFA_LOCAL]),
-                          ifa->ifa_family == AF_INET ? 4 : 16) == 0) {
-                       fprintf(fp, "/%d ", ifa->ifa_prefixlen);
-               } else {
-                       fprintf(fp, " peer %s/%d ",
-                               format_host(ifa->ifa_family,
-                                           RTA_PAYLOAD(rta_tb[IFA_ADDRESS]),
-                                           RTA_DATA(rta_tb[IFA_ADDRESS]),
-                                           abuf, sizeof(abuf)),
-                               ifa->ifa_prefixlen);
+               if (rta_tb[IFA_ADDRESS] &&
+                   memcmp(RTA_DATA(rta_tb[IFA_ADDRESS]),
+                          RTA_DATA(rta_tb[IFA_LOCAL]),
+                          ifa->ifa_family == AF_INET ? 4 : 16)) {
+                       fprintf(fp, " peer ");
+                       color_fprintf(fp, ifa_family_color(ifa->ifa_family),
+                                     "%s", format_host(ifa->ifa_family,
+                                     RTA_PAYLOAD(rta_tb[IFA_ADDRESS]),
+                                     RTA_DATA(rta_tb[IFA_ADDRESS]),
+                                     abuf, sizeof(abuf)));
                }
+               fprintf(fp, "/%d ", ifa->ifa_prefixlen);
        }
 
        if (brief)
                goto brief_exit;
 
        if (rta_tb[IFA_BROADCAST]) {
-               fprintf(fp, "brd %s ",
+               fprintf(fp, "brd ");
+               color_fprintf(fp, ifa_family_color(ifa->ifa_family), "%s ",
                        format_host(ifa->ifa_family,
                                    RTA_PAYLOAD(rta_tb[IFA_BROADCAST]),
                                    RTA_DATA(rta_tb[IFA_BROADCAST]),
                                    abuf, sizeof(abuf)));
        }
        if (rta_tb[IFA_ANYCAST]) {
-               fprintf(fp, "any %s ",
+               fprintf(fp, "any ");
+               color_fprintf(fp, ifa_family_color(ifa->ifa_family), "%s ",
                        format_host(ifa->ifa_family,
                                    RTA_PAYLOAD(rta_tb[IFA_ANYCAST]),
                                    RTA_DATA(rta_tb[IFA_ANYCAST]),