6730c1
diff --git a/pcap-linux.c b/pcap-linux.c
6730c1
index 0bfc77a..8cf531b 100644
6730c1
--- a/pcap-linux.c
6730c1
+++ b/pcap-linux.c
6730c1
@@ -368,6 +368,12 @@ static void pcap_oneshot_mmap(u_char *user, const struct pcap_pkthdr *h,
6730c1
     const u_char *bytes);
6730c1
 #endif
6730c1
 
6730c1
+#ifdef TP_STATUS_VLAN_TPID_VALID
6730c1
+#define VLAN_TPID(hdr, hv)	(((hv)->tp_vlan_tpid || ((hdr)->tp_status & TP_STATUS_VLAN_TPID_VALID)) ? (hv)->tp_vlan_tpid : ETH_P_8021Q)
6730c1
+#else
6730c1
+#define VLAN_TPID(hdr, hv)	ETH_P_8021Q
6730c1
+#endif
6730c1
+
6730c1
 /*
6730c1
  * Wrap some ioctl calls
6730c1
  */
6730c1
@@ -1656,7 +1662,7 @@ pcap_read_packet(pcap_t *handle, pcap_handler callback, u_char *userdata)
6730c1
 			memmove(bp, bp + VLAN_TAG_LEN, handlep->vlan_offset);
6730c1
 
6730c1
 			tag = (struct vlan_tag *)(bp + handlep->vlan_offset);
6730c1
-			tag->vlan_tpid = htons(ETH_P_8021Q);
6730c1
+			tag->vlan_tpid = htons(VLAN_TPID(aux, aux));
6730c1
 			tag->vlan_tci = htons(aux->tp_vlan_tci);
6730c1
 
6730c1
                         /* store vlan tci to bpf_aux_data struct for userland bpf filter */
6730c1
@@ -4242,7 +4248,8 @@ static int pcap_handle_packet_mmap(
6730c1
 		unsigned int tp_sec,
6730c1
 		unsigned int tp_usec,
6730c1
 		int tp_vlan_tci_valid,
6730c1
-		__u16 tp_vlan_tci)
6730c1
+		__u16 tp_vlan_tci,
6730c1
+		__u16 tp_vlan_tpid)
6730c1
 {
6730c1
 	struct pcap_linux *handlep = handle->priv;
6730c1
 	unsigned char *bp;
6730c1
@@ -4350,7 +4357,7 @@ static int pcap_handle_packet_mmap(
6730c1
 		memmove(bp, bp + VLAN_TAG_LEN, handlep->vlan_offset);
6730c1
 
6730c1
 		tag = (struct vlan_tag *)(bp + handlep->vlan_offset);
6730c1
-		tag->vlan_tpid = htons(ETH_P_8021Q);
6730c1
+		tag->vlan_tpid = htons(tp_vlan_tpid);
6730c1
 		tag->vlan_tci = htons(tp_vlan_tci);
6730c1
 
6730c1
 		pcaphdr.caplen += VLAN_TAG_LEN;
6730c1
@@ -4410,6 +4417,7 @@ pcap_read_linux_mmap_v1(pcap_t *handle, int max_packets, pcap_handler callback,
6730c1
 				h.h1->tp_sec,
6730c1
 				h.h1->tp_usec,
6730c1
 				0,
6730c1
+				0,
6730c1
 				0);
6730c1
 		if (ret == 1) {
6730c1
 			pkts++;
6730c1
@@ -4488,7 +4496,8 @@ pcap_read_linux_mmap_v2(pcap_t *handle, int max_packets, pcap_handler callback,
6730c1
 #else
6730c1
 				h.h2->tp_vlan_tci != 0,
6730c1
 #endif
6730c1
-				h.h2->tp_vlan_tci);
6730c1
+				h.h2->tp_vlan_tci,
6730c1
+				VLAN_TPID(h.h2, h.h2));
6730c1
 		if (ret == 1) {
6730c1
 			pkts++;
6730c1
 			handlep->packets_read++;
6730c1
@@ -4583,7 +4592,8 @@ pcap_read_linux_mmap_v3(pcap_t *handle, int max_packets, pcap_handler callback,
6730c1
 #else
6730c1
 					tp3_hdr->hv1.tp_vlan_tci != 0,
6730c1
 #endif
6730c1
-					tp3_hdr->hv1.tp_vlan_tci);
6730c1
+					tp3_hdr->hv1.tp_vlan_tci,
6730c1
+					VLAN_TPID(tp3_hdr, &tp3_hdr->hv1));
6730c1
 			if (ret == 1) {
6730c1
 				pkts++;
6730c1
 				handlep->packets_read++;