https://bugs.winehq.org/show_bug.cgi?id=55487
Bug ID: 55487 Summary: winpcap: pcap_dispatch doesn't work with count argument -1 Product: Wine Version: 8.14 Hardware: x86-64 OS: Linux Status: UNCONFIRMED Severity: normal Priority: P2 Component: wpcap Assignee: wine-bugs@winehq.org Reporter: amubtdx@gmail.com Distribution: ---
Hi,
While trying to use a Windows program that uses WinPcap, it is not receiving anything from `pcap_dispatch`.
`pcap_dispatch` is a function to receive raw packets from the ethernet adapter.
In the Windows program, `pcap_dispatch` is called with the `cnt` argument `-1`.
According to WinPcap documentation of `pcap_dispatch` (https://www.winpcap.org/docs/docs_41b5/html/group__wpcapfunc.html#g60ce104cd...):
A cnt of -1 processes all the packets received in one buffer when reading a live capture, or all the packets in the file when reading a ``savefile''
But Wine implementation of `pcap_dispatch` does this:
```c int CDECL pcap_dispatch( struct pcap *pcap, int count, void (CALLBACK *callback)(unsigned char *, const struct pcap_pkthdr_win32 *, const unsigned char *), unsigned char *user ) { int processed = 0;
TRACE( "%p, %d, %p, %p\n", pcap, count, callback, user );
while (processed < count) { ``` See here: https://github.com/wine-mirror/wine/blob/bd10252332491bc39100f230540b14d59f0...
When `count` is `-1`, `while (processed < count)` exit immediately without processing any packets.
I've tried a local build using this condition instead, and it fixes the issue: `while (count <= 0 || processed < count)`.
I use `count <= 0` to match libpcap's way of checking unlimited count.
```c // pcap-int.h: #define PACKET_COUNT_IS_UNLIMITED(count) ((count) <= 0)
// pcap-netfilter-linux.c, end of function netfilter_read_linux: // [...] if (count >= max_packets && !PACKET_COUNT_IS_UNLIMITED(max_packets)) { // [...] ``` Note: here, `count` is the number of processed packets so far and `max_packet` is the value of `cnt`/`count` given to `pcap_dispatch`.
See here: https://github.com/the-tcpdump-group/libpcap/blob/bf8bfc74b2c8e893b2af2d657a...