summaryrefslogtreecommitdiffstats
path: root/contrib/tcpdump/print-ascii.c
diff options
context:
space:
mode:
authordelphij <delphij@FreeBSD.org>2015-01-07 19:55:18 +0000
committerdelphij <delphij@FreeBSD.org>2015-01-07 19:55:18 +0000
commitf49c5d523af9076a4a59e8dd664f9a897108432e (patch)
treee268839e08c106e178b33bd461d8d0a9c6fb5ad9 /contrib/tcpdump/print-ascii.c
parentc371846049d370ab78d943e60e789cdffe0aad3d (diff)
parent08263d19579d35a7a65e0c8bcb768504ce76d04e (diff)
downloadFreeBSD-src-f49c5d523af9076a4a59e8dd664f9a897108432e.zip
FreeBSD-src-f49c5d523af9076a4a59e8dd664f9a897108432e.tar.gz
MFV r276761: tcpdump 4.6.2.
MFC after: 1 month
Diffstat (limited to 'contrib/tcpdump/print-ascii.c')
-rw-r--r--contrib/tcpdump/print-ascii.c75
1 files changed, 44 insertions, 31 deletions
diff --git a/contrib/tcpdump/print-ascii.c b/contrib/tcpdump/print-ascii.c
index fa8793cb..96410da 100644
--- a/contrib/tcpdump/print-ascii.c
+++ b/contrib/tcpdump/print-ascii.c
@@ -36,14 +36,11 @@
* POSSIBILITY OF SUCH DAMAGE.
*/
+#define NETDISSECT_REWORKED
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
-#ifndef lint
-static const char rcsid[] _U_ =
- "@(#) $Header: /tcpdump/master/tcpdump/print-ascii.c,v 1.17 2005-07-06 20:53:32 guy Exp $";
-#endif
#include <tcpdump-stdinc.h>
#include <stdio.h>
@@ -57,24 +54,39 @@ static const char rcsid[] _U_ =
(HEXDUMP_HEXSTUFF_PER_SHORT * HEXDUMP_SHORTS_PER_LINE)
void
-ascii_print(register const u_char *cp, register u_int length)
+ascii_print(netdissect_options *ndo,
+ const u_char *cp, u_int length)
{
- register int s;
+ register u_char s;
- putchar('\n');
+ ND_PRINT((ndo, "\n"));
while (length > 0) {
s = *cp++;
length--;
- if (!isgraph(s) &&
- (s != '\t' && s != ' ' && s != '\n' && s != '\r'))
- putchar('.');
- else
- putchar(s);
+ if (s == '\r') {
+ /*
+ * Don't print CRs at the end of the line; they
+ * don't belong at the ends of lines on UN*X,
+ * and the standard I/O library will give us one
+ * on Windows so we don't need to print one
+ * ourselves.
+ *
+ * In the middle of a line, just print a '.'.
+ */
+ if (length > 1 && *cp != '\n')
+ ND_PRINT((ndo, "."));
+ } else {
+ if (!ND_ISGRAPH(s) &&
+ (s != '\t' && s != ' ' && s != '\n'))
+ ND_PRINT((ndo, "."));
+ else
+ ND_PRINT((ndo, "%c", s));
+ }
}
}
void
-hex_and_ascii_print_with_offset(register const char *ident,
+hex_and_ascii_print_with_offset(netdissect_options *ndo, register const char *ident,
register const u_char *cp, register u_int length, register u_int oset)
{
register u_int i;
@@ -92,14 +104,14 @@ hex_and_ascii_print_with_offset(register const char *ident,
(void)snprintf(hsp, sizeof(hexstuff) - (hsp - hexstuff),
" %02x%02x", s1, s2);
hsp += HEXDUMP_HEXSTUFF_PER_SHORT;
- *(asp++) = (isgraph(s1) ? s1 : '.');
- *(asp++) = (isgraph(s2) ? s2 : '.');
+ *(asp++) = (ND_ISGRAPH(s1) ? s1 : '.');
+ *(asp++) = (ND_ISGRAPH(s2) ? s2 : '.');
i++;
if (i >= HEXDUMP_SHORTS_PER_LINE) {
*hsp = *asp = '\0';
- (void)printf("%s0x%04x: %-*s %s",
+ ND_PRINT((ndo, "%s0x%04x: %-*s %s",
ident, oset, HEXDUMP_HEXSTUFF_PER_LINE,
- hexstuff, asciistuff);
+ hexstuff, asciistuff));
i = 0; hsp = hexstuff; asp = asciistuff;
oset += HEXDUMP_BYTES_PER_LINE;
}
@@ -109,30 +121,31 @@ hex_and_ascii_print_with_offset(register const char *ident,
(void)snprintf(hsp, sizeof(hexstuff) - (hsp - hexstuff),
" %02x", s1);
hsp += 3;
- *(asp++) = (isgraph(s1) ? s1 : '.');
+ *(asp++) = (ND_ISGRAPH(s1) ? s1 : '.');
++i;
}
if (i > 0) {
*hsp = *asp = '\0';
- (void)printf("%s0x%04x: %-*s %s",
+ ND_PRINT((ndo, "%s0x%04x: %-*s %s",
ident, oset, HEXDUMP_HEXSTUFF_PER_LINE,
- hexstuff, asciistuff);
+ hexstuff, asciistuff));
}
}
void
-hex_and_ascii_print(register const char *ident, register const u_char *cp,
- register u_int length)
+hex_and_ascii_print(netdissect_options *ndo, register const char *ident,
+ register const u_char *cp, register u_int length)
{
- hex_and_ascii_print_with_offset(ident, cp, length, 0);
+ hex_and_ascii_print_with_offset(ndo, ident, cp, length, 0);
}
/*
* telnet_print() wants this. It is essentially default_print_unaligned()
*/
void
-hex_print_with_offset(register const char *ident, register const u_char *cp, register u_int length,
- register u_int oset)
+hex_print_with_offset(netdissect_options *ndo,
+ const char *ident, const u_char *cp, u_int length,
+ u_int oset)
{
register u_int i, s;
register int nshorts;
@@ -141,16 +154,16 @@ hex_print_with_offset(register const char *ident, register const u_char *cp, reg
i = 0;
while (--nshorts >= 0) {
if ((i++ % 8) == 0) {
- (void)printf("%s0x%04x: ", ident, oset);
+ ND_PRINT((ndo,"%s0x%04x: ", ident, oset));
oset += HEXDUMP_BYTES_PER_LINE;
}
s = *cp++;
- (void)printf(" %02x%02x", s, *cp++);
+ ND_PRINT((ndo," %02x%02x", s, *cp++));
}
if (length & 1) {
if ((i % 8) == 0)
- (void)printf("%s0x%04x: ", ident, oset);
- (void)printf(" %02x", *cp);
+ ND_PRINT((ndo,"%s0x%04x: ", ident, oset));
+ ND_PRINT((ndo," %02x", *cp));
}
}
@@ -158,9 +171,9 @@ hex_print_with_offset(register const char *ident, register const u_char *cp, reg
* just for completeness
*/
void
-hex_print(register const char *ident, register const u_char *cp, register u_int length)
+hex_print(netdissect_options *ndo,const char *ident, const u_char *cp, u_int length)
{
- hex_print_with_offset(ident, cp, length, 0);
+ hex_print_with_offset(ndo, ident, cp, length, 0);
}
#ifdef MAIN
OpenPOWER on IntegriCloud