What I currently do is the following:
struct pcap_pkthdr *phdr;
const u_char *data;
pcap_next_ex(descriptor, &phdr, &data);
memcpy((void*)mybuf, phdr, sizeof(*phdr));
memcpy((void*)mybuf + sizeof(*phdr), data, phdr->len);
But what I'd like to do is the following, that is, providing a preallocated buffer.
u_char mybuf[2048];
pcap_next_ex(descriptor, mybuf, mybuf + 16); // 16 is size of pkthdr
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.
Is there a way or API to make libpcap take preallocated buffers to write the results of pcap_next_ex into?