adds support for -A for tcpdump, to print captured text without the
hex dump. can be useful if you're watching text-based protocols like
HTTP or SIP. tcpdump.org uses the same flag (this isn't their code
though).
comments? OK?
Index: tcpdump.8
===================================================================
RCS file: /cvs/src/usr.sbin/tcpdump/tcpdump.8,v
retrieving revision 1.75
diff -u -p -r1.75 tcpdump.8
--- tcpdump.8 28 Mar 2011 09:37:03 -0000 1.75
+++ tcpdump.8 10 Jul 2012 17:22:47 -0000
@@ -28,7 +28,7 @@
.Sh SYNOPSIS
.Nm tcpdump
.Bk -words
-.Op Fl adefILlNnOopqStvXx
+.Op Fl AadefILlNnOopqStvXx
.Op Fl c Ar count
.Op Fl D Ar direction
.Oo Fl E Oo Ar espalg : Oc Ns
@@ -51,6 +51,14 @@ You must have read access to
.Pp
The options are as follows:
.Bl -tag -width "-c count"
+.It Fl A
+Print each packet in ASCII.
+If the
+.Fl e
+option is also specified, the link-level header will be included.
+The smaller of the entire packet or
+.Ar snaplen
+bytes will be printed.
.It Fl a
Attempt to convert network and broadcast addresses to names.
.It Fl c Ar count
Index: tcpdump.c
===================================================================
RCS file: /cvs/src/usr.sbin/tcpdump/tcpdump.c,v
retrieving revision 1.63
diff -u -p -r1.63 tcpdump.c
--- tcpdump.c 26 Jun 2010 16:47:07 -0000 1.63
+++ tcpdump.c 10 Jul 2012 17:22:47 -0000
@@ -59,6 +59,7 @@
#include "pfctl_parser.h"
#include "privsep.h"
+int Aflag; /* dump ascii */
int aflag; /* translate network and broadcast addresses */
int dflag; /* print filter code */
int eflag; /* print ethernet header */
@@ -228,9 +229,14 @@ main(int argc, char **argv)
opterr = 0;
while ((op = getopt(argc, argv,
- "ac:D:deE:fF:i:IlLnNOopqr:s:StT:vw:xXy:Y")) != -1)
+ "Aac:D:deE:fF:i:IlLnNOopqr:s:StT:vw:xXy:Y")) != -1)
switch (op) {
+ case 'A':
+ if (xflag == 0) ++xflag;
+ ++Aflag;
+ break;
+
case 'a':
++aflag;
break;
@@ -597,6 +603,20 @@ default_print_hexl(const u_char *cp, uns
}
}
+/* dump the text from the buffer */
+void
+default_print_ascii(const u_char *cp, unsigned int length, unsigned int offset)
+{
+ int c, i;
+
+ printf("\n");
+ for (i = 0; i < length; i++) {
+ c = cp[i];
+ c = isprint(c) || isspace(c) ? c : '.';
+ putchar(c);
+ }
+}
+
/* Like default_print() but data need not be aligned */
void
default_print_unaligned(register const u_char *cp, register u_int length)
@@ -607,6 +627,9 @@ default_print_unaligned(register const u
if (Xflag) {
/* dump the buffer in `emacs-hexl' style */
default_print_hexl(cp, length, 0);
+ } else if (Aflag) {
+ /* dump the text in the buffer */
+ default_print_ascii(cp, length, 0);
} else {
/* dump the buffer in old tcpdump style */
nshorts = (u_int) length / sizeof(u_short);
@@ -635,6 +658,9 @@ default_print(register const u_char *bp,
if (Xflag) {
/* dump the buffer in `emacs-hexl' style */
default_print_hexl(bp, length, 0);
+ } else if (Aflag) {
+ /* dump the text in the buffer */
+ default_print_ascii(bp, length, 0);
} else {
/* dump the buffer in old tcpdump style */
if ((long)bp & 1) {
@@ -674,7 +700,7 @@ __dead void
usage(void)
{
(void)fprintf(stderr,
-"Usage: %s [-adefILlNnOopqStvXx] [-c count] [-D direction]\n",
+"Usage: %s [-AadefILlNnOopqStvXx] [-c count] [-D direction]\n",
program_name);
(void)fprintf(stderr,
"\t [-E [espalg:]espkey] [-F file] [-i interface] [-r file]\n");