Skip site navigation (1)Skip section navigation (2)
Date:      Thu, 16 Sep 1999 23:07:12 +0100 (BST)
From:      fanf@demon.net
To:        FreeBSD-gnats-submit@freebsd.org
Subject:   bin/13781: [PATCH] allow tcpdump to print packet contents in ascii
Message-ID:  <199909162207.XAA16067@fanf.eng.demon.net>

next in thread | raw e-mail | index | archive | help

>Number:         13781
>Category:       bin
>Synopsis:       [PATCH] allow tcpdump to print packet contents in ascii
>Confidential:   no
>Severity:       non-critical
>Priority:       medium
>Responsible:    freebsd-bugs
>State:          open
>Quarter:        
>Keywords:       
>Date-Required:
>Class:          change-request
>Submitter-Id:   current-users
>Arrival-Date:   Thu Sep 16 15:10:00 PDT 1999
>Closed-Date:
>Last-Modified:
>Originator:     Tony Finch
>Release:        FreeBSD 3.3-RC-19990916 i386
>Organization:
Demon Internet
>Environment:

FreeBSD fanf.eng.demon.net 3.3-RC-19990916 FreeBSD 3.3-RC-19990916 #3: Thu Sep 16 03:06:33 BST 1999     root@fanf.eng.demon.net:/usr/src/sys/compile/DELL-PREC410  i386

>Description:

This patch adds a -z flag to tcpdump like the existing -x flag, but this one
prints the packet contents in ascii as well as hex

>How-To-Repeat:


>Fix:
	

diff -ur tcpdump/VERSION tcpdump-fanf/VERSION
--- tcpdump/VERSION	Tue Sep 15 20:36:18 1998
+++ tcpdump-fanf/VERSION	Thu Sep 16 22:34:02 1999
@@ -1 +1 @@
-3.4
+3.4f2
diff -ur tcpdump/interface.h tcpdump-fanf/interface.h
--- tcpdump/interface.h	Thu May 27 04:06:52 1999
+++ tcpdump-fanf/interface.h	Thu Sep 16 22:34:02 1999
@@ -45,6 +45,7 @@
 extern int tflag;		/* print packet arrival time */
 extern int vflag;		/* verbose */
 extern int xflag;		/* print packet in hex */
+extern int zflag;		/* print packet in ascii */
 
 extern int packettype;		/* as specified by -T */
 #define PT_VAT		1	/* Visual Audio Tool */
diff -ur tcpdump/print-atm.c tcpdump-fanf/print-atm.c
--- tcpdump/print-atm.c	Tue Sep 15 20:46:59 1998
+++ tcpdump-fanf/print-atm.c	Thu Sep 16 22:36:51 1999
@@ -151,12 +151,14 @@
 			       p[0], p[1], p[2], /* dsap/ssap/ctrl */
 			       p[3], p[4], p[5], /* manufacturer's code */
 			       ethertype);
-		if (!xflag && !qflag)
+		if (!xflag && !qflag && !zflag)
 		    /* default_print(p, caplen); */
 		    llc_print(p-8,length+8,caplen+8,"000000","000000");
 	}
 	if (xflag)
 		default_print(p, caplen);
+	if (zflag)
+		ascii_print(p, caplen);
  out:
 	putchar('\n');
 }
diff -ur tcpdump/print-ether.c tcpdump-fanf/print-ether.c
--- tcpdump/print-ether.c	Tue Sep 15 20:46:59 1998
+++ tcpdump-fanf/print-ether.c	Thu Sep 16 22:34:02 1999
@@ -126,18 +126,20 @@
 				printf("(LLC %s) ",
 			       etherproto_string(htons(extracted_ethertype)));
 			}
-			if (!xflag && !qflag)
+			if (!xflag && !qflag && !zflag)
 				default_print(p, caplen);
 		}
 	} else if (ether_encap_print(ether_type, p, length, caplen) == 0) {
 		/* ether_type not known, print raw packet */
 		if (!eflag)
 			ether_print((u_char *)ep, length + sizeof(*ep));
-		if (!xflag && !qflag)
+		if (!xflag && !qflag && !zflag)
 			default_print(p, caplen);
 	}
 	if (xflag)
 		default_print(p, caplen);
+	if (zflag)
+		ascii_print(p, caplen);
  out:
 	putchar('\n');
 }
diff -ur tcpdump/print-fddi.c tcpdump-fanf/print-fddi.c
--- tcpdump/print-fddi.c	Tue Sep 15 20:46:59 1998
+++ tcpdump-fanf/print-fddi.c	Thu Sep 16 22:34:02 1999
@@ -318,7 +318,7 @@
 				printf("(LLC %s) ",
 			etherproto_string(htons(extracted_ethertype)));
 			}
