title: reading a pcap file in c++
body: <p>I want to read a pcap file and get the header information of the packets of a flow...</p>
  
  <p>for this I found a c++ program from <a href="http://www.cnblogs.com/xiangshancuizhu/archive/2012/10/14/2723654.html" rel="nofollow">http://www.cnblogs.com/xiangshancuizhu/archive/2012/10/14/2723654.html</a>  which read the pcap file and have a header pointer , this  pointer </p>
  
  <p>class just point to length of header, but I want to access the other features of header </p>
  
  <p>such as syn,fin,ack,seq no,....here is my code, how can I do this?</p>
  
  <pre><code> char errbuff[PCAP_ERRBUF_SIZE];
  
  /*
  * Step 4 - Open the file and store result in pointer to pcap_t
  */
  
  // Use pcap_open_offline
  // http://www.winpcap.org/docs/docs_41b5/html/group__wpcapfunc.html#g91078168a13de8848df2b7b83d1f5b69
  pcap_t * pcap = pcap_open_offline(file.c_str(), errbuff);
  
  /*
  * Step 5 - Create a header and a data object
  */
  
  // Create a header object:
  // http://www.winpcap.org/docs/docs_40_2/html/structpcap__pkthdr.html
  struct pcap_pkthdr *header;
  
  // Create a character array using a u_char
  // u_char is defined here:
  // C:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\Include\WinSock2.h
  // typedef unsigned char   u_char;
  const u_char *data;
  
  /*
  * Step 6 - Loop through packets and print them to screen
  */
  u_int packetCount = 0;
  while (int returnValue = pcap_next_ex(pcap, &amp;header, &amp;data) &gt;= 0)
  {
      // Print using printf. See printf reference:
      // http://www.cplusplus.com/reference/clibrary/cstdio/printf/
  
      // Show the packet number
      printf("Packet # %i\n", ++packetCount);
  
      // Show the size in bytes of the packet
      printf("Packet size: %d bytes\n", header-&gt;len);
  </code></pre>
  
  <p>and header is a structure like:</p>
  
  <pre><code>struct pcap_pkthdr {
      struct timeval ts;  /* time stamp */
      bpf_u_int32 caplen; /* length of portion present */
      bpf_u_int32 len;    /* length this packet (off wire) */
  };
  </code></pre>
  
  <p>and I want this structure have more members, what should I do?
  thanks a lot.</p>