* WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
*
- * @(#) $Header: /tcpdump/master/tcpdump/interface.h,v 1.255 2005-06-20 07:39:21 hannes Exp $ (LBL)
+ * @(#) $Header: /tcpdump/master/tcpdump/interface.h,v 1.256 2005-07-06 20:53:30 guy Exp $ (LBL)
*/
#ifndef tcpdump_interface_h
#include <pcap.h>
extern int print_unknown_data(const u_char *, const char *,int);
-extern void ascii_print_with_offset(const char *, const u_char *, u_int, u_int);
-extern void ascii_print(const char *, const u_char *, u_int);
+extern void ascii_print(const u_char *, u_int);
+extern void hex_and_ascii_print_with_offset(const char *, const u_char *,
+ u_int, u_int);
+extern void hex_and_ascii_print(const char *, const u_char *, u_int);
extern void hex_print_with_offset(const char *, const u_char *, u_int, u_int);
-extern void telnet_print(const u_char *, u_int);
extern void hex_print(const char *, const u_char *, u_int);
+extern void telnet_print(const u_char *, u_int);
extern int ether_encap_print(u_short, const u_char *, u_int, u_int, u_short *);
extern int llc_print(const u_char *, u_int, u_int, const u_char *,
const u_char *, u_short *);
* WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
*
- * @(#) $Header: /tcpdump/master/tcpdump/netdissect.h,v 1.16 2005-04-07 00:28:17 mcr Exp $ (LBL)
+ * @(#) $Header: /tcpdump/master/tcpdump/netdissect.h,v 1.17 2005-07-06 20:53:31 guy Exp $ (LBL)
*/
#ifndef netdissect_h
/* stuff that has not yet been rototiled */
#if 0
-extern void ascii_print_with_offset(netdissect_options *, const char *,
- u_int, u_int);
-extern void ascii_print(netdissect_options *,const char *, u_int);
+extern void ascii_print(netdissect_options *,u_int);
+extern void hex_and_ascii_print_with_offset(netdissect_options *,const char *,
+ u_int, u_int);
+extern void hex_and_ascii_print(netdissect_options *,const char *, u_int);
extern void hex_print_with_offset(netdissect_options *,const char *,
- u_int, u_int);
-extern void telnet_print(netdissect_options *,const u_char *, u_int);
-extern void hex_print(netdissect_options *,const char *, u_int);
+ u_int, u_int);
+extern void hex_print(netdissect_options *,const char *, u_int);
+extern void telnet_print(netdissect_options *,const u_char *, u_int);
extern int ether_encap_print(netdissect_options *,u_short, const u_char *,
u_int, u_int, u_short *);
extern int llc_print(netdissect_options *,
#ifndef lint
static const char rcsid[] _U_ =
- "@(#) $Header: /tcpdump/master/tcpdump/print-ascii.c,v 1.16 2004-07-21 22:00:10 guy Exp $";
+ "@(#) $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>
(HEXDUMP_HEXSTUFF_PER_SHORT * HEXDUMP_SHORTS_PER_LINE)
void
-ascii_print_with_offset(register const char *ident, register const u_char *cp, register u_int length,
- register u_int oset)
+ascii_print(register const u_char *cp, register u_int length)
+{
+ register int s;
+
+ putchar('\n');
+ while (length > 0) {
+ s = *cp++;
+ length--;
+ if (!isgraph(s) &&
+ (s != '\t' && s != ' ' && s != '\n' && s != '\r'))
+ putchar('.');
+ else
+ putchar(s);
+ }
+}
+
+void
+hex_and_ascii_print_with_offset(register const char *ident,
+ register const u_char *cp, register u_int length, register u_int oset)
{
register u_int i;
register int s1, s2;
register int nshorts;
char hexstuff[HEXDUMP_SHORTS_PER_LINE*HEXDUMP_HEXSTUFF_PER_SHORT+1], *hsp;
char asciistuff[ASCII_LINELENGTH+1], *asp;
- u_int maxlength = (Aflag ? ASCII_LINELENGTH : HEXDUMP_SHORTS_PER_LINE);
nshorts = length / sizeof(u_short);
i = 0;
hsp = hexstuff; asp = asciistuff;
- if (Aflag) *(asp++) = '\n';
while (--nshorts >= 0) {
s1 = *cp++;
s2 = *cp++;
- if (Aflag) {
- i += 2;
- *(asp++) = (isgraph(s1) ? s1 : (s1 != '\t' && s1 != ' ' && s1 != '\n' && s1 != '\r' ? '.' : s1) );
- *(asp++) = (isgraph(s2) ? s2 : (s2 != '\t' && s2 != ' ' && s2 != '\n' && s2 != '\r' ? '.' : s2) );
- if (s1 == '\n' || s2 == '\n') i = maxlength;
-
- } else {
- (void)snprintf(hsp, sizeof(hexstuff) - (hsp - hexstuff),
- " %02x%02x", s1, s2);
- hsp += HEXDUMP_HEXSTUFF_PER_SHORT;
- *(asp++) = (isgraph(s1) ? s1 : '.');
- *(asp++) = (isgraph(s2) ? s2 : '.');
- i++;
- }
- if (i >= maxlength) {
+ (void)snprintf(hsp, sizeof(hexstuff) - (hsp - hexstuff),
+ " %02x%02x", s1, s2);
+ hsp += HEXDUMP_HEXSTUFF_PER_SHORT;
+ *(asp++) = (isgraph(s1) ? s1 : '.');
+ *(asp++) = (isgraph(s2) ? s2 : '.');
+ i++;
+ if (i >= HEXDUMP_SHORTS_PER_LINE) {
*hsp = *asp = '\0';
- if (Aflag) {
- (void)printf("%s", asciistuff);
- } else {
- (void)printf("%s0x%04x: %-*s %s",
- ident, oset, HEXDUMP_HEXSTUFF_PER_LINE,
- hexstuff, asciistuff);
- }
+ (void)printf("%s0x%04x: %-*s %s",
+ ident, oset, HEXDUMP_HEXSTUFF_PER_LINE,
+ hexstuff, asciistuff);
i = 0; hsp = hexstuff; asp = asciistuff;
oset += HEXDUMP_BYTES_PER_LINE;
}
}
if (length & 1) {
s1 = *cp++;
- if (Aflag) {
- *(asp++) = (isgraph(s1) ? s1 : (s1 != '\t' && s1 != ' ' && s1 != '\n' && s1 != '\r' ? '.' : s1) );
- } else {
- (void)snprintf(hsp, sizeof(hexstuff) - (hsp - hexstuff),
- " %02x", s1);
- hsp += 3;
- *(asp++) = (isgraph(s1) ? s1 : '.');
- }
+ (void)snprintf(hsp, sizeof(hexstuff) - (hsp - hexstuff),
+ " %02x", s1);
+ hsp += 3;
+ *(asp++) = (isgraph(s1) ? s1 : '.');
++i;
}
if (i > 0) {
*hsp = *asp = '\0';
- if (Aflag) {
- (void)printf("%s%s", ident, asciistuff);
- } else {
- (void)printf("%s0x%04x: %-*s %s",
- ident, oset, HEXDUMP_HEXSTUFF_PER_LINE,
- hexstuff, asciistuff);
- }
+ (void)printf("%s0x%04x: %-*s %s",
+ ident, oset, HEXDUMP_HEXSTUFF_PER_LINE,
+ hexstuff, asciistuff);
}
}
void
-ascii_print(register const char *ident, register const u_char *cp, register u_int length)
+hex_and_ascii_print(register const char *ident, register const u_char *cp,
+ register u_int length)
{
- ascii_print_with_offset(ident, cp, length, 0);
+ hex_and_ascii_print_with_offset(ident, cp, length, 0);
}
/*
int
main(int argc, char *argv[])
{
- hex_print("Hello, World!\n", 14);
+ hex_print("\n\t", "Hello, World!\n", 14);
+ printf("\n");
+ hex_and_ascii_print("\n\t", "Hello, World!\n", 14);
printf("\n");
ascii_print("Hello, World!\n", 14);
printf("\n");
#define TMSG "Now is the winter of our discontent...\n"
- ascii_print_with_offset(TMSG, sizeof(TMSG) - 1, 0x100);
+ hex_print_with_offset("\n\t", TMSG, sizeof(TMSG) - 1, 0x100);
+ printf("\n");
+ hex_and_ascii_print_with_offset("\n\t", TMSG, sizeof(TMSG) - 1, 0x100);
printf("\n");
exit(0);
}
#endif /* MAIN */
-
-
"@(#) Copyright (c) 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997, 2000\n\
The Regents of the University of California. All rights reserved.\n";
static const char rcsid[] _U_ =
- "@(#) $Header: /tcpdump/master/tcpdump/tcpdump.c,v 1.258 2005-06-03 22:08:53 guy Exp $ (LBL)";
+ "@(#) $Header: /tcpdump/master/tcpdump/tcpdump.c,v 1.259 2005-07-06 20:53:32 guy Exp $ (LBL)";
#endif
/*
break;
case 'A':
- ++xflag;
- ++Xflag;
++Aflag;
break;
snapend = sp + h->caplen;
hdrlen = (*print_info->printer)(h, sp);
- if (xflag) {
+ if (Xflag) {
/*
- * Print the raw packet data.
+ * Print the raw packet data in hex and ASCII.
+ */
+ if (Xflag > 1) {
+ /*
+ * Include the link-layer header.
+ */
+ hex_and_ascii_print("\n\t", sp, h->caplen);
+ } else {
+ /*
+ * Don't include the link-layer header - and if
+ * we have nothing past the link-layer header,
+ * print nothing.
+ */
+ if (h->caplen > hdrlen)
+ hex_and_ascii_print("\n\t", sp + hdrlen,
+ h->caplen - hdrlen);
+ }
+ } else if (xflag) {
+ /*
+ * Print the raw packet data in hex.
*/
if (xflag > 1) {
/*
hex_print("\n\t", sp + hdrlen,
h->caplen - hdrlen);
}
- } else if (Xflag) {
+ } else if (Aflag) {
/*
- * Print the raw packet data.
+ * Print the raw packet data in ASCII.
*/
- if (Xflag > 1) {
+ if (Aflag > 1) {
/*
* Include the link-layer header.
*/
- ascii_print("\n\t", sp, h->caplen);
+ ascii_print(sp, h->caplen);
} else {
/*
* Don't include the link-layer header - and if
* print nothing.
*/
if (h->caplen > hdrlen)
- ascii_print("\n\t", sp + hdrlen,
- h->caplen - hdrlen);
+ ascii_print(sp + hdrlen, h->caplen - hdrlen);
}
}
#endif
/*
- * By default, print the specified data out in hex.
+ * By default, print the specified data out in hex and ASCII.
*/
static void
ndo_default_print(netdissect_options *ndo _U_, const u_char *bp, u_int length)
{
- ascii_print("\n\t", bp, length); /* pass on lf and identation string */
+ hex_and_ascii_print("\n\t", bp, length); /* pass on lf and identation string */
}
void