ZeroCopy read packet data causes heap allocations in pcapNextPacketEx
- Dominant language
- Go
- Stars
- 6.8k
- Forks
- 1.2k
- PR merge metrics
- No merged PRs in 30d
Description
```
gopacket@v1.1.19
go version go1.21.1 linux/amd64
Fedora 39, amd64
```
ZeroCopy receiving using pcap on Unix causes 1-allocation per receive, which is very unfortunate:

There is a mysterious comment in this function suggesting some weirdness with GC:
```go
func (p *Handle) pcapNextPacketEx() NextError {
// This horrible magic allows us to pass a ptr-to-ptr to pcap_next_ex
// without causing that ptr-to-ptr to itself be allocated on the heap.
// Since Handle itself survives through the duration of the pcap_next_ex
// call, this should be perfectly safe for GC stuff, etc.
return NextError(C.pcap_next_ex_escaping(p.cptr, C.uintptr_t(uintptr(unsafe.Pointer(&p.pkthdr))), C.uintptr_t(uintptr(unsafe.Pointer(&p.bufptr)))))
}
```
No idea why this allocates anything.
Contributor guide
Assessment
This issue has not been assessed yet.