-			if (!xflag && !qflag)
+			if (!xflag && !qflag && !zflag)
 				default_print(p, caplen);
 		}
 	} else if ((fddip->fddi_fc & FDDIFC_CLFF) == FDDIFC_SMT)
@@ -327,11 +327,13 @@
 		/* Some kinds of FDDI packet we cannot handle intelligently */
 		if (!eflag)
 			fddi_print(fddip, length, ESRC(&ehdr), EDST(&ehdr));
-		if (!xflag && !qflag)
+		if (!xflag && !qflag && !zflag)
 			default_print(p, caplen);
 	}
 	if (xflag)
 		default_print(p, caplen);
+	if (zflag)
+		ascii_print(p, caplen);
 out:
 	putchar('\n');
 }
diff -ur tcpdump/print-fr.c tcpdump-fanf/print-fr.c
--- tcpdump/print-fr.c	Thu Jan  1 04:13:43 1998
+++ tcpdump-fanf/print-fr.c	Thu Sep 16 22:38:16 1999
@@ -240,13 +240,16 @@
 	default:
 		if(!eflag)
 			fr_hdlc_print(p, length);
-		if(!xflag)
+		if(!xflag && !zflag)
 			default_print((const u_char *)(p + LAYER2_LEN(p)),
 					caplen - LAYER2_LEN(p));
 	}
 
 	if (xflag)
 		default_print((const u_char *)(p + LAYER2_LEN(p)),
+				caplen - LAYER2_LEN(p));
+	if (zflag)
+		ascii_print((const u_char *)(p + LAYER2_LEN(p)),
 				caplen - LAYER2_LEN(p));
 out:
 	putchar('\n');
diff -ur tcpdump/print-null.c tcpdump-fanf/print-null.c
--- tcpdump/print-null.c	Tue Sep 15 20:46:59 1998
+++ tcpdump-fanf/print-null.c	Thu Sep 16 22:34:02 1999
@@ -118,6 +118,8 @@
 
 	if (xflag)
 		default_print((const u_char *)ip, caplen - NULL_HDRLEN);
+	if (zflag)
+		ascii_print((const u_char *)ip, caplen - NULL_HDRLEN);
 	putchar('\n');
 }
 
diff -ur tcpdump/print-ppp.c tcpdump-fanf/print-ppp.c
--- tcpdump/print-ppp.c	Tue Sep 15 20:46:59 1998
+++ tcpdump-fanf/print-ppp.c	Thu Sep 16 22:37:06 1999
@@ -521,7 +521,7 @@
 	default:
 		if(!eflag)
 			ppp_hdlc_print(p, length);
-		if(!xflag)
+		if(!xflag && !zflag)
 			default_print((const u_char *)(p + PPP_HDRLEN),
 					caplen - PPP_HDRLEN);
 	}
@@ -529,6 +529,9 @@
 	if (xflag)
 		default_print((const u_char *)(p + PPP_HDRLEN),
 				caplen - PPP_HDRLEN);
+	if (zflag)
+		ascii_print((const u_char *)(p + PPP_HDRLEN),
+				caplen - PPP_HDRLEN);
 out:
 	putchar('\n');
 }
@@ -606,6 +609,8 @@
 
 	if (xflag)
 		default_print((const u_char *)p, caplen - hdrlength);
+	if (zflag)
+		ascii_print((const u_char *)p, caplen - hdrlength);
 out:
 	putchar('\n');
 }
diff -ur tcpdump/print-raw.c tcpdump-fanf/print-raw.c
--- tcpdump/print-raw.c	Tue Sep 15 20:36:30 1998
+++ tcpdump-fanf/print-raw.c	Thu Sep 16 22:34:02 1999
@@ -84,5 +84,7 @@
 
 	if (xflag)
 		default_print(p, caplen);
+	if (zflag)
+		ascii_print(p, caplen);
 	putchar('\n');
 }
diff -ur tcpdump/print-sl.c tcpdump-fanf/print-sl.c
--- tcpdump/print-sl.c	Tue Sep 15 20:46:59 1998
+++ tcpdump-fanf/print-sl.c	Thu Sep 16 22:34:03 1999
@@ -108,6 +108,8 @@
 
 	if (xflag)
 		default_print((u_char *)ip, caplen - SLIP_HDRLEN);
+	if (zflag)
+		ascii_print((u_char *)ip, caplen - SLIP_HDRLEN);
  out:
 	putchar('\n');
 }
