--- usr/src/usr.sbin/tcpdump/tcpdump/tcpdump.c Tue May 30 12:52:39 1995 +++ usr/src/usr.sbin/tcpdump/tcpdump/tcpdump.c Wed Aug 2 10:42:55 1995 @@ -39,6 +39,7 @@ #include #include +#include #include #include #ifdef __STDC__ @@ -351,25 +352,58 @@ exit(0); } +static void +chardump(const char *s_, size_t n) +{ + register const unsigned char *s; + + s = s_; + printf(" /"); + while (n-- != 0) { + int c = *s++; + if (c < 0x20 || c == 0x7f || c >= 0xfd) + c = '.'; + putchar(c); + }/* while */ + putchar(' '); +} + + /* Like default_print() but data need not be aligned */ void default_print_unaligned(register const u_char *cp, register int length) { register u_int i, s; register int nshorts; + char *pp; + int out; + pp = (char *)cp; + out = 0; nshorts = (u_int) length / sizeof(u_short); i = 0; while (--nshorts >= 0) { if ((i++ % 8) == 0) - (void)printf("\n\t\t\t"); + (void)printf("\n\t\t"); s = *cp++; (void)printf(" %02x%02x", s, *cp++); + if ((xflag & 2) && (out += 2) == 16) { + chardump(pp, out); + pp += out; + out = 0; + } } if (length & 1) { if ((i % 8) == 0) - (void)printf("\n\t\t\t"); - (void)printf(" %02x", *cp); + (void)printf("\n\t\t"); + (void)printf(" %02x ", *cp); + out++; + } + if (xflag & 2) { + int j; + for (j = (out + 1) / 2 * 2; j < 16; j += 2) + printf(" "); + chardump(pp, out); } } @@ -379,7 +413,11 @@ register const u_short *sp; register u_int i; register int nshorts; + char *pp; + int out; + pp = (char *)bp; + out = 0; if ((int)bp & 1) { default_print_unaligned(bp, length); return; @@ -389,13 +427,25 @@ i = 0; while (--nshorts >= 0) { if ((i++ % 8) == 0) - (void)printf("\n\t\t\t"); + (void)printf("\n\t\t"); (void)printf(" %04x", ntohs(*sp++)); + if ((xflag & 2) && (out += 2) == 16) { + chardump(pp, out); + pp += out; + out = 0; + } } if (length & 1) { if ((i % 8) == 0) - (void)printf("\n\t\t\t"); - (void)printf(" %02x", *(u_char *)sp); + (void)printf("\n\t\t"); + (void)printf(" %02x ", *(u_char *)sp); + out++; + } + if (xflag & 2) { + int j; + for (j = (out + 1) / 2 * 2; j < 16; j += 2) + printf(" "); + chardump(pp, out); } } --- usr/src/usr.sbin/tcpdump/tcpdump/print-atalk.c Wed Aug 2 10:47:31 1995 +++ usr/src/usr.sbin/tcpdump/tcpdump/print-atalk.c Wed Aug 2 11:15:29 1995 @@ -100,9 +100,16 @@ register const struct atShortDDP *sdp; u_short snet; +#if 0 lp = (struct LAP *)bp; bp += sizeof(*lp); length -= sizeof(*lp); +#else + { + static struct LAP lp_ = {0, 0, lapDDP}; + lp = &lp_; + } +#endif switch (lp->type) { case lapShortDDP: @@ -532,7 +539,7 @@ if (tp2->addr == i) { tp->addr = (atnet << 8) | athost; tp->nxt = (struct hnamemem *)calloc(1, sizeof(*tp)); - (void)sprintf(nambuf, "%s.%d", tp2->name, athost); + (void)sprintf(nambuf, "%s.%02x", tp2->name, athost); tp->name = savestr(nambuf); return (tp->name); } @@ -540,10 +547,10 @@ tp->addr = (atnet << 8) | athost; tp->nxt = (struct hnamemem *)calloc(1, sizeof(*tp)); if (athost != 255) - (void)sprintf(nambuf, "%d.%d.%d", + (void)sprintf(nambuf, "%02x.%02x.%02x", atnet >> 8, atnet & 0xff, athost); else - (void)sprintf(nambuf, "%d.%d", atnet >> 8, atnet & 0xff); + (void)sprintf(nambuf, "%02x.%02x", atnet >> 8, atnet & 0xff); i = strlen(nambuf) + 1; tp->name = strcpy(malloc((u_int) i), nambuf); @@ -564,8 +571,8 @@ static char buf[8]; if (nflag) { - (void)sprintf(buf, "%d", skt); + (void)sprintf(buf, "%02x", skt); return (buf); } - return (tok2str(skt2str, "%d", skt)); + return (tok2str(skt2str, "%02x", skt)); }