]> The Tcpdump Group git mirrors - tcpdump/commitdiff
- pass on ident string to hex_print()
authorhannes <hannes>
Mon, 29 Dec 2003 22:42:20 +0000 (22:42 +0000)
committerhannes <hannes>
Mon, 29 Dec 2003 22:42:20 +0000 (22:42 +0000)
- pass on ident string to ascii_print()
- pave the way for eliminating print_unknown_data()
  and subsequent hex_print() replacement

- clean up the default_print() related functions:
  - call always into print_ascii() b/c just hexdump data
    is uninteresting; hex-offsets plus ascii representation
    is what most people are looking for
  - remove default_print_unaligned() as it is now obsolete

interface.h
print-ascii.c
print-cdp.c
print-ether.c
print-telnet.c
tcpdump.c
util.c

index eab0a21ad737ad9dabb428283ead34abc5dfe30e..d04d1032b5d401f4f62eb59367db528d2ba31597 100644 (file)
@@ -18,7 +18,7 @@
  * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
  * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
  *
- * @(#) $Header: /tcpdump/master/tcpdump/interface.h,v 1.217.2.3 2003-11-19 01:28:18 guy Exp $ (LBL)
+ * @(#) $Header: /tcpdump/master/tcpdump/interface.h,v 1.217.2.4 2003-12-29 22:42:21 hannes Exp $ (LBL)
  */
 
 #ifndef tcpdump_interface_h
@@ -191,11 +191,11 @@ extern const char *dnnum_string(u_short);
 #include <pcap.h>
 
 extern int print_unknown_data(const u_char *, const char *,int);
-extern void ascii_print_with_offset(const u_char *, u_int, u_int);
-extern void ascii_print(const u_char *, u_int);
-extern void hex_print_with_offset(const u_char *, u_int, u_int);
+extern void ascii_print_with_offset(const u_char *, const u_char *, u_int, u_int);
+extern void ascii_print(const u_char *, const u_char *, u_int);
+extern void hex_print_with_offset(const u_char *, const u_char *, u_int, u_int);
 extern void telnet_print(const u_char *, u_int);
-extern void hex_print(const u_char *, u_int);
+extern void hex_print(const u_char *, const u_char *, u_int);
 extern int ether_encap_print(u_short, const u_char *, u_int, u_int, u_short *);
 extern int llc_print(const u_char *, u_int, u_int, const u_char *,
        const u_char *, u_short *);
index c00d039d02dd3ae728d2d2ee8a1dc4e8a200b98d..1643a2e9f390d90e875fd96a764f88bcf226fb07 100644 (file)
@@ -42,7 +42,7 @@
 
 #ifndef lint
 static const char rcsid[] _U_ =
-     "@(#) $Header: /tcpdump/master/tcpdump/print-ascii.c,v 1.10.2.2 2003-11-16 08:51:11 guy Exp $";
+     "@(#) $Header: /tcpdump/master/tcpdump/print-ascii.c,v 1.10.2.3 2003-12-29 22:42:20 hannes Exp $";
 #endif
 #include <tcpdump-stdinc.h>
 #include <stdio.h>
@@ -57,7 +57,7 @@ static const char rcsid[] _U_ =
                (HEXDUMP_HEXSTUFF_PER_SHORT * HEXDUMP_SHORTS_PER_LINE)
 
 void
-ascii_print_with_offset(register const u_char *cp, register u_int length,
+ascii_print_with_offset(register const u_char *ident, register const u_char *cp, register u_int length,
                        register u_int oset)
 {
        register u_int i;
@@ -93,8 +93,8 @@ ascii_print_with_offset(register const u_char *cp, register u_int length,
                        if (Aflag) {
                                (void)printf("%s", asciistuff);
                        } else {
-                               (void)printf("\n0x%04x\t%-*s\t%s",
-                                   oset, HEXDUMP_HEXSTUFF_PER_LINE,
+                               (void)printf("%s0x%04x: %-*s  %s",
+                                   ident, oset, HEXDUMP_HEXSTUFF_PER_LINE,
                                    hexstuff, asciistuff);
                        }
                        i = 0; hsp = hexstuff; asp = asciistuff;
@@ -116,26 +116,26 @@ ascii_print_with_offset(register const u_char *cp, register u_int length,
        if (i > 0) {
                *hsp = *asp = '\0';
                if (Aflag) {
-                       (void)printf("\n%s", asciistuff);
+                       (void)printf("%s%s", ident, asciistuff);
                } else {
-                       (void)printf("\n0x%04x\t%-*s\t%s",
-                            oset, HEXDUMP_HEXSTUFF_PER_LINE,
+                       (void)printf("%s0x%04x: %-*s  %s",
+                            ident, oset, HEXDUMP_HEXSTUFF_PER_LINE,
                             hexstuff, asciistuff);
                }
        }
 }
 
 void
-ascii_print(register const u_char *cp, register u_int length)
+ascii_print(register const u_char *ident, register const u_char *cp, register u_int length)
 {
-       ascii_print_with_offset(cp, length, 0);
+       ascii_print_with_offset(ident, cp, length, 0);
 }
 
 /*
  * telnet_print() wants this.  It is essentially default_print_unaligned()
  */
 void
-hex_print_with_offset(register const u_char *cp, register u_int length,
+hex_print_with_offset(register const u_char *ident, register const u_char *cp, register u_int length,
                      register u_int oset)
 {
        register u_int i, s;
@@ -145,7 +145,7 @@ hex_print_with_offset(register const u_char *cp, register u_int length,
        i = 0;
        while (--nshorts >= 0) {
                if ((i++ % 8) == 0) {
-                       (void)printf("\n0x%04x\t", oset);
+                       (void)printf("%s0x%04x: ", ident, oset);
                        oset += HEXDUMP_BYTES_PER_LINE;
                }
                s = *cp++;
@@ -153,7 +153,7 @@ hex_print_with_offset(register const u_char *cp, register u_int length,
        }
        if (length & 1) {
                if ((i % 8) == 0)
-                       (void)printf("\n0x%04x\t", oset);
+                       (void)printf("%s0x%04x: ", ident, oset);
                (void)printf(" %02x", *cp);
        }
 }
@@ -162,9 +162,9 @@ hex_print_with_offset(register const u_char *cp, register u_int length,
  * just for completeness
  */
 void
-hex_print(register const u_char *cp, register u_int length)
+hex_print(register const u_char *ident, register const u_char *cp, register u_int length)
 {
-       hex_print_with_offset(cp, length, 0);
+       hex_print_with_offset(ident, cp, length, 0);
 }
 
 #ifdef MAIN
@@ -181,3 +181,5 @@ main(int argc, char *argv[])
        exit(0);
 }
 #endif /* MAIN */
+
+
index 02cfd0817e4dfb2775e203f59402652ab191ba8e..a5197cfa94d7e0199a38dd02581db3ecc3df80f0 100644 (file)
@@ -26,7 +26,7 @@
 
 #ifndef lint
 static const char rcsid[] _U_ =
-    "@(#) $Header: /tcpdump/master/tcpdump/print-cdp.c,v 1.19.2.2 2003-11-16 08:51:14 guy Exp $ (LBL)";
+    "@(#) $Header: /tcpdump/master/tcpdump/print-cdp.c,v 1.19.2.3 2003-12-29 22:42:22 hannes Exp $";
 #endif
 
 #ifdef HAVE_CONFIG_H
@@ -99,9 +99,9 @@ cdp_print(const u_char *pptr, u_int length, u_int caplen)
 
         if (!TTEST2(*tptr, CDP_HEADER_LEN))
                 goto trunc;
-       printf("CDP v%u, ttl: %us", *tptr, *(tptr+1));
+       printf("CDPv%u, ttl: %us", *tptr, *(tptr+1));
         if (vflag)
-                printf(", checksum: %u (unverified)", EXTRACT_16BITS(tptr));
+                printf(", checksum: %u (unverified), length %u", EXTRACT_16BITS(tptr), length);
        tptr += CDP_HEADER_LEN;
 
        while (tptr < (pptr+length)) {
@@ -213,6 +213,9 @@ cdp_print(const u_char *pptr, u_int length, u_int caplen)
                        break;
                tptr = tptr+len;
        }
+        if (vflag < 1)
+            printf(", length %u",caplen);
+
        return;
 trunc:
        printf("[|cdp]");
index adf2bfcfb961f6a79d6712c82681d88a5cbc5361..e9230d2fc752bc2d11ab02276ff3055526f7e481 100644 (file)
@@ -20,7 +20,7 @@
  */
 #ifndef lint
 static const char rcsid[] _U_ =
-    "@(#) $Header: /tcpdump/master/tcpdump/print-ether.c,v 1.82.2.2 2003-11-16 08:51:20 guy Exp $ (LBL)";
+    "@(#) $Header: /tcpdump/master/tcpdump/print-ether.c,v 1.82.2.3 2003-12-29 22:42:21 hannes Exp $ (LBL)";
 #endif
 
 #ifdef HAVE_CONFIG_H
@@ -87,8 +87,14 @@ ether_hdr_print(register const u_char *bp, u_int length)
                if (ntohs(ep->ether_type) <= ETHERMTU)
                          (void)printf(", 802.3");
                 else 
-                         (void)printf(", ethertype %s",
-                                      tok2str(ethertype_values,"0x%04x", ntohs(ep->ether_type)));            
+                         (void)printf(", ethertype %s (0x%04x)",
+                                      tok2str(ethertype_values,"Unknown", ntohs(ep->ether_type)),
+                                       ntohs(ep->ether_type));       
+        } else {
+                if (ntohs(ep->ether_type) <= ETHERMTU)
+                          (void)printf(", 802.3");
+                else 
+                          (void)printf(", %s", tok2str(ethertype_values,"Unknown Ethertype (0x%04x)", ntohs(ep->ether_type)));  
         }
 
        (void)printf(", length %u: ", length);
@@ -139,7 +145,7 @@ ether_print(const u_char *p, u_int length, u_int caplen)
 
                if (!xflag && !qflag)
                        default_print(p, caplen);
-       }
+       } 
 }
 
 /*
@@ -255,7 +261,7 @@ ether_encap_print(u_short ether_type, const u_char *p,
                return (1);
 
         case ETHERTYPE_LOOPBACK:
-                return (1);
+                return (0);
 
        case ETHERTYPE_MPLS:
        case ETHERTYPE_MPLS_MULTI:
index 61a29c2b9b9bf5b9c3ffc263e1d6a8ef370ced1f..a925b862c7ecdef2ff8a7baaec5cc50e3e8c2dfa 100644 (file)
@@ -51,7 +51,7 @@
 
 #ifndef lint
 static const char rcsid[] _U_ =
-     "@(#) $Header: /tcpdump/master/tcpdump/print-telnet.c,v 1.21.2.2 2003-11-16 08:51:48 guy Exp $";
+     "@(#) $Header: /tcpdump/master/tcpdump/print-telnet.c,v 1.21.2.3 2003-12-29 22:42:23 hannes Exp $";
 #endif
 
 #include <tcpdump-stdinc.h>
@@ -244,7 +244,7 @@ telnet_print(const u_char *sp, u_int length)
                if (Xflag && 2 < vflag) {
                        if (first)
                                printf("\nTelnet:");
-                       hex_print_with_offset(sp, l, sp - osp);
+                       hex_print_with_offset("\n", sp, l, sp - osp);
                        if (l > 8)
                                printf("\n\t\t\t\t");
                        else
index 6a87ecc3677cd74293ccb0e952ed415e43a188bc..3983a33e9e8fd1fef2e0f96cb8a4c7238bdbb04e 100644 (file)
--- a/tcpdump.c
+++ b/tcpdump.c
@@ -30,7 +30,7 @@ static const char copyright[] _U_ =
     "@(#) Copyright (c) 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997, 2000\n\
 The Regents of the University of California.  All rights reserved.\n";
 static const char rcsid[] _U_ =
-    "@(#) $Header: /tcpdump/master/tcpdump/tcpdump.c,v 1.216.2.5 2003-12-18 01:22:57 guy Exp $ (LBL)";
+    "@(#) $Header: /tcpdump/master/tcpdump/tcpdump.c,v 1.216.2.6 2003-12-29 22:42:22 hannes Exp $ (LBL)";
 #endif
 
 /*
@@ -1011,7 +1011,7 @@ print_packet(u_char *user, const struct pcap_pkthdr *h, const u_char *sp)
                        /*
                         * Include the link-layer header.
                         */
-                       default_print_unaligned(sp, h->caplen);
+                       default_print(sp, h->caplen);
                } else {
                        /*
                         * Don't include the link-layer header - and if
@@ -1019,7 +1019,7 @@ print_packet(u_char *user, const struct pcap_pkthdr *h, const u_char *sp)
                         * print nothing.
                         */
                        if (h->caplen > hdrlen)
-                               default_print_unaligned(sp + hdrlen,
+                               default_print(sp + hdrlen,
                                    h->caplen - hdrlen);
                }
        }
@@ -1031,32 +1031,6 @@ print_packet(u_char *user, const struct pcap_pkthdr *h, const u_char *sp)
                info(0);
 }
 
-/* Like default_print() but data need not be aligned */
-void
-default_print_unaligned(register const u_char *cp, register u_int length)
-{
-       register u_int i, s;
-       register int nshorts;
-
-       if (Xflag) {
-               ascii_print(cp, length);
-               return;
-       }
-       nshorts = (u_int) length / sizeof(u_short);
-       i = 0;
-       while (--nshorts >= 0) {
-               if ((i++ % 8) == 0)
-                       (void)printf("\n\t\t\t");
-               s = *cp++;
-               (void)printf(" %02x%02x", s, *cp++);
-       }
-       if (length & 1) {
-               if ((i % 8) == 0)
-                       (void)printf("\n\t\t\t");
-               (void)printf(" %02x", *cp);
-       }
-}
-
 #ifdef WIN32
        /*
         * XXX - there should really be libpcap calls to get the version
@@ -1088,7 +1062,7 @@ default_print_unaligned(register const u_char *cp, register u_int length)
 void
 default_print(register const u_char *bp, register u_int length)
 {
-       default_print_unaligned(bp, length);
+    ascii_print("\n\t", bp, length); /* pass on lf and identation string */
 }
 
 #ifdef SIGINFO
diff --git a/util.c b/util.c
index 088c14e76fc7b78110786cb6b1c4a219003af7e1..4e3d61fc7941bea73bdb3509c9900eaeac4ca589 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.87.2.2 2003-11-16 08:51:58 guy Exp $ (LBL)";
+    "@(#) $Header: /tcpdump/master/tcpdump/util.c,v 1.87.2.3 2003-12-29 22:42:23 hannes 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 */
 }