X-Git-Url: https://git.tcpdump.org/tcpdump/blobdiff_plain/176a3e498602351ae25833cf7456c1e30f7f59ae..41f87a79787f53df8a36796b7029e6c642cb1e23:/print-atalk.c diff --git a/print-atalk.c b/print-atalk.c index 30ae8b4e..6ea13611 100644 --- a/print-atalk.c +++ b/print-atalk.c @@ -22,24 +22,19 @@ */ #ifndef lint -static const char rcsid[] = - "@(#) $Header: /tcpdump/master/tcpdump/print-atalk.c,v 1.67 2001-07-05 18:54:14 guy Exp $ (LBL)"; +static const char rcsid[] _U_ = + "@(#) $Header: /tcpdump/master/tcpdump/print-atalk.c,v 1.81 2004-05-01 09:41:50 hannes Exp $ (LBL)"; #endif #ifdef HAVE_CONFIG_H #include "config.h" #endif -#include -#include -#include - -#include +#include #include #include #include -#include /* for MAXHOSTNAMELEN on some platforms */ #include #include "interface.h" @@ -86,41 +81,42 @@ static const char *ddpskt_string(int); /* * Print LLAP packets received on a physical LocalTalk interface. */ -void -ltalk_if_print(u_char *user, const struct pcap_pkthdr *h, const u_char *p) +u_int +ltalk_if_print(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); + return (llap_print(p, h->caplen)); } /* * Print AppleTalk LLAP packets. */ -void +u_int 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; + u_int hdrlen; - 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); + hdrlen = sizeof(*lp); switch (lp->type) { case lapShortDDP: if (length < ddpSSize) { (void)printf(" [|sddp %d]", length); - return; + return (length); } sdp = (const struct atShortDDP *)bp; printf("%s.%s", @@ -129,13 +125,14 @@ llap_print(register const u_char *bp, u_int length) ataddr_string(0, lp->dst), ddpskt_string(sdp->dstSkt)); bp += ddpSSize; length -= ddpSSize; + hdrlen += ddpSSize; ddp_print(bp, length, sdp->type, 0, lp->src, sdp->srcSkt); break; case lapDDP: if (length < ddpSize) { (void)printf(" [|ddp %d]", length); - return; + return (length); } dp = (const struct atDDP *)bp; snet = EXTRACT_16BITS(&dp->srcNet); @@ -146,6 +143,7 @@ llap_print(register const u_char *bp, u_int length) ddpskt_string(dp->dstSkt)); bp += ddpSize; length -= ddpSize; + hdrlen += ddpSize; ddp_print(bp, length, dp->type, snet, dp->srcNode, dp->srcSkt); break; @@ -160,6 +158,7 @@ llap_print(register const u_char *bp, u_int length) lp->src, lp->dst, lp->type, length); break; } + return (hdrlen); } /* @@ -173,15 +172,18 @@ atalk_print(register const u_char *bp, u_int length) register const struct atDDP *dp; u_short snet; + if(!eflag) + printf("AT "); + if (length < ddpSize) { - (void)printf(" [|ddp %d]", length); - return; + (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:", + printf(" > %s.%s: ", ataddr_string(EXTRACT_16BITS(&dp->dstNet), dp->dstNode), ddpskt_string(dp->dstSkt)); bp += ddpSize; @@ -199,9 +201,10 @@ aarp_print(register const u_char *bp, u_int length) printf("aarp "); ap = (const struct aarp *)bp; - if (ntohs(ap->htype) == 1 && ntohs(ap->ptype) == ETHERTYPE_ATALK && + if (EXTRACT_16BITS(&ap->htype) == 1 && + EXTRACT_16BITS(&ap->ptype) == ETHERTYPE_ATALK && ap->halen == 6 && ap->palen == 4 ) - switch (ntohs(ap->op)) { + switch (EXTRACT_16BITS(&ap->op)) { case 1: /* request */ (void)printf("who-has %s tell %s", @@ -219,8 +222,8 @@ aarp_print(register const u_char *bp, u_int length) return; } (void)printf("len %u op %u htype %u ptype %#x halen %u palen %u", - length, ntohs(ap->op), ntohs(ap->htype), ntohs(ap->ptype), - ap->halen, ap->palen); + length, EXTRACT_16BITS(&ap->op), EXTRACT_16BITS(&ap->htype), + EXTRACT_16BITS(&ap->ptype), ap->halen, ap->palen); } /* @@ -241,6 +244,10 @@ ddp_print(register const u_char *bp, register u_int length, register int t, atp_print((const struct atATP *)bp, length); break; + case ddpEIGRP: + eigrp_print(bp, length); + break; + default: (void)printf(" at-%s %d", tok2str(type2str, NULL, t), length); break; @@ -375,10 +382,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 */ @@ -451,7 +463,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); }