title: Creating a pcap file
body: <p>I need to save UDP packets to a file and would like to use the pcap format to reuse the various tools available (wireshark, tcpdump, ...).
  There are some information in <a href="https://stackoverflow.com/questions/7309773/c-writing-structs-to-a-file-pcap">this thread</a> but I can't find how to write the global file header 'struct pcap_file_header'.</p>
  
  <pre><code>pcap_t* pd = pcap_open_dead(DLT_RAW, 65535);
  pcap_dumper_t* pdumper = pcap_dump_open(pd, filename);
  
  struct pcap_file_header file_hdr;
  file_hdr.magic_number = 0xa1b2c3d4;
  file_hdr.version_major = 2;
  file_hdr.version_minor = 4;
  file_hdr.thiszone = 0;
  file_hdr.sigfigs = 0;
  file_hdr.snaplen = 65535;
  file_hdr.linktype = 1;
  
  // How do I write file_hdr to m_pdumper?
  
  while( (len = recvmsg(sd, &amp;msg_hdr, 0)) &gt; 0 )
    pcap_dump((u_char*)m_pdumper, &amp;m_pcap_pkthdr, (const u_char*)&amp;data);
  </code></pre>
  
  <p>How should I write the global file header? 
  If there is no specific pcap function available, how can I retrieve the file descriptor to insert the header using write()?</p>