Making "extracted_ethertype" static to "print-ether.c" broke other
dissectors that expected calls to "llc_print()" to set it.  (Thanks and
a tip of the hat to Olaf Kirch <okir@caldera.de> for noticing this.)

Make "ether_encap_print()" and "llc_print()" take a pointer to an
extracted-Ethertype variable as an argument, have "llc_print()" pass it
to "ether_encap_print()", and have "ether_encap_print()" set what it
points to rather than setting a static "extracted_ethertype" variable.

Get rid of said static "extracted_ethertype" variable in favor of one
local to "ether_if_print()", just as other link-layer dissectors have
local "extracted_ethertype" variables.
diff --git a/interface.h b/interface.h
index c8462f4..8008fc5 100644
--- a/interface.h
+++ b/interface.h
@@ -18,7 +18,7 @@
  * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
  * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
  *
- * @(#) $Header: /tcpdump/master/tcpdump/interface.h,v 1.146 2000-12-05 06:42:49 guy Exp $ (LBL)
+ * @(#) $Header: /tcpdump/master/tcpdump/interface.h,v 1.147 2000-12-18 05:41:58 guy Exp $ (LBL)
  */
 
 #ifndef tcpdump_interface_h
@@ -200,9 +200,9 @@
 extern void hex_print_with_offset(const u_char *, u_int, u_int);    
 extern void telnet_print(const u_char *, u_int);    
 extern void hex_print(const u_char *, u_int);    
-extern int ether_encap_print(u_short, const u_char *, u_int, u_int);
+extern int ether_encap_print(u_short, const u_char *, u_int, u_int, u_short *);
 extern int llc_print(const u_char *, u_int, u_int, const u_char *,
-	const u_char *);
+	const u_char *, u_short *);
 extern void aarp_print(const u_char *, u_int);
 extern void arp_print(const u_char *, u_int, u_int);
 extern void atalk_print(const u_char *, u_int);
diff --git a/print-cip.c b/print-cip.c
index 248fb5e..7a2de81 100644
--- a/print-cip.c
+++ b/print-cip.c
@@ -22,7 +22,7 @@
 
 #ifndef lint
 static const char rcsid[] =
-    "@(#) $Header: /tcpdump/master/tcpdump/print-cip.c,v 1.9 2000-09-29 04:58:35 guy Exp $ (LBL)";
+    "@(#) $Header: /tcpdump/master/tcpdump/print-cip.c,v 1.10 2000-12-18 05:41:58 guy Exp $ (LBL)";
 #endif
 
 #ifdef HAVE_CONFIG_H
@@ -132,7 +132,8 @@
 	extracted_ethertype = 0;
 	if (ether_type < ETHERMTU) {
 		/* Try to print the LLC-layer header & higher layers */
-		if (llc_print(p, length, caplen, NULL, NULL)==0) {
+		if (llc_print(p, length, caplen, NULL, NULL,
+		    &extracted_ethertype)==0) {
 			/* ether_type not known, print raw packet */
 			if (!eflag)
 				cip_print((u_char *)bp, length);
@@ -143,7 +144,8 @@
 			if (!xflag && !qflag)
 				default_print(p, caplen);
 		}
-	} else if (ether_encap_print(ether_type, p, length, caplen) == 0) {
+	} else if (ether_encap_print(ether_type, p, length, caplen,
+	    &extracted_ethertype) == 0) {
 		/* ether_type not known, print raw packet */
 		if (!eflag)
 			cip_print((u_char *)bp, length + RFC1483LLC_LEN);
diff --git a/print-ether.c b/print-ether.c
index 167c53e..0711cca 100644
--- a/print-ether.c
+++ b/print-ether.c
@@ -20,7 +20,7 @@
  */
 #ifndef lint
 static const char rcsid[] =
-    "@(#) $Header: /tcpdump/master/tcpdump/print-ether.c,v 1.59 2000-10-22 04:17:53 guy Exp $ (LBL)";
+    "@(#) $Header: /tcpdump/master/tcpdump/print-ether.c,v 1.60 2000-12-18 05:41:59 guy Exp $ (LBL)";
 #endif
 
 #ifdef HAVE_CONFIG_H
@@ -67,8 +67,6 @@
 			     length);
 }
 
-static u_short extracted_ethertype;
-
 /*
  * This is the top level routine of the printer.  'p' is the points
  * to the ether header of the packet, 'h->tv' is the timestamp,
@@ -82,6 +80,7 @@
 	u_int length = h->len;
 	struct ether_header *ep;
 	u_short ether_type;
+	u_short extracted_ethertype;
 
 	ts_print(&h->ts);
 
@@ -114,7 +113,8 @@
 	extracted_ethertype = 0;
 	if (ether_type <= ETHERMTU) {
 		/* Try to print the LLC-layer header & higher layers */
-		if (llc_print(p, length, caplen, ESRC(ep), EDST(ep)) == 0) {
+		if (llc_print(p, length, caplen, ESRC(ep), EDST(ep),
+		    &extracted_ethertype) == 0) {
 			/* ether_type not known, print raw packet */
 			if (!eflag)
 				ether_print((u_char *)ep, length);
@@ -125,7 +125,8 @@
 			if (!xflag && !qflag)
 				default_print(p, caplen);
 		}
-	} else if (ether_encap_print(ether_type, p, length, caplen) == 0) {
+	} else if (ether_encap_print(ether_type, p, length, caplen,
+	    &extracted_ethertype) == 0) {
 		/* ether_type not known, print raw packet */
 		if (!eflag)
 			ether_print((u_char *)ep, length + ETHER_HDRLEN);
@@ -144,16 +145,18 @@
  *
  * Returns non-zero if it can do so, zero if the ethertype is unknown.
  *
- * Stuffs the ether type into a global for the benefit of lower layers
- * that might want to know what it is.
+ * The Ethernet type code is passed through a pointer; if it was
+ * ETHERTYPE_8021Q, it gets updated to be the Ethernet type of
+ * the 802.1Q payload, for the benefit of lower layers that might
+ * want to know what it is.
  */
 
 int
 ether_encap_print(u_short ethertype, const u_char *p,
-    u_int length, u_int caplen)
+    u_int length, u_int caplen, u_short *extracted_ethertype)
 {
  recurse:
-	extracted_ethertype = ethertype;
+	*extracted_ethertype = ethertype;
 
 	switch (ethertype) {
 
@@ -202,15 +205,16 @@
 		if (ethertype > ETHERMTU)
 			goto recurse;
 
-		extracted_ethertype = 0;
+		*extracted_ethertype = 0;
 
-		if (llc_print(p, length, caplen, p - 18, p - 12) == 0) {
+		if (llc_print(p, length, caplen, p - 18, p - 12,
+		    extracted_ethertype) == 0) {
 			/* ether_type not known, print raw packet */
 			if (!eflag)
 				ether_print(p - 18, length + 4);
-			if (extracted_ethertype) {
+			if (*extracted_ethertype) {
 				printf("(LLC %s) ",
-			       etherproto_string(htons(extracted_ethertype)));
+			       etherproto_string(htons(*extracted_ethertype)));
 			}
 			if (!xflag && !qflag)
 				default_print(p - 18, caplen + 4);
diff --git a/print-fddi.c b/print-fddi.c
index f1e0ecf..6763ad4 100644
--- a/print-fddi.c
+++ b/print-fddi.c
@@ -21,7 +21,7 @@
 
 #ifndef lint
 static const char rcsid[] =
-    "@(#) $Header: /tcpdump/master/tcpdump/print-fddi.c,v 1.47 2000-10-09 02:59:40 guy Exp $ (LBL)";
+    "@(#) $Header: /tcpdump/master/tcpdump/print-fddi.c,v 1.48 2000-12-18 05:41:59 guy Exp $ (LBL)";
 #endif
 
 #ifdef HAVE_CONFIG_H
@@ -298,8 +298,8 @@
 	extracted_ethertype = 0;
 	if ((fddip->fddi_fc & FDDIFC_CLFF) == FDDIFC_LLC_ASYNC) {
 		/* Try to print the LLC-layer header & higher layers */
-		if (llc_print(p, length, caplen, ESRC(&ehdr), EDST(&ehdr))
-		    == 0) {
+		if (llc_print(p, length, caplen, ESRC(&ehdr), EDST(&ehdr),
+		    &extracted_ethertype) == 0) {
 			/*
 			 * Some kinds of LLC packet we cannot
 			 * handle intelligently
diff --git a/print-gre.c b/print-gre.c
index 1076c7f..1e801b9 100644
--- a/print-gre.c
+++ b/print-gre.c
@@ -24,7 +24,7 @@
 
 #ifndef lint
 static const char rcsid[] =
-    "@(#) $Header: /tcpdump/master/tcpdump/print-gre.c,v 1.8 2000-09-29 04:58:39 guy Exp $";
+    "@(#) $Header: /tcpdump/master/tcpdump/print-gre.c,v 1.9 2000-12-18 05:41:59 guy Exp $";
 #endif
 
 #ifdef HAVE_CONFIG_H
@@ -86,7 +86,7 @@
 {
 	const u_char *cp = bp + 4;
 	const struct gre *gre;
-	u_short flags, proto;
+	u_short flags, proto, extracted_ethertype;
 
 	gre = (const struct gre *)bp;
 
@@ -123,7 +123,8 @@
 		cp += 4;
 
 	length -= cp - bp;
-	if (ether_encap_print(proto, cp, length, length) == 0)
+	if (ether_encap_print(proto, cp, length, length,
+	    &extracted_ethertype) == 0)
  		printf("gre-proto-0x%04X", proto);
 	return;
 
diff --git a/print-lane.c b/print-lane.c
index 5010314..149a5ae 100644
--- a/print-lane.c
+++ b/print-lane.c
@@ -22,7 +22,7 @@
 
 #ifndef lint
 static const char rcsid[] =
-    "@(#) $Header: /tcpdump/master/tcpdump/print-lane.c,v 1.9 2000-09-29 04:58:43 guy Exp $ (LBL)";
+    "@(#) $Header: /tcpdump/master/tcpdump/print-lane.c,v 1.10 2000-12-18 05:42:00 guy Exp $ (LBL)";
 #endif
 
 #ifdef HAVE_CONFIG_H
@@ -112,7 +112,8 @@
 	extracted_ethertype = 0;
 	if (ether_type < ETHERMTU) {
 		/* Try to print the LLC-layer header & higher layers */
-		if (llc_print(p, length, caplen, ep->h_source,ep->h_dest)==0) {
+		if (llc_print(p, length, caplen, ep->h_source, ep->h_dest,
+		    &extracted_ethertype) == 0) {
 			/* ether_type not known, print raw packet */
 			if (!eflag)
 				lane_print((u_char *)ep, length);
@@ -123,7 +124,8 @@
 			if (!xflag && !qflag)
 				default_print(p, caplen);
 		}
-	} else if (ether_encap_print(ether_type, p, length, caplen) == 0) {
+	} else if (ether_encap_print(ether_type, p, length, caplen,
+	    &extracted_ethertype) == 0) {
 		/* ether_type not known, print raw packet */
 		if (!eflag)
 			lane_print((u_char *)ep, length + sizeof(*ep));
diff --git a/print-llc.c b/print-llc.c
index 2763c0f..6e75771 100644
--- a/print-llc.c
+++ b/print-llc.c
@@ -24,7 +24,7 @@
 
 #ifndef lint
 static const char rcsid[] =
-    "@(#) $Header: /tcpdump/master/tcpdump/print-llc.c,v 1.30 2000-12-05 06:42:48 guy Exp $";
+    "@(#) $Header: /tcpdump/master/tcpdump/print-llc.c,v 1.31 2000-12-18 05:42:00 guy Exp $";
 #endif
 
 #ifdef HAVE_CONFIG_H
@@ -64,7 +64,7 @@
  */
 int
 llc_print(const u_char *p, u_int length, u_int caplen,
-	  const u_char *esrc, const u_char *edst)
+	  const u_char *esrc, const u_char *edst, u_short *extracted_ethertype)
 {
 	struct llc llc;
 	register u_short et;
@@ -153,7 +153,8 @@
 
 		/* This is an encapsulated Ethernet packet */
 		et = EXTRACT_16BITS(&llc.ethertype[0]);
-		ret = ether_encap_print(et, p, length, caplen);
+		ret = ether_encap_print(et, p, length, caplen,
+		    extracted_ethertype);
 		if (ret)
 			return (ret);
 	}
diff --git a/print-token.c b/print-token.c
index 156c610..9fa0b63 100644
--- a/print-token.c
+++ b/print-token.c
@@ -25,7 +25,7 @@
  */
 #ifndef lint
 static const char rcsid[] =
-    "@(#) $Header: /tcpdump/master/tcpdump/print-token.c,v 1.8 2000-10-06 04:23:14 guy Exp $";
+    "@(#) $Header: /tcpdump/master/tcpdump/print-token.c,v 1.9 2000-12-18 05:42:00 guy Exp $";
 #endif
 
 #ifdef HAVE_CONFIG_H
@@ -180,8 +180,8 @@
 	extracted_ethertype = 0;
 	if (FRAME_TYPE(trp) == TOKEN_FC_LLC) {
 		/* Try to print the LLC-layer header & higher layers */
-		if (llc_print(p, length, caplen, ESRC(&ehdr), EDST(&ehdr))
-		    == 0) {
+		if (llc_print(p, length, caplen, ESRC(&ehdr), EDST(&ehdr),
+		    &extracted_ethertype) == 0) {
 			/* ether_type not known, print raw packet */
 			if (!eflag)
 				token_print(trp, length,