[PATCH] Fix integer truncation in systat -ifstat

Ryan Stone rysto32 at gmail.com
Thu Sep 11 21:59:59 UTC 2014


systat -ifstat currently truncates byte counters down to 32-bit
integers.  The following fixes the issue, but I'm not very happy with
it.  u_long is what the rest of our code uses for network counters,
but that ends up meaning that our counters are 32-bits wide on 32-bit
platforms.  I could make it uint64_t but that's not very future proof.
RIght now I'm leaning towards punting on the issue and using u_long as
there is an awful lot of code that would have to be modified for
extended byte counters to actually work on all platforms.

[rstone at rstone-laptop systat]svn diff
Index: ifstat.c
===================================================================
--- ifstat.c    (revision 271439)
+++ ifstat.c    (working copy)
@@ -269,8 +269,8 @@
        struct  if_stat *ifp = NULL;
        struct  timeval tv, new_tv, old_tv;
        double  elapsed = 0.0;
-       u_int   new_inb, new_outb, old_inb, old_outb = 0;
-       u_int   new_inp, new_outp, old_inp, old_outp = 0;
+       u_long  new_inb, new_outb, old_inb, old_outb = 0;
+       u_long  new_inp, new_outp, old_inp, old_outp = 0;

        SLIST_FOREACH(ifp, &curlist, link) {
                /*


More information about the freebsd-net mailing list