@@ -147,6 +149,8 @@
 
 	if (xflag)
 		default_print((u_char *)ip, caplen - SLIP_HDRLEN);
+	if (zflag)
+		ascii_print((u_char *)ip, caplen - SLIP_HDRLEN);
  out:
 	putchar('\n');
 }
diff -ur tcpdump/print-token.c tcpdump-fanf/print-token.c
--- tcpdump/print-token.c	Thu May 27 04:06:53 1999
+++ tcpdump-fanf/print-token.c	Thu Sep 16 22:38:48 1999
@@ -155,11 +155,13 @@
 			printf("(LLC %s) ",
 		       etherproto_string(htons(extracted_ethertype)));
 		}
-		if (!xflag && !qflag)
+		if (!xflag && !qflag && !zflag)
 			default_print(p, caplen);
 	}
 	if (xflag)
 		default_print(p, caplen);
+	if (zflag)
+		ascii_print(p, caplen);
  out:
 	putchar('\n');
 }
diff -ur tcpdump/tcpdump.1 tcpdump-fanf/tcpdump.1
--- tcpdump/tcpdump.1	Tue Dec 29 02:53:08 1998
+++ tcpdump-fanf/tcpdump.1	Thu Sep 16 22:34:03 1999
@@ -215,6 +215,12 @@
 The smaller of the entire packet or
 .I snaplen
 bytes will be printed.
+.TP
+.B \-z
+Print each packet (minus its link level header) in ascii.
+The smaller of the entire packet or
+.I snaplen
+bytes will be printed.
 .IP "\fI expression\fP"
 .RS
 selects which packets will be dumped.  If no \fIexpression\fP
diff -ur tcpdump/tcpdump.c tcpdump-fanf/tcpdump.c
--- tcpdump/tcpdump.c	Thu May 27 04:06:55 1999
+++ tcpdump-fanf/tcpdump.c	Thu Sep 16 22:34:03 1999
@@ -46,6 +46,7 @@
 #include <stdlib.h>
 #include <string.h>
 #include <unistd.h>
+#include <ctype.h>
 
 #include "interface.h"
 #include "addrtoname.h"
@@ -66,6 +67,7 @@
 int tflag = 1;			/* print packet arrival time */
 int vflag;			/* verbose */
 int xflag;			/* print packet in hex */
+int zflag;			/* print packet in ascii */
 
 int packettype;
 
@@ -149,7 +151,7 @@
 
 	opterr = 0;
 	while (
-	    (op = getopt(argc, argv, "ac:defF:i:lnNOpqr:s:StT:vw:xY")) != EOF)
+	    (op = getopt(argc, argv, "ac:defF:i:lnNOpqr:s:StT:vw:xYz")) != EOF)
 		switch (op) {
 
 		case 'a':
@@ -263,6 +265,10 @@
 			++xflag;
 			break;
 
+		case 'z':
+			++zflag;
+			break;
+
 		default:
 			usage();
 			/* NOTREACHED */
@@ -408,6 +414,12 @@
  *
  * (BTW, please don't send us patches to print the packet out in ascii)
  */
+/*
+ * The developers of tcpdump are fascist bastards.
+ * (And fuckwits, too. (void)printf("foo")? Bunch of arse.
+ * They should be writing if (printf("foo") < 0)
+ * { perror("stdout"); exit(EXIT_FAILURE); }
+ */
 void
 default_print(register const u_char *bp, register u_int length)
 {
@@ -432,6 +444,35 @@
 			(void)printf("\n\t\t\t");
 		(void)printf(" %02x", *(u_char *)sp);
 	}
+}
+
+/*
+ * print the packet out in ascii
+ */
+void
+ascii_print(register const u_char *bp, register int length)
+{
+	register u_int i, j;
+
+	for (i = 0; i < length; i += 16, bp += 16) {
+		fputs("\n ", stdout);
+		for (j = 0; j < 16; j++) {
+			if (i + j < length)
+				printf(" %02X", bp[j]);
+			else
+				printf("   ");
+			if (j % 4 == 3)
+				fputs("  ", stdout);
+		}
+		fputs("  ", stdout);
+		for (j = 0; j < 16; j++) {
+			if (i + j < length)
+				putchar(isprint(bp[j]) ? bp[j] : '.');
+			if (j % 4 == 3)
+				putchar(' ');
+		}
+	}
+	putchar('\n');
 }
 
 __dead void

>Release-Note:
>Audit-Trail:
>Unformatted:


To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-bugs" in the body of the message




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?199909162207.XAA16067>