title: How do I fetch the VLAN tags using libpcap and C?
body: <p>I am trying to parse a pcap file including different type of Network Packets (some are tagged as VLAN and some aren't) using #include .
  here is my code so far:</p>
  
  <pre><code>pcap_t *pcap;
  const unsigned char *packet;
  char errbuf[PCAP_ERRBUF_SIZE];
  struct pcap_pkthdr header;
  pcap = pcap_open_offline(argv[0], errbuf);
  if (pcap == NULL)
      {
      fprintf(stderr, "error reading pcap file: %s\n", errbuf);
      exit(1);
  }
  while ((packet = pcap_next(pcap, &amp;header)) != NULL)
  {
      struct ip_header *ip;
      unsigned int IP_header_length;
      packet += sizeof(struct ether_header);
      capture_len -= sizeof(struct ether_header);
      ip = (struct ip_header*) packet;
      IP_header_length = ip-&gt;vhl * 4; /* ip_hl is in 4-byte words */
      char *sinfo = strdup(inet_ntoa(ip-&gt;src));
      char *dinfo = strdup(inet_ntoa(ip-&gt;dst));
      printf ("%s&lt;-__-&gt;%s\n", sinfo ,dinfo);
      free (sinfo);
      free (dinfo);
  }
  </code></pre>
  
  <p>There must be somewhere in the code to check the VLAN and jump over them correctly.How should I distinguish VLAN packets from non-VLANS? </p>