Date: Thu, 29 Feb 1996 20:13:28 -0500 (EST) From: Richard Toren <rpt@miles.sso.loral.com> To: Lyndon Nerenberg VE7TCP <lyndon@orthanc.com> Cc: hackers@freebsd.org Subject: Re: tcpdump changes Message-ID: <Pine.SUN.3.91.960229200656.15478A-100000@miles> In-Reply-To: <199602290146.RAA05053@multivac.orthanc.com>
next in thread | previous in thread | raw e-mail | index | archive | help
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 | ====================================================
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?Pine.SUN.3.91.960229200656.15478A-100000>