From owner-freebsd-hackers Thu Feb 29 17:15:18 1996 Return-Path: owner-hackers Received: (from root@localhost) by freefall.freebsd.org (8.7.3/8.7.3) id RAA27131 for hackers-outgoing; Thu, 29 Feb 1996 17:15:18 -0800 (PST) Received: from wdl1.wdl.loral.com ([137.249.32.1]) by freefall.freebsd.org (8.7.3/8.7.3) with SMTP id RAA27126 for ; Thu, 29 Feb 1996 17:15:11 -0800 (PST) Received: from miles.sso.loral.com (miles.wdl.loral.com) by wdl1.wdl.loral.com (5.x/WDL-2.4-1.0) id AA03722; Thu, 29 Feb 1996 17:14:31 -0800 Received: by miles.sso.loral.com (4.1/SSO-SUN-2.04) id AA15545; Thu, 29 Feb 96 20:13:29 EST Date: Thu, 29 Feb 1996 20:13:28 -0500 (EST) From: Richard Toren X-Sender: rpt@miles To: Lyndon Nerenberg VE7TCP Cc: hackers@freebsd.org Subject: Re: tcpdump changes In-Reply-To: <199602290146.RAA05053@multivac.orthanc.com> Message-Id: Mime-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII Sender: owner-hackers@freebsd.org Precedence: bulk On Wed, 28 Feb 1996, Lyndon Nerenberg VE7TCP wrote: > I'm thinking of making a change to tcpdump and would like > to solicit comments ... > > The '-x' option prints a hex dump of packet contents (modulo capture > length). I would like to modify it to also include an ASCII > representation of the same data. (Makes it easier to trace things like I did that with the following modification to tcpdump.c. This routine is near the end of the source file. This was 3.0.2 source. I don't have the original handy, but this should be a good start. Then rebuild and the -x will dump hex/ascii. Have fun... default_print(register const u_char *data, register int len) { /* DESCZ Dumps to dbglog file a hex/ascii formatted dump of the passed address for the specified number of bytes. */ char hexbuf[64]; char chrbuf[24]; char *k; int i, j; if (len <= 0) return; printf("\n"); for (i=j=0, k=hexbuf; i< len; i++, j++) { if (j >= 16) { chrbuf[j] = 0x00; printf ("\t\t\t|%-42s|%-16s|\n", hexbuf, chrbuf); j = 0; k = hexbuf; } if (j&1) { sprintf (k, "%02X ", data[i]); chrbuf[j] = isprint (data[i]) ? data[i] : '.'; k = k+3; } else { sprintf (k, "%02X", data[i]); chrbuf[j] = isprint (data[i]) ? data[i] : '.'; k = k+2; } } if (j > 0) { chrbuf[j] = 0x00; printf( "\t\t\t|%-42s|%-16s|\n", hexbuf, chrbuf); j = 0; k = hexbuf; } fflush (stdout); /********** original ***** register const u_short *sp; register u_int i; register int nshorts; if ((int)bp & 1) { default_print_unaligned(bp, length); return; } sp = (u_short *)bp; nshorts = (u_int) length / sizeof(u_short); i = 0; while (--nshorts >= 0) { if ((i++ % 8) == 0) (void)printf("\n\t\t\t"); (void)printf(" %04x", ntohs(*sp++)); } if (length & 1) { if ((i % 8) == 0) (void)printf("\n\t\t\t"); (void)printf(" %02x", *(u_char *)sp); } *********/ } ==================================================== Rip Toren | The bad news is that C++ is not an object-oriented | rpt@miles.sso.loral.com | programming language. .... The good news is that | | C++ supports object-oriented programming. | | C++ Programming & Fundamental Concepts | | by Anderson & Heinze | ====================================================