title: libpcap: pcap_next_ex with "own" buffers
body: <p>What I currently do is the following:</p>
  
  <pre><code>struct pcap_pkthdr *phdr;
  const u_char *data;
  
  pcap_next_ex(descriptor, &amp;phdr, &amp;data);
  memcpy((void*)mybuf, phdr, sizeof(*phdr));
  memcpy((void*)mybuf + sizeof(*phdr), data, phdr-&gt;len);
  </code></pre>
  
  <p>But what I'd like to do is the following, that is, providing a preallocated buffer.</p>
  
  <pre><code>u_char mybuf[2048];
  
  pcap_next_ex(descriptor, mybuf, mybuf + 16); // 16 is size of pkthdr
  </code></pre>
  
  <p>The second example wouldn't compile anyway because of wrong pointer types, but I think my question is better understandable this way. I am reading from a 10G interface and speed is extremely important. I'd like to benchmarks certain parts of the code, for example, using own preallocated packet buffers instead of the hidden allocations/buffers in libpcap.</p>
  
  <p>Is there a way or API to make libpcap take preallocated buffers to write the results of pcap_next_ex into?</p>