]> git.ipfire.org Git - thirdparty/iproute2.git/commitdiff
Handle default hoplimit
authorStephen Hemminger <stephen.hemminger@vyatta.com>
Mon, 23 Mar 2009 17:49:21 +0000 (10:49 -0700)
committerStephen Hemminger <stephen.hemminger@vyatta.com>
Mon, 23 Mar 2009 17:49:21 +0000 (10:49 -0700)
Default for hoplimit is -1 which should be displayed as zero.

ip/iproute.c

index 6a2ea05f18bac186fdae0ac8c29c219920e1be18..bf0f31bdbf0107292971120c52b56d6778acd15d 100644 (file)
@@ -493,6 +493,8 @@ int print_route(const struct sockaddr_nl *who, struct nlmsghdr *n, void *arg)
                        mxlock = *(unsigned*)RTA_DATA(mxrta[RTAX_LOCK]);
 
                for (i=2; i<= RTAX_MAX; i++) {
+                       unsigned val;
+
                        if (mxrta[i] == NULL)
                                continue;
                        if (!hz)
@@ -505,21 +507,31 @@ int print_route(const struct sockaddr_nl *who, struct nlmsghdr *n, void *arg)
                        if (mxlock & (1<<i))
                                fprintf(fp, " lock");
 
-                       if (i != RTAX_RTT && i != RTAX_RTTVAR &&
-                           i != RTAX_RTO_MIN)
-                               fprintf(fp, " %u", *(unsigned*)RTA_DATA(mxrta[i]));
-                       else {
-                               unsigned long long val = *(unsigned*)RTA_DATA(mxrta[i]);
+                       val = *(unsigned*)RTA_DATA(mxrta[i]);
+                       switch (i) {
+                       case RTAX_HOPLIMIT:
+                               if ((long)val == -1)
+                                       val = 0;
+                               /* fall through */
+                       default:
+                               fprintf(fp, " %u", val);
+                               break;
 
+                       case RTAX_RTT:
+                       case RTAX_RTTVAR:
+                       case RTAX_RTO_MIN:
                                val *= 1000;
                                if (i == RTAX_RTT)
                                        val /= 8;
                                else if (i == RTAX_RTTVAR)
                                        val /= 4;
+
                                if (val >= hz)
-                                       fprintf(fp, " %llums", val/hz);
+                                       fprintf(fp, " %llums",
+                                               (unsigned long long) val / hz);
                                else
-                                       fprintf(fp, " %.2fms", (float)val/hz);
+                                       fprintf(fp, " %.2fms", 
+                                               (double)val / hz);
                        }
                }
        }