]> The Tcpdump Group git mirrors - tcpdump/blobdiff - util.c
Check for a TCP header length that's too short, report more information
[tcpdump] / util.c
diff --git a/util.c b/util.c
index 7326a62e9354621502f484ba7b66c74484f90847..005824e369cc20cb88528b39da9637e92ccbf864 100644 (file)
--- a/util.c
+++ b/util.c
@@ -20,8 +20,8 @@
  */
 
 #ifndef lint
-static const char rcsid[] =
-    "@(#) $Header: /tcpdump/master/tcpdump/util.c,v 1.87 2003-10-02 13:16:14 hannes Exp $ (LBL)";
+static const char rcsid[] _U_ =
+    "@(#) $Header: /tcpdump/master/tcpdump/util.c,v 1.87.2.4 2004-04-28 22:09:23 guy Exp $ (LBL)";
 #endif
 
 #ifdef HAVE_CONFIG_H
@@ -199,27 +199,9 @@ relts_print(int secs)
  */
 
 int
-print_unknown_data(const u_char *cp,const char *lf,int len)
+print_unknown_data(const u_char *cp,const char *ident,int len)
 {
-        int i;
-
-        if (len ==0)
-           return(0);
-
-       printf("%s0x0000: ",lf);
-       for(i=0;i<len;i++) {
-           if (!TTEST2(*(cp+i), 1)) {
-              printf("%spacket exceeded snapshot",lf);
-              return(0);
-            }
-           printf("%02x",*(cp+i));
-           if (i%2)
-               printf(" ");
-           if (i/16!=(i+1)/16) {
-               if (i<(len-1))
-                   printf("%s0x%04x: ",lf,i+1);
-           }
-       }
+        hex_print(ident,cp,len);
        return(1); /* everything is ok */
 }
 
@@ -230,7 +212,9 @@ const char *
 tok2str(register const struct tok *lp, register const char *fmt,
        register int v)
 {
-       static char buf[128];
+       static char buf[4][128];
+       static int idx = 0;
+       char *ret;
 
        while (lp->s != NULL) {
                if (lp->v == v)
@@ -239,8 +223,10 @@ tok2str(register const struct tok *lp, register const char *fmt,
        }
        if (fmt == NULL)
                fmt = "#%d";
-       (void)snprintf(buf, sizeof(buf), fmt, v);
-       return (buf);
+       ret = buf[idx];
+       (void)snprintf(ret, sizeof(buf[0]), fmt, v);
+       idx = (idx+1) & 3;
+       return (ret);
 }
 
 /*