]> The Tcpdump Group git mirrors - tcpdump/blobdiff - util.c
Make "-x" and "-X" work with PPPoE interfaces; based on code from Darren
[tcpdump] / util.c
diff --git a/util.c b/util.c
index fc3a603a3d67fe108ef0a7c82064cee67ea3827b..fb849c6f68186f8a73528f81b186fd4bb675ac2f 100644 (file)
--- a/util.c
+++ b/util.c
@@ -21,7 +21,7 @@
 
 #ifndef lint
 static const char rcsid[] =
-    "@(#) $Header: /tcpdump/master/tcpdump/util.c,v 1.70 2001-09-10 00:28:54 fenner Exp $ (LBL)";
+    "@(#) $Header: /tcpdump/master/tcpdump/util.c,v 1.72 2001-10-08 16:12:13 fenner Exp $ (LBL)";
 #endif
 
 #ifdef HAVE_CONFIG_H
@@ -183,10 +183,14 @@ relts_print(int secs)
        const char **l = lengths;
        const int *s = seconds;
 
-       if (secs <= 0) {
+       if (secs == 0) {
                (void)printf("0s");
                return;
        }
+       if (secs < 0) {
+               (void)printf("-");
+               secs = -secs;
+       }
        while (secs > 0) {
                if (secs >= *s) {
                        (void)printf("%d%s", secs / *s, *l);
@@ -217,6 +221,25 @@ tok2str(register const struct tok *lp, register const char *fmt,
        return (buf);
 }
 
+/*
+ * Convert a value to a string using an array; the macro
+ * tok2strary() in <interface.h> is the public interface to
+ * this function and ensures that the second argument is
+ * correct for bounds-checking.
+ */
+const char *
+tok2strary_internal(register const char **lp, int n, register const char *fmt,
+       register int v)
+{
+       static char buf[128];
+
+       if (v >= 0 && v < n && lp[v] != NULL)
+               return lp[v];
+       if (fmt == NULL)
+               fmt = "#%d";
+       (void)snprintf(buf, sizeof(buf), fmt, v);
+       return (buf);
+}
 
 /* VARARGS */
 void