Merge remote-tracking branch 'goog/tcpdump'

* goog/tcpdump: (3066 commits)
  Remove old version. Getting ready for new tcpdump 4.5
  Support -Q for setting the capture direction.
  Clean up the TLV processing loop.
  With -A and -AA, don't send CRs to the standard output.
  Use the new libpcap <pcap/nflog.h> for NFLOG definitions and declarations.
  Do our own isascii(), isprint(), isgraph(), and toascii().
  Fix a compiler warning.
  Don't use the __attribute__((packed)) on most platforms.
  The interval in an AODV HELLO extension is not aligned on a 4-byte boundary.
  As with memcpy, so with memcmp.
  More UNALIGNED_MEM{CPY,CMP} on IP addresses.
  Another case where UNALIGNED_MEMCPY() is probably necessary.
  No need for casting back and forth.
  Only do the unaligned_mem{cpy,cmp} hack if necessary.
  No need to declare unaligned_mem{cpy,cmp} in netdissect.h *and* interface.h.
  More possibly-unaligned memcpy()s and assignments - use unaligned_memcpy().
  Check for compiling for IPv6; don't check whether we can create an IPv6 socket.
  Use unaligned_memcmp() to compare with IPv{4,6} addresses in a packet.
  Use EXTRACT_nBITS even when just testing against zero.
  Fix some more unaligned accesses.
  ...

Change-Id: I9e98707d30c989b9e32dcd5af798bd0746ab4434
diff --git a/print-atalk.c b/print-atalk.c
index f1f45a3..be1c154 100644
--- a/print-atalk.c
+++ b/print-atalk.c
@@ -23,7 +23,7 @@
 
 #ifndef lint
 static const char rcsid[] _U_ =
-    "@(#) $Header: /tcpdump/master/tcpdump/print-atalk.c,v 1.81 2004/05/01 09:41:50 hannes Exp $ (LBL)";
+    "@(#) $Header: /tcpdump/master/tcpdump/print-atalk.c,v 1.81 2004-05-01 09:41:50 hannes Exp $ (LBL)";
 #endif
 
 #ifdef HAVE_CONFIG_H
@@ -43,7 +43,7 @@
 #include "extract.h"			/* must come after interface.h */
 #include "appletalk.h"
 
-static struct tok type2str[] = {
+static const struct tok type2str[] = {
 	{ ddpRTMP,		"rtmp" },
 	{ ddpRTMPrequest,	"rtmpReq" },
 	{ ddpECHO,		"echo" },
@@ -99,14 +99,10 @@
 	u_short snet;
 	u_int hdrlen;
 
-	/*
-	 * 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()".
-	 */
+	if (length < sizeof(*lp)) {
+		(void)printf(" [|llap %u]", length);
+		return (length);
+	}
 	lp = (const struct LAP *)bp;
 	bp += sizeof(*lp);
 	length -= sizeof(*lp);
@@ -115,7 +111,7 @@
 
 	case lapShortDDP:
 		if (length < ddpSSize) {
-			(void)printf(" [|sddp %d]", length);
+			(void)printf(" [|sddp %u]", length);
 			return (length);
 		}
 		sdp = (const struct atShortDDP *)bp;
@@ -131,7 +127,7 @@
 
 	case lapDDP:
 		if (length < ddpSize) {
-			(void)printf(" [|ddp %d]", length);
+			(void)printf(" [|ddp %u]", length);
 			return (length);
 		}
 		dp = (const struct atDDP *)bp;
@@ -154,7 +150,7 @@
 #endif
 
 	default:
-		printf("%d > %d at-lap#%d %d",
+		printf("%d > %d at-lap#%d %u",
 		    lp->src, lp->dst, lp->type, length);
 		break;
 	}
@@ -176,7 +172,7 @@
             printf("AT ");
 
 	if (length < ddpSize) {
-		(void)printf(" [|ddp %d]", length);
+		(void)printf(" [|ddp %u]", length);
 		return;
 	}
 	dp = (const struct atDDP *)bp;
@@ -213,7 +209,7 @@
 
 		case 2:				/* response */
 			(void)printf("reply %s is-at %s",
-			    AT(pdaddr), etheraddr_string(ap->hdaddr));
+			    AT(psaddr), etheraddr_string(ap->hsaddr));
 			return;
 
 		case 3:				/* probe (oy!) */
@@ -265,6 +261,10 @@
 		fputs(tstr, stdout);
 		return;
 	}
