diff options
author | Stuart Henderson <sthen@cvs.openbsd.org> | 2012-07-10 18:07:38 +0000 |
---|---|---|
committer | Stuart Henderson <sthen@cvs.openbsd.org> | 2012-07-10 18:07:38 +0000 |
commit | 139829c0fe6bccb7b6b45b0aa41515f1b0babb43 (patch) | |
tree | 1ecc4fc502091410695a242abb465bb1a2f71b1d /usr.sbin | |
parent | e0f927cd805537c6cef79fd83e52285421193570 (diff) |
support -A to print the ascii text of captured packets. ok deraadt@
Diffstat (limited to 'usr.sbin')
-rw-r--r-- | usr.sbin/tcpdump/tcpdump.8 | 14 | ||||
-rw-r--r-- | usr.sbin/tcpdump/tcpdump.c | 32 |
2 files changed, 40 insertions, 6 deletions
diff --git a/usr.sbin/tcpdump/tcpdump.8 b/usr.sbin/tcpdump/tcpdump.8 index 43a64ff74df..848309a0107 100644 --- a/usr.sbin/tcpdump/tcpdump.8 +++ b/usr.sbin/tcpdump/tcpdump.8 @@ -1,4 +1,4 @@ -.\" $OpenBSD: tcpdump.8,v 1.75 2011/03/28 09:37:03 jmc Exp $ +.\" $OpenBSD: tcpdump.8,v 1.76 2012/07/10 18:07:37 sthen Exp $ .\" .\" Copyright (c) 1987, 1988, 1989, 1990, 1991, 1992, 1994, 1995, 1996 .\" The Regents of the University of California. All rights reserved. @@ -19,7 +19,7 @@ .\" WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF .\" MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. .\" -.Dd $Mdocdate: March 28 2011 $ +.Dd $Mdocdate: July 10 2012 $ .Dt TCPDUMP 8 .Os .Sh NAME @@ -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 diff --git a/usr.sbin/tcpdump/tcpdump.c b/usr.sbin/tcpdump/tcpdump.c index 2298c8e2de1..ecd42fd1dfa 100644 --- a/usr.sbin/tcpdump/tcpdump.c +++ b/usr.sbin/tcpdump/tcpdump.c @@ -1,4 +1,4 @@ -/* $OpenBSD: tcpdump.c,v 1.63 2010/06/26 16:47:07 henning Exp $ */ +/* $OpenBSD: tcpdump.c,v 1.64 2012/07/10 18:07:37 sthen Exp $ */ /* * Copyright (c) 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997 @@ -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, unsigned int length, unsigned int offset) } } +/* 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_char *cp, register u_int length) 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, register u_int length) 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"); |