844bd3
diff --git a/netdissect.h b/netdissect.h
844bd3
index 4f3c666a..93fa8be6 100644
844bd3
--- a/netdissect.h
844bd3
+++ b/netdissect.h
844bd3
@@ -465,6 +465,7 @@ extern u_int raw_if_print IF_PRINTER_ARGS;
844bd3
 extern u_int sl_bsdos_if_print IF_PRINTER_ARGS;
844bd3
 extern u_int sl_if_print IF_PRINTER_ARGS;
844bd3
 extern u_int sll_if_print IF_PRINTER_ARGS;
844bd3
+extern u_int sll2_if_print IF_PRINTER_ARGS;
844bd3
 extern u_int sunatm_if_print IF_PRINTER_ARGS;
844bd3
 extern u_int symantec_if_print IF_PRINTER_ARGS;
844bd3
 extern u_int token_if_print IF_PRINTER_ARGS;
844bd3
diff --git a/print-sll.c b/print-sll.c
844bd3
index 571b7c5e..5a4e2f68 100644
844bd3
--- a/print-sll.c
844bd3
+++ b/print-sll.c
844bd3
@@ -84,6 +84,21 @@ struct sll_header {
844bd3
 	uint16_t	sll_protocol;	/* protocol */
844bd3
 };
844bd3
 
