From owner-freebsd-bugs Tue Aug 1 21:20:02 1995 Return-Path: bugs-owner Received: (from majordom@localhost) by freefall.cdrom.com (8.6.11/8.6.6) id VAA03438 for bugs-outgoing; Tue, 1 Aug 1995 21:20:02 -0700 Received: (from gnats@localhost) by freefall.cdrom.com (8.6.11/8.6.6) id VAA03428 ; Tue, 1 Aug 1995 21:20:01 -0700 Resent-Date: Tue, 1 Aug 1995 21:20:01 -0700 Resent-Message-Id: <199508020420.VAA03428@freefall.cdrom.com> Resent-From: gnats (GNATS Management) Resent-To: freebsd-bugs Resent-Reply-To: FreeBSD-gnats@freefall.cdrom.com, candy@fct.kgc.co.jp Received: from mail0.iij.ad.jp (mail0.iij.ad.jp [192.244.176.61]) by freefall.cdrom.com (8.6.11/8.6.6) with ESMTP id VAA02920 for ; Tue, 1 Aug 1995 21:14:50 -0700 Received: from uucp0.iij.ad.jp (uucp0.iij.ad.jp [192.244.176.51]) by mail0.iij.ad.jp (8.6.12+2.4W/3.3W9-MAIL) with ESMTP id NAA21857 for ; Wed, 2 Aug 1995 13:14:47 +0900 Received: (from uucp@localhost) by uucp0.iij.ad.jp (8.6.12+2.4W/3.3W9-UUCP) with UUCP id NAA29080 for FreeBSD-gnats-submit@freebsd.org; Wed, 2 Aug 1995 13:14:50 +0900 Received: from xxx.fct.kgc.co.jp by fender.fct.kgc.co.jp (8.6.12+2.4W/3.4W:95071117) id LAA13408; Wed, 2 Aug 1995 11:51:47 +0900 Received: by xxx.fct.kgc.co.jp (8.6.12+2.4W/3.3W8:95062916) id LAA28681; Wed, 2 Aug 1995 11:51:47 +0900 Message-Id: <199508020251.LAA28681@xxx.fct.kgc.co.jp> Date: Wed, 2 Aug 1995 11:51:47 +0900 From: Toshihiro Kanda Reply-To: candy@fct.kgc.co.jp To: FreeBSD-gnats-submit@freebsd.org Cc: candy@fct.kgc.co.jp X-Send-Pr-Version: 3.2 Subject: bin/649: tcpdump(1) doesn't show AppleTalk packets correctly Sender: bugs-owner@freebsd.org Precedence: bulk >Number: 649 >Category: bin >Synopsis: tcpdump(1) doesn't show AppleTalk packets correctly >Confidential: no >Severity: non-critical >Priority: low >Responsible: freebsd-bugs >State: open >Class: sw-bug >Submitter-Id: current-users >Arrival-Date: Tue Aug 1 21:20:01 PDT 1995 >Last-Modified: >Originator: candy@fct.kgc.co.jp (Toshihiro Kanda) >Organization: Keisokugiken corp. >Release: FreeBSD 2.0-BUILT-19950603 i386 >Environment: Kernel configured with bpf. $ uname -rms FreeBSD 2.0.5-RELEASE i386 >Description: tcpdump(1) doesn't show AppleTalk (EtherTalk) packets. EtherTalk don't have LAP header, though I don't know about IPTalk. >How-To-Repeat: $ tcpdump 'ether[14]==0xaa' >Fix: Here are three modification: 1) fixes above. 2) shows appletalk address in hex. 3) adds option '-xx' which makes tcpdump dump with characters. --- usr/src/usr.sbin/tcpdump/tcpdump/tcpdump.c.orig 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.orig 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)); } >Audit-Trail: >Unformatted: