X-Git-Url: https://git.tcpdump.org/tcpdump/blobdiff_plain/e11ed169b11242f2107d02cc3ec2ab5a77736bfb..f72fe0d0de6eb91663b005b7d061ecebb555d667:/print-atalk.c diff --git a/print-atalk.c b/print-atalk.c index b5d162c7..13848a11 100644 --- a/print-atalk.c +++ b/print-atalk.c @@ -23,7 +23,7 @@ #ifndef lint static const char rcsid[] = - "@(#) $Header: /tcpdump/master/tcpdump/print-atalk.c,v 1.61 2000-10-06 04:23:10 guy Exp $ (LBL)"; + "@(#) $Header: /tcpdump/master/tcpdump/print-atalk.c,v 1.71 2002-02-05 10:03:34 guy Exp $ (LBL)"; #endif #ifdef HAVE_CONFIG_H @@ -39,13 +39,14 @@ static const char rcsid[] = #include #include #include +#include /* for MAXHOSTNAMELEN on some platforms */ +#include #include "interface.h" #include "addrtoname.h" #include "ethertype.h" #include "extract.h" /* must come after interface.h */ #include "appletalk.h" -#include "savestr.h" static struct tok type2str[] = { { ddpRTMP, "rtmp" }, @@ -83,17 +84,43 @@ static void ddp_print(const u_char *, u_int, int, u_short, u_char, u_char); static const char *ddpskt_string(int); /* - * Print AppleTalk Datagram Delivery Protocol packets. + * Print LLAP packets received on a physical LocalTalk interface. */ void -atalk_print(register const u_char *bp, u_int length) +ltalk_if_print(u_char *user, const struct pcap_pkthdr *h, const u_char *p) +{ + snapend = p + h->caplen; + ++infodelay; + ts_print(&h->ts); + llap_print(p, h->caplen); + if(xflag) + default_print(p, h->caplen); + putchar('\n'); + --infodelay; + if (infoprint) + info(0); +} + +/* + * Print AppleTalk LLAP packets. + */ +void +llap_print(register const u_char *bp, u_int length) { register const struct LAP *lp; register const struct atDDP *dp; register const struct atShortDDP *sdp; u_short snet; - lp = (struct LAP *)bp; + /* + * Our packet is on a 4-byte boundary, as we're either called + * directly from a top-level link-layer printer (ltalk_if_print) + * or from the UDP printer. The LLAP+DDP header is a multiple + * of 4 bytes in length, so the DDP payload is also on a 4-byte + * boundary, and we don't need to align it before calling + * "ddp_print()". + */ + lp = (const struct LAP *)bp; bp += sizeof(*lp); length -= sizeof(*lp); switch (lp->type) { @@ -143,6 +170,48 @@ atalk_print(register const u_char *bp, u_int length) } } +/* + * Print EtherTalk/TokenTalk packets (or FDDITalk, or whatever it's called + * when it runs over FDDI; yes, I've seen FDDI captures with AppleTalk + * packets in them). + */ +void +atalk_print(register const u_char *bp, u_int length) +{ + register const struct atDDP *dp; + u_short snet; + + if (length < ddpSize) { + (void)printf(" [|ddp %d]", length); + return; + } + dp = (const struct atDDP *)bp; + snet = EXTRACT_16BITS(&dp->srcNet); + printf("%s.%s", ataddr_string(snet, dp->srcNode), + ddpskt_string(dp->srcSkt)); + printf(" > %s.%s:", + ataddr_string(EXTRACT_16BITS(&dp->dstNet), dp->dstNode), + ddpskt_string(dp->dstSkt)); + bp += ddpSize; + length -= ddpSize; +#ifdef LBL_ALIGN + if ((long)bp & 3) { + static u_char *abuf = NULL; + + if (abuf == NULL) { + abuf = (u_char *)malloc(snaplen); + if (abuf == NULL) + error("atalk_print: malloc"); + } + memcpy((char *)abuf, (char *)bp, min(length, snaplen)); + snapend += abuf - (u_char *)bp; + packetp = abuf; + bp = abuf; + } +#endif + ddp_print(bp, length, dp->type, snet, dp->srcNode, dp->srcSkt); +} + /* XXX should probably pass in the snap header and do checks like arp_print() */ void aarp_print(register const u_char *bp, u_int length) @@ -177,6 +246,9 @@ aarp_print(register const u_char *bp, u_int length) ap->halen, ap->palen); } +/* + * Print AppleTalk Datagram Delivery Protocol packets. + */ static void ddp_print(register const u_char *bp, register u_int length, register int t, register u_short snet, register u_char snode, u_char skt) @@ -326,10 +398,15 @@ nbp_print(register const struct atNBP *np, u_int length, register u_short snet, register u_char snode, register u_char skt) { register const struct atNBPtuple *tp = - (struct atNBPtuple *)((u_char *)np + nbpHeaderSize); + (const struct atNBPtuple *)((u_char *)np + nbpHeaderSize); int i; const u_char *ep; + if (length < nbpHeaderSize) { + (void)printf(" truncated-nbp %d", length); + return; + } + length -= nbpHeaderSize; if (length < 8) { /* must be room for at least one tuple */ @@ -402,7 +479,7 @@ print_cstring(register const char *cp, register const u_char *ep) return (0); } while ((int)--length >= 0) { - if (cp >= (char *)ep) { + if (cp >= (const char *)ep) { fputs(tstr, stdout); return (0); } @@ -511,7 +588,7 @@ ataddr_string(u_short atnet, u_char athost) ; tp->addr = i3; tp->nxt = newhnamemem(); - tp->name = savestr(nambuf); + tp->name = strdup(nambuf); } fclose(fp); } @@ -528,7 +605,7 @@ ataddr_string(u_short atnet, u_char athost) tp->nxt = newhnamemem(); (void)snprintf(nambuf, sizeof(nambuf), "%s.%d", tp2->name, athost); - tp->name = savestr(nambuf); + tp->name = strdup(nambuf); return (tp->name); } @@ -540,7 +617,7 @@ ataddr_string(u_short atnet, u_char athost) else (void)snprintf(nambuf, sizeof(nambuf), "%d.%d", atnet >> 8, atnet & 0xff); - tp->name = savestr(nambuf); + tp->name = strdup(nambuf); return (tp->name); }