844bd3
+/*
844bd3
+ * A DLT_LINUX_SLL2 fake link-layer header.
844bd3
+ */
844bd3
+#define SLL2_HDR_LEN	20		/* total header length */
844bd3
+
844bd3
+struct sll2_header {
844bd3
+	uint16_t	sll2_protocol;		/* protocol */
844bd3
+	uint16_t	sll2_reserved_mbz;	/* reserved - must be zero */
844bd3
+	uint32_t	sll2_if_index;		/* 1-based interface index */
844bd3
+	uint16_t	sll2_hatype;		/* link-layer address type */
844bd3
+	uint8_t		sll2_pkttype;		/* packet type */
844bd3
+	uint8_t		sll2_halen;		/* link-layer address length */
844bd3
+	u_char		sll2_addr[SLL_ADDRLEN];	/* link-layer address */
844bd3
+};
844bd3
+
844bd3
 /*
844bd3
  * The LINUX_SLL_ values for "sll_pkttype"; these correspond to the
844bd3
  * PACKET_ values on Linux, but are defined here so that they're
844bd3
@@ -308,3 +323,192 @@ recurse:
844bd3
 
844bd3
 	return (hdrlen);
844bd3
 }
844bd3
+
844bd3
+static void
844bd3
+sll2_print(netdissect_options *ndo, const struct sll2_header *sllp, u_int length)
844bd3
+{
844bd3
+	u_short ether_type;
844bd3
+
844bd3
+	ndo->ndo_protocol = "sll2";
844bd3
+       ND_PRINT((ndo,"ifindex %u ", EXTRACT_32BITS(&sllp->sll2_if_index)));
844bd3
+
844bd3
+	/*
844bd3
+	 * XXX - check the link-layer address type value?
844bd3
+	 * For now, we just assume 6 means Ethernet.
844bd3
+	 * XXX - print others as strings of hex?
844bd3
+	 */
844bd3
+	if (EXTRACT_8BITS(&sllp->sll2_halen) == 6)
844bd3
+		ND_PRINT((ndo, "%s ", etheraddr_string(ndo, sllp->sll2_addr)));
844bd3
+
844bd3
+	if (!ndo->ndo_qflag) {
844bd3
+		ether_type = EXTRACT_16BITS(&sllp->sll2_protocol);
844bd3
+
844bd3
+		if (ether_type <= MAX_ETHERNET_LENGTH_VAL) {
844bd3
+			/*
844bd3
+			 * Not an Ethernet type; what type is it?
844bd3
+			 */
844bd3
+			switch (ether_type) {
844bd3
+
844bd3
+			case LINUX_SLL_P_802_3:
844bd3
+				/*
844bd3
+				 * Ethernet_802.3 IPX frame.
844bd3
+				 */
844bd3
+				ND_PRINT((ndo, "802.3"));
844bd3
+				break;
844bd3
+
844bd3
+			case LINUX_SLL_P_802_2:
844bd3
+				/*
844bd3
+				 * 802.2.
844bd3
+				 */
844bd3
+				ND_PRINT((ndo, "802.2"));
844bd3
+				break;
844bd3
+
844bd3
+			default:
844bd3
+				/*
844bd3
+				 * What is it?
844bd3
+				 */
844bd3
+				ND_PRINT((ndo, "ethertype Unknown (0x%04x)",
844bd3
+				    ether_type));
844bd3
+				break;
844bd3
+			}
844bd3
+		} else {
844bd3
+			ND_PRINT((ndo, "ethertype %s (0x%04x)",
844bd3
+			    tok2str(ethertype_values, "Unknown", ether_type),
844bd3
+			    ether_type));
844bd3
+		}
844bd3
+		ND_PRINT((ndo, ", length %u: ", length));
844bd3
+	}
844bd3
+}
844bd3
+
844bd3
+/*
844bd3
+ * This is the top level routine of the printer.  'p' points to the
844bd3
+ * Linux "cooked capture" header of the packet, 'h->ts' is the timestamp,
844bd3
+ * 'h->len' is the length of the packet off the wire, and 'h->caplen'
844bd3
+ * is the number of bytes actually captured.
844bd3
+ */
844bd3
+u_int
844bd3
+sll2_if_print(netdissect_options *ndo, const struct pcap_pkthdr *h, const u_char *p)
844bd3
+{
844bd3
+	u_int caplen = h->caplen;
844bd3
+	u_int length = h->len;
844bd3
+	const struct sll2_header *sllp;
844bd3
+	u_short ether_type;
844bd3
+	int llc_hdrlen;
844bd3
+	u_int hdrlen;
844bd3
+
844bd3
+	ndo->ndo_protocol = "sll2";
844bd3
+	if (caplen < SLL2_HDR_LEN) {
844bd3
+		/*
844bd3
+		 * XXX - this "can't happen" because "pcap-linux.c" always
844bd3
+		 * adds this many bytes of header to every packet in a
844bd3
+		 * cooked socket capture.
844bd3
+		 */
844bd3
+		ND_PRINT((ndo, " [|%s]", ndo->ndo_protocol));
844bd3
+		return (caplen);
844bd3
+	}
844bd3
+
844bd3
+	sllp = (const struct sll2_header *)p;
844bd3
+#ifdef HAVE_NET_IF_H
844bd3
+	uint32_t if_index = EXTRACT_32BITS(&sllp->sll2_if_index);
844bd3
+	if (!if_indextoname(if_index, ifname))
844bd3
+		strncpy(ifname, "?", 2);
844bd3
+	ND_PRINT((ndo, "%-5s ", ifname));
844bd3
+#endif
844bd3
+
844bd3
+	ND_PRINT((ndo, "%-3s ",
844bd3
+		tok2str(sll_pkttype_values, "?", EXTRACT_8BITS(&sllp->sll2_pkttype))));
844bd3
+
844bd3
+	if (ndo->ndo_eflag)
844bd3
+		sll2_print(ndo, sllp, length);
844bd3
+
844bd3
+	/*
844bd3
+	 * Go past the cooked-mode header.
844bd3
+	 */
844bd3
+	length -= SLL2_HDR_LEN;
844bd3
+	caplen -= SLL2_HDR_LEN;
844bd3
+	p += SLL2_HDR_LEN;
844bd3
+	hdrlen = SLL2_HDR_LEN;
844bd3
+
844bd3
+	ether_type = EXTRACT_16BITS(&sllp->sll2_protocol);
844bd3
+
844bd3
+recurse:
844bd3
+	/*
844bd3
+	 * Is it (gag) an 802.3 encapsulation, or some non-Ethernet
844bd3
+	 * packet type?
844bd3
+	 */
844bd3
+	if (ether_type <= MAX_ETHERNET_LENGTH_VAL) {
844bd3
+		/*
844bd3
+		 * Yes - what type is it?
844bd3
+		 */
844bd3
+		switch (ether_type) {
844bd3
+
844bd3
+		case LINUX_SLL_P_802_3:
844bd3
+			/*
844bd3
+			 * Ethernet_802.3 IPX frame.
844bd3
+			 */
844bd3
+			ipx_print(ndo, p, length);
844bd3
+			break;
844bd3
+
844bd3
+		case LINUX_SLL_P_802_2:
844bd3
+			/*
844bd3
+			 * 802.2.
844bd3
+			 * Try to print the LLC-layer header & higher layers.
844bd3
+			 */
844bd3
+			llc_hdrlen = llc_print(ndo, p, length, caplen, NULL, NULL);
844bd3
+			if (llc_hdrlen < 0)
844bd3
+				goto unknown;	/* unknown LLC type */
844bd3
+			hdrlen += llc_hdrlen;
844bd3
+			break;
844bd3
+
844bd3
+		default:
844bd3
+			/*FALLTHROUGH*/
844bd3
+
844bd3
+		unknown:
844bd3
+			/* packet type not known, print raw packet */
844bd3
+			if (!ndo->ndo_suppress_default_print)
844bd3
+				ND_DEFAULTPRINT(p, caplen);
844bd3
+			break;
844bd3
+		}
844bd3
+	} else if (ether_type == ETHERTYPE_8021Q) {
844bd3
+		/*
844bd3
+		 * Print VLAN information, and then go back and process
844bd3
+		 * the enclosed type field.
844bd3
+		 */
844bd3
+		if (caplen < 4) {
844bd3
+			ND_PRINT((ndo, "[|vlan]"));
844bd3
+			return (hdrlen + caplen);
844bd3
+		}
844bd3
+		if (length < 4) {
844bd3
+			ND_PRINT((ndo, "[|vlan]"));
844bd3
+			return (hdrlen + length);
844bd3
+		}
844bd3
+	        if (ndo->ndo_eflag) {
844bd3
+			uint16_t tag = EXTRACT_16BITS(p);
844bd3
+
844bd3
+			ND_PRINT((ndo, "%s, ", ieee8021q_tci_string(tag)));
844bd3
+		}
844bd3
+
844bd3
+		ether_type = EXTRACT_16BITS(p + 2);
844bd3
+		if (ether_type <= MAX_ETHERNET_LENGTH_VAL)
844bd3
+			ether_type = LINUX_SLL_P_802_2;
844bd3
+		if (!ndo->ndo_qflag) {
844bd3
+			ND_PRINT((ndo, "ethertype %s, ",
844bd3
+			    tok2str(ethertype_values, "Unknown", ether_type)));
844bd3
+		}
844bd3
+		p += 4;
844bd3
+		length -= 4;
844bd3
+		caplen -= 4;
844bd3
+		hdrlen += 4;
844bd3
+		goto recurse;
844bd3
+	} else {
844bd3
+		if (ethertype_print(ndo, ether_type, p, length, caplen, NULL, NULL) == 0) {
844bd3
+			/* ether_type not known, print raw packet */
844bd3
+			if (!ndo->ndo_eflag)
844bd3
+				sll2_print(ndo, sllp, length + SLL2_HDR_LEN);
844bd3
+			if (!ndo->ndo_suppress_default_print)
844bd3
+				ND_DEFAULTPRINT(p, caplen);
844bd3
+		}
844bd3
+	}
844bd3
+
844bd3
+	return (hdrlen);
844bd3
+}
844bd3
diff --git a/print.c b/print.c
844bd3
index b9c92adc..4cc35bab 100644
844bd3
--- a/print.c
844bd3
+++ b/print.c
844bd3
@@ -126,6 +126,9 @@ static const struct printer printers[] = {
844bd3
 #ifdef DLT_LINUX_SLL
844bd3
 	{ sll_if_print,		DLT_LINUX_SLL },
844bd3
 #endif
844bd3
+#ifdef DLT_LINUX_SLL2
844bd3
+	{ sll2_if_print,	DLT_LINUX_SLL2 },
844bd3
+#endif
844bd3
 #ifdef DLT_FR
844bd3
 	{ fr_if_print,		DLT_FR },
844bd3
 #endif
844bd3
diff --git a/ethertype.h b/ethertype.h
844bd3
index f38ec8e4..7719a6f0 100644
844bd3
--- a/ethertype.h
844bd3
+++ b/ethertype.h
844bd3
@@ -19,6 +19,13 @@
844bd3
  * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
844bd3
  */
844bd3
 
844bd3
+/*
844bd3
+ * Maximum length of the length field in an Ethernet header; any value
844bd3
+ * greater than this is not a length value, so it's either an Ethernet
844bd3
+ * type or an invalid value.
844bd3
+ */
844bd3
+#define        MAX_ETHERNET_LENGTH_VAL 1500
844bd3
+
844bd3
 /*
844bd3
  * Ethernet types.
844bd3
  *
844bd3
diff --git a/config.h.in b/config.h.in
844bd3
index 4fcbba77..8ae16730 100644
844bd3
--- a/config.h.in
844bd3
+++ b/config.h.in
844bd3
@@ -78,6 +78,9 @@
844bd3
 /* Define to 1 if you have the <netinet/if_ether.h> header file. */
844bd3
 #undef HAVE_NETINET_IF_ETHER_H
844bd3
 
844bd3
+/* Define to 1 if you have the <net/if.h> header file. */
844bd3
+#undef HAVE_NET_IF_H
844bd3
+
844bd3
 /* Define to 1 if you have the <net/if_pflog.h> header file. */
844bd3
 #undef HAVE_NET_IF_PFLOG_H
844bd3
 
844bd3
diff --git a/configure b/configure
844bd3
index eb33db18..f64c4eea 100755
844bd3
--- a/configure
844bd3
+++ b/configure
844bd3
@@ -4037,7 +4037,7 @@ fi
844bd3
 done
844bd3
 
844bd3
 
844bd3
-for ac_header in fcntl.h rpc/rpc.h rpc/rpcent.h
844bd3
+for ac_header in fcntl.h rpc/rpc.h rpc/rpcent.h net/if.h
844bd3
 do :
844bd3
   as_ac_Header=`$as_echo "ac_cv_header_$ac_header" | $as_tr_sh`
844bd3
 ac_fn_c_check_header_mongrel "$LINENO" "$ac_header" "$as_ac_Header" "$ac_includes_default"
844bd3
diff --git a/configure.ac b/configure.ac
844bd3
index 32f48b60..46f841c0 100644
844bd3
--- a/configure.ac
844bd3
+++ b/configure.ac
844bd3
@@ -24,7 +24,7 @@ AC_PROG_CC_C99
844bd3
 	fi
844bd3
 fi
844bd3
 
844bd3
-AC_CHECK_HEADERS(fcntl.h rpc/rpc.h rpc/rpcent.h)
844bd3
+AC_CHECK_HEADERS(fcntl.h rpc/rpc.h rpc/rpcent.h net/if.h)
844bd3
 AC_CHECK_HEADERS(net/pfvar.h, , , [#include <sys/types.h>
844bd3
 #include <sys/socket.h>
844bd3
 #include <net/if.h>])
844bd3
diff --git a/print-sll.c b/print-sll.c
844bd3
index 96031442..e6c7bd4a 100644
844bd3
--- a/print-sll.c
844bd3
+++ b/print-sll.c
844bd3
@@ -25,6 +25,10 @@
844bd3
 #include "config.h"
844bd3
 #endif
844bd3
 
844bd3
+#ifdef HAVE_NET_IF_H
844bd3
+#include <net/if.h>
844bd3
+#endif
844bd3
+
844bd3
 #include <netdissect-stdinc.h>
844bd3
 
844bd3
 #include "netdissect.h"
844bd3
@@ -395,6 +399,9 @@ sll2_if_print(netdissect_options *ndo, const struct pcap_pkthdr *h, const u_char
844bd3
 	u_short ether_type;
844bd3
 	int llc_hdrlen;
844bd3
 	u_int hdrlen;
844bd3
+#ifdef HAVE_NET_IF_H
844bd3
+	char ifname[IF_NAMESIZE];
844bd3
+#endif
844bd3
 
844bd3
 	ndo->ndo_protocol = "sll2";
844bd3
 	if (caplen < SLL2_HDR_LEN) {
844bd3
diff --git a/tcpdump.c b/tcpdump.c
844bd3
index 2bef72c8..0ef21117 100644
844bd3
--- a/tcpdump.c
844bd3
+++ b/tcpdump.c
844bd3
@@ -1978,6 +1978,10 @@ main(int argc, char **argv)
844bd3
 			    RFileName, dlt_name,
844bd3
 			    pcap_datalink_val_to_description(dlt));
844bd3
 		}
844bd3
+#ifdef DLT_LINUX_SLL2
844bd3
+		if (dlt == DLT_LINUX_SLL2)
844bd3
+			fprintf(stderr, "Warning: interface names might be incorrect\n");
844bd3
+#endif
844bd3
 	} else {
844bd3
 		/*
844bd3
 		 * We're doing a live capture.
844bd3
diff --git a/tcpdump.c b/tcpdump.c
844bd3
index 376d9a20..06d3d9b9 100644
844bd3
--- a/tcpdump.c
844bd3
+++ b/tcpdump.c
844bd3
@@ -155,6 +155,7 @@ static int Iflag;			/* rfmon (monitor) mode */
844bd3
 static int Jflag;			/* list available time stamp types */
844bd3
 #endif
844bd3
 static int jflag = -1;			/* packet time stamp source */
844bd3
+static int oflag = 0;
844bd3
 static int pflag;			/* don't go promiscuous */
844bd3
 #ifdef HAVE_PCAP_SETDIRECTION
844bd3
 static int Qflag = -1;			/* restrict captured packet by send/receive direction */
844bd3
@@ -515,7 +515,7 @@ show_devices_and_exit (void)
844bd3
 #define Q_FLAG
844bd3
 #endif
844bd3
 
844bd3
-#define SHORTOPTS "aAb" B_FLAG "c:C:d" D_FLAG "eE:fF:G:hHi:" I_FLAG j_FLAG J_FLAG "KlLm:M:nNOpq" Q_FLAG "r:s:StT:u" U_FLAG "vV:w:W:xXy:Yz:Z:#"
844bd3
+#define SHORTOPTS "aAb" B_FLAG "c:C:d" D_FLAG "eE:fF:G:hHi:" I_FLAG j_FLAG J_FLAG "KlLm:M:nNoOpq" Q_FLAG "r:s:StT:u" U_FLAG "vV:w:W:xXy:Yz:Z:#"
844bd3
 
844bd3
 /*
844bd3
  * Long options.
844bd3
@@ -1340,6 +1341,10 @@ main(int argc, char **argv)
844bd3
 			++ndo->ndo_Nflag;
844bd3
 			break;
844bd3
 
844bd3
+		case 'o':
844bd3
+			oflag++;
844bd3
+			break;
844bd3
+
844bd3
 		case 'O':
844bd3
 			Oflag = 0;
844bd3
 			break;
844bd3
@@ -1932,6 +1932,14 @@ main(int argc, char **argv)
844bd3
 		show_devices_and_exit();
844bd3
 #endif
844bd3
 
844bd3
+#if defined(DLT_LINUX_SLL2) && defined(HAVE_PCAP_SET_DATALINK)
844bd3
+/* Set default linktype DLT_LINUX_SLL2 when capturing on the "any" device */
844bd3
+		if (device != NULL &&
844bd3
+		    strncmp (device, "any", strlen("any")) == 0
844bd3
+		    && yflag_dlt == -1 && oflag > 0)
844bd3
+			yflag_dlt = DLT_LINUX_SLL2;
844bd3
+#endif
844bd3
+
844bd3
 	switch (ndo->ndo_tflag) {
844bd3
 
844bd3
 	case 0: /* Default */
844bd3
@@ -2180,7 +2188,8 @@ main(int argc, char **argv)
844bd3
 			}
844bd3
 #endif
844bd3
 			(void)fprintf(stderr, "%s: data link type %s\n",
844bd3
-				      program_name, yflag_dlt_name);
844bd3
+				      program_name,
844bd3
+				      pcap_datalink_val_to_name(yflag_dlt));
844bd3
 			(void)fflush(stderr);
844bd3
 		}
844bd3
 		i = pcap_snapshot(pd);