google / gopacket

Provides packet processing capabilities for Go
BSD 3-Clause "New" or "Revised" License
6.22k stars 1.11k forks source link

WinPcap (npcap) errorBufferSize is now too small #756

Open hdm opened 4 years ago

hdm commented 4 years ago

It looks like newer versions of npcap may require a larger error buffer size. In some cases (mostly concurrent use of the interface), the syscall returns an error:

PacketGetAdapterNames: The data area passed to a system call is too small. (122)

func pcapFindAllDevs() (pcapDevices, error) {
    var alldevsp pcapDevices
    err := LoadWinPCAP()
    if err != nil {
        return alldevsp, err
    }

    buf := make([]byte, errorBufferSize)
        ^^^^^^^^^^^^^^^^^^^^^^^^^^^
    ret, _, _ := syscall.Syscall(pcapFindalldevsPtr, 2, uintptr(unsafe.Pointer(&alldevsp.all)), uintptr(unsafe.Pointer(&buf[0])), 0)

    if pcapCint(ret) < 0 {
        return pcapDevices{}, errors.New(byteSliceToString(buf))
    }
    return alldevsp, nil
}

This comes from const errorBufferSize = 0x100 created by generate_defs.exe.

Could this buffer size be increased, or the defs regenerated using the current npcap?

frei-0xff commented 1 year ago

I have the same issue. The error happens very rarely, like ones per 100 runs, and without any obvious reason. Update: As I can see, errorBufferSize is set to PCAP_ERRBUF_SIZE constant from WinPcap, and it is in compliance with documentation of pcap_findalldevs function, PCAP_ERRBUF_SIZE is defined as 256 for the latest WinPcap 4.0.2, so everything seems right. Therefore, in my opinion, it is not a gopacket's issue, but an issue of WinPcap library.