From: hannes Date: Mon, 29 Dec 2003 22:42:20 +0000 (+0000) Subject: - pass on ident string to hex_print() X-Git-Tag: tcpdump-3.8.2~46 X-Git-Url: https://git.tcpdump.org/tcpdump/commitdiff_plain/ea91ebb8324c8156ce9fba06959e3eaad0b5717e - pass on ident string to hex_print() - 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 --- diff --git a/interface.h b/interface.h index eab0a21a..d04d1032 100644 --- a/interface.h +++ b/interface.h @@ -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 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 *); diff --git a/print-ascii.c b/print-ascii.c index c00d039d..1643a2e9 100644 --- a/print-ascii.c +++ b/print-ascii.c @@ -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 #include @@ -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 */ + + diff --git a/print-cdp.c b/print-cdp.c index 02cfd081..a5197cfa 100644 --- a/print-cdp.c +++ b/print-cdp.c @@ -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]"); diff --git a/print-ether.c b/print-ether.c index adf2bfcf..e9230d2f 100644 --- a/print-ether.c +++ b/print-ether.c @@ -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: diff --git a/print-telnet.c b/print-telnet.c index 61a29c2b..a925b862 100644 --- a/print-telnet.c +++ b/print-telnet.c @@ -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 @@ -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 diff --git a/tcpdump.c b/tcpdump.c index 6a87ecc3..3983a33e 100644 --- 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 088c14e7..4e3d61fc 100644 --- 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