Date: Wed, 2 Aug 1995 11:51:47 +0900 From: Toshihiro Kanda <candy@fct.kgc.co.jp> To: FreeBSD-gnats-submit@freebsd.org Cc: candy@fct.kgc.co.jp Subject: bin/649: tcpdump(1) doesn't show AppleTalk packets correctly Message-ID: <199508020251.LAA28681@xxx.fct.kgc.co.jp> Resent-Message-ID: <199508020420.VAA03428@freefall.cdrom.com>
next in thread | raw e-mail | index | archive | help
>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 <netinet/in.h> #include <pcap.h> +#include <ctype.h> #include <signal.h> #include <stdio.h> #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:
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?199508020251.LAA28681>