+	if (length < sizeof(*ap)) {
+		(void)printf(" [|atp %u]", length);
+		return;
+	}
 	length -= sizeof(*ap);
 	switch (ap->control & 0xc0) {
 
@@ -276,7 +276,7 @@
 		atp_bitmap_print(ap->bitmap);
 
 		if (length != 0)
-			(void)printf(" [len=%d]", length);
+			(void)printf(" [len=%u]", length);
 
 		switch (ap->control & (atpEOM|atpSTS)) {
 		case atpEOM:
@@ -292,7 +292,7 @@
 		break;
 
 	case atpRspCode:
-		(void)printf(" atp-resp%s%d:%d (%d)",
+		(void)printf(" atp-resp%s%d:%d (%u)",
 			     ap->control & atpEOM? "*" : " ",
 			     EXTRACT_16BITS(&ap->transID), ap->bitmap, length);
 		switch (ap->control & (atpXO|atpSTS)) {
@@ -315,7 +315,7 @@
 
 		/* length should be zero */
 		if (length)
-			(void)printf(" [len=%d]", length);
+			(void)printf(" [len=%u]", length);
 
 		/* there shouldn't be any control flags */
 		if (ap->control & (atpXO|atpEOM|atpSTS)) {
@@ -337,7 +337,7 @@
 		break;
 
 	default:
-		(void)printf(" atp-0x%x  %d (%d)", ap->control,
+		(void)printf(" atp-0x%x  %d (%u)", ap->control,
 			     EXTRACT_16BITS(&ap->transID), length);
 		break;
 	}
@@ -387,14 +387,14 @@
 	const u_char *ep;
 
 	if (length < nbpHeaderSize) {
-		(void)printf(" truncated-nbp %d", length);
+		(void)printf(" truncated-nbp %u", length);
 		return;
 	}
 
 	length -= nbpHeaderSize;
 	if (length < 8) {
 		/* must be room for at least one tuple */
-		(void)printf(" truncated-nbp %d", length + nbpHeaderSize);
+		(void)printf(" truncated-nbp %u", length + nbpHeaderSize);
 		return;
 	}
 	/* ep points to end of available data */
@@ -439,7 +439,7 @@
 		break;
 
 	default:
-		(void)printf(" nbp-0x%x  %d (%d)", np->control, np->id,
+		(void)printf(" nbp-0x%x  %d (%u)", np->control, np->id,
 				length);
 		break;
 	}
@@ -540,7 +540,7 @@
 {
 	register struct hnamemem *tp, *tp2;
 	register int i = (atnet << 8) | athost;
-	char nambuf[MAXHOSTNAMELEN + 20];
+	char nambuf[256+1];
 	static int first = 1;
 	FILE *fp;
 
@@ -551,26 +551,24 @@
 	if (first && (first = 0, !nflag)
 	    && (fp = fopen("/etc/atalk.names", "r"))) {
 		char line[256];
-		int i1, i2, i3;
+		int i1, i2;
 
 		while (fgets(line, sizeof(line), fp)) {
 			if (line[0] == '\n' || line[0] == 0 || line[0] == '#')
 				continue;
-			if (sscanf(line, "%d.%d.%d %256s", &i1, &i2, &i3,
-				     nambuf) == 4)
+			if (sscanf(line, "%d.%d %256s", &i1, &i2, nambuf) == 3)
 				/* got a hostname. */
-				i3 |= ((i1 << 8) | i2) << 8;
-			else if (sscanf(line, "%d.%d %256s", &i1, &i2,
-					nambuf) == 3)
+				i2 |= (i1 << 8);
+			else if (sscanf(line, "%d %256s", &i1, nambuf) == 2)
 				/* got a net name */
-				i3 = (((i1 << 8) | i2) << 8) | 255;
+				i2 = (i1 << 8) | 255;
 			else
 				continue;
 
-			for (tp = &hnametable[i3 & (HASHNAMESIZE-1)];
+			for (tp = &hnametable[i2 & (HASHNAMESIZE-1)];
 			     tp->nxt; tp = tp->nxt)
 				;
-			tp->addr = i3;
+			tp->addr = i2;
 			tp->nxt = newhnamemem();
 			tp->name = strdup(nambuf);
 		}
@@ -596,17 +594,15 @@
 	tp->addr = (atnet << 8) | athost;
 	tp->nxt = newhnamemem();
 	if (athost != 255)
-		(void)snprintf(nambuf, sizeof(nambuf), "%d.%d.%d",
-		    atnet >> 8, atnet & 0xff, athost);
+		(void)snprintf(nambuf, sizeof(nambuf), "%d.%d", atnet, athost);
 	else
-		(void)snprintf(nambuf, sizeof(nambuf), "%d.%d", atnet >> 8,
-		    atnet & 0xff);
+		(void)snprintf(nambuf, sizeof(nambuf), "%d", atnet);
 	tp->name = strdup(nambuf);
 
 	return (tp->name);
 }
 
-static struct tok skt2str[] = {
+static const struct tok skt2str[] = {
 	{ rtmpSkt,	"rtmp" },	/* routing table maintenance */
 	{ nbpSkt,	"nis" },	/* name info socket */
 	{ echoSkt,	"echo" },	/* AppleTalk echo protocol */