]> The Tcpdump Group git mirrors - tcpdump/blobdiff - util.c
Fix the pointer tests in the non-ndoified TTEST2() macro as well.
[tcpdump] / util.c
diff --git a/util.c b/util.c
index 2fd26ef17fa69f73ce79230db4d71121a391afc3..5731ca7b376a95751d9e9448d65092429eef14d7 100644 (file)
--- a/util.c
+++ b/util.c
@@ -138,8 +138,26 @@ static char *
 ts_format(netdissect_options *ndo, int sec, int usec)
 {
        static char buf[sizeof("00:00:00.000000000")];
-       const char *format = ndo->ndo_tstamp_precision == PCAP_TSTAMP_PRECISION_NANO ?
-                "%02d:%02d:%02d.%09u" : "%02d:%02d:%02d.%06u";
+       const char *format;
+
+#ifdef HAVE_PCAP_SET_TSTAMP_PRECISION
+       switch (ndo->ndo_tstamp_precision) {
+
+       case PCAP_TSTAMP_PRECISION_MICRO:
+               format = "%02d:%02d:%02d.%06u";
+               break;
+
+       case PCAP_TSTAMP_PRECISION_NANO:
+               format = "%02d:%02d:%02d.%09u";
+               break;
+
+       default:
+               format = "%02d:%02d:%02d.{unknown precision}";
+               break;
+       }
+#else
+       format = "%02d:%02d:%02d.%06u";
+#endif
 
        snprintf(buf, sizeof(buf), format,
                  sec / 3600, (sec % 3600) / 60, sec % 60, usec);
@@ -323,6 +341,7 @@ bittok2str_internal(register const struct tok *lp, register const char *fmt,
         int buflen=0;
         register int rotbit; /* this is the bit we rotate through all bitpositions */
         register int tokval;
+        const char * sepstr = "";
 
        while (lp != NULL && lp->s != NULL) {
             tokval=lp->v;   /* load our first value */
@@ -335,7 +354,8 @@ bittok2str_internal(register const struct tok *lp, register const char *fmt,
                if (tokval == (v&rotbit)) {
                     /* ok we have found something */
                     buflen+=snprintf(buf+buflen, sizeof(buf)-buflen, "%s%s",
-                                     lp->s, sep ? ", " : "");
+                                     sepstr, lp->s);
+                    sepstr = sep ? ", " : "";
                     break;
                 }
                 rotbit=rotbit<<1; /* no match - lets shift and try again */
@@ -343,23 +363,10 @@ bittok2str_internal(register const struct tok *lp, register const char *fmt,
             lp++;
        }
 
-        /* user didn't want string seperation - no need to cut off trailing seperators */
-        if (!sep) {
-            return (buf);
-        }
-
-        if (buflen != 0) { /* did we find anything */
-            /* yep, set the trailing zero 2 bytes before to eliminate the last comma & whitespace */
-            buf[buflen-2] = '\0';
-            return (buf);
-        }
-        else {
+        if (buflen == 0)
             /* bummer - lets print the "unknown" message as advised in the fmt string if we got one */
-            if (fmt == NULL)
-               fmt = "#%d";
-            (void)snprintf(buf, sizeof(buf), fmt, v);
-            return (buf);
-        }
+            (void)snprintf(buf, sizeof(buf), fmt == NULL ? "#%d" : fmt, v);
+        return (buf);
 }
 
 /*