]> The Tcpdump Group git mirrors - tcpdump/blobdiff - util.c
change the TCP printer to print new-style order:
[tcpdump] / util.c
diff --git a/util.c b/util.c
index 963a2dc0d176739e9903b86195cd8fc6aacd8c2a..6b723e543c603c4314af3053c1d28f89db2fb252 100644 (file)
--- a/util.c
+++ b/util.c
@@ -21,7 +21,7 @@
 
 #ifndef lint
 static const char rcsid[] _U_ =
-    "@(#) $Header: /tcpdump/master/tcpdump/util.c,v 1.108 2006-08-19 06:47:39 guy Exp $ (LBL)";
+    "@(#) $Header: /tcpdump/master/tcpdump/util.c,v 1.109 2007-01-29 09:59:42 hannes Exp $ (LBL)";
 #endif
 
 #ifdef HAVE_CONFIG_H
@@ -316,11 +316,12 @@ tok2str(register const struct tok *lp, register const char *fmt,
 
 /*
  * Convert a bit token value to a string; use "fmt" if not found.
- * this is useful for parsing bitfields, the output strings are comma seperated
+ * this is useful for parsing bitfields, the output strings are seperated
+ * if the s field is positive.
  */
-char *
-bittok2str(register const struct tok *lp, register const char *fmt,
-          register int v)
+static char *
+bittok2str_internal(register const struct tok *lp, register const char *fmt,
+          register int v, register int sep)
 {
         static char buf[256]; /* our stringbuffer */
         int buflen=0;
@@ -337,7 +338,8 @@ bittok2str(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, ",lp->s);
+                    buflen+=snprintf(buf+buflen, sizeof(buf)-buflen, "%s%s",
+                                     lp->s, sep ? ", " : "");
                     break;
                 }
                 rotbit=rotbit<<1; /* no match - lets shift and try again */
@@ -345,6 +347,11 @@ bittok2str(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 the trailing zero 2 bytes before to eliminate the last comma & whitespace */
             buf[buflen-2] = '\0';
@@ -359,6 +366,28 @@ bittok2str(register const struct tok *lp, register const char *fmt,
         }
 }
 
+/*
+ * Convert a bit token value to a string; use "fmt" if not found.
+ * this is useful for parsing bitfields, the output strings are not seperated.
+ */
+char *
+bittok2str_nosep(register const struct tok *lp, register const char *fmt,
+          register int v)
+{
+    return (bittok2str_internal(lp, fmt, v, 0));
+}
+
+/*
+ * Convert a bit token value to a string; use "fmt" if not found.
+ * this is useful for parsing bitfields, the output strings are comma seperated.
+ */
+char *
+bittok2str(register const struct tok *lp, register const char *fmt,
+          register int v)
+{
+    return (bittok2str_internal(lp, fmt, v, 1));
+}
+
 /*
  * Convert a value to a string using an array; the macro
  * tok2strary() in <interface.h> is the public interface to