[Bug 55487] New: winpcap: pcap_dispatch doesn't work with count argument -1
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(a)winehq.org Reporter: amubtdx(a)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... -- Do not reply to this email, post in Bugzilla using the above URL to reply. You are receiving this mail because: You are watching all bug changes.
https://bugs.winehq.org/show_bug.cgi?id=55487 --- Comment #1 from Alexis Murzeau <amubtdx(a)gmail.com> --- Created attachment 75050 --> https://bugs.winehq.org/attachment.cgi?id=75050 test_pcap.c program to test pcap_dispatch The test_pcap program is a test that does this: - Capture packets using pcap_dispatch with count set to -1 (to process all packets at once) - Send a packet with ether_type 0x1234 to have at least one packet to receive in pcap_dispatch - Each time a packet is received in pcap_dispatch, a new packet is sent with pcap_sendpacket and ether_type 0x1234 The test_pcap program should do this (this is what it does when compiled for Linux, note that it requires either root or CAP_SYS_ADMIN for example): ``` # ./test_pcap wlan0 Will use a 2 differents pcap_t instances, one for pcap_dispatch and one for pcap_sendpacket received packet with size: 14, ether_type: 0x1234 received packet with size: 14, ether_type: 0x1234 [... repeated line "received packet" ] ``` But with Wine, it shows this instead (which mean pcap_dispatch doesn't process any packets) (note that /opt/wine-staging/bin/wine64-preloader needs CAP_NET_RAW, and that setcap needs the actual file and not a symlink): ``` # setcap cap_net_raw+epi /opt/wine-staging/bin/wine64-preloader $ wine ./test_pcap.exe 1 List of interfaces with interface number: 1. \Device\NPF_{00000003-0000-0000-0000-4E6574446576} (wlx00c0cab1aa57) 2. \Device\NPF_{00000001-0000-0000-0000-4E6574446576} (lo) 3. \Device\NPF_{00000002-0000-0000-0000-4E6574446576} (enp34s0) Will use a 2 differents pcap_t instances, one for pcap_dispatch and one for pcap_sendpacket pcap_dispatch processed 0 packets [... repeated above line, there is no "received packet" line ] ``` Compilation instruction are in comments inside test_pcap.c. -- Do not reply to this email, post in Bugzilla using the above URL to reply. You are receiving this mail because: You are watching all bug changes.
https://bugs.winehq.org/show_bug.cgi?id=55487 Alexis Murzeau <amubtdx(a)gmail.com> changed: What |Removed |Added ---------------------------------------------------------------------------- Summary|winpcap: pcap_dispatch |winpcap: pcap_dispatch |doesn't work with count |doesn't capture anything |argument -1 |with count argument -1 -- Do not reply to this email, post in Bugzilla using the above URL to reply. You are receiving this mail because: You are watching all bug changes.
https://bugs.winehq.org/show_bug.cgi?id=55487 --- Comment #2 from Alexis Murzeau <amubtdx(a)gmail.com> --- Created attachment 75055 --> https://bugs.winehq.org/attachment.cgi?id=75055 compiled test_pcap.c for Windows with mingw -- Do not reply to this email, post in Bugzilla using the above URL to reply. You are receiving this mail because: You are watching all bug changes.
https://bugs.winehq.org/show_bug.cgi?id=55487 --- Comment #3 from Hans Leidekker <hans(a)meelstraat.net> --- Thanks for the detailed bug report. The fix you proposed looks good, would you mind creating a merge request at https://gitlab.winehq.org? Note that pcap_loop() will need the same treatment. -- Do not reply to this email, post in Bugzilla using the above URL to reply. You are receiving this mail because: You are watching all bug changes.
https://bugs.winehq.org/show_bug.cgi?id=55487 Alexis Murzeau <amubtdx(a)gmail.com> changed: What |Removed |Added ---------------------------------------------------------------------------- Attachment #75050|0 |1 is obsolete| | Attachment #75055|0 |1 is obsolete| | --- Comment #4 from Alexis Murzeau <amubtdx(a)gmail.com> --- Created attachment 75065 --> https://bugs.winehq.org/attachment.cgi?id=75065 test_pcap.c program to test pcap_dispatch (fixed) The previous test_pcap.c program was not using the provided interface number, but always the last one. This attachment fix this. -- Do not reply to this email, post in Bugzilla using the above URL to reply. You are receiving this mail because: You are watching all bug changes.
https://bugs.winehq.org/show_bug.cgi?id=55487 --- Comment #5 from Alexis Murzeau <amubtdx(a)gmail.com> --- (In reply to Hans Leidekker from comment #3)
Thanks for the detailed bug report. The fix you proposed looks good, would you mind creating a merge request at https://gitlab.winehq.org? Note that pcap_loop() will need the same treatment.
Yes, no problem. -- Do not reply to this email, post in Bugzilla using the above URL to reply. You are receiving this mail because: You are watching all bug changes.
https://bugs.winehq.org/show_bug.cgi?id=55487 --- Comment #6 from Alexis Murzeau <amubtdx(a)gmail.com> --- Merge request posted here: https://gitlab.winehq.org/wine/wine/-/merge_requests/3684 -- Do not reply to this email, post in Bugzilla using the above URL to reply. You are receiving this mail because: You are watching all bug changes.
https://bugs.winehq.org/show_bug.cgi?id=55487 Hans Leidekker <hans(a)meelstraat.net> changed: What |Removed |Added ---------------------------------------------------------------------------- Resolution|--- |FIXED Status|UNCONFIRMED |RESOLVED Fixed by SHA1| |2cc573aef98c082ce1c934750b4 | |e448cd1070d9c --- Comment #7 from Hans Leidekker <hans(a)meelstraat.net> --- Fixed with 2cc573aef98c082ce1c934750b4e448cd1070d9c. -- Do not reply to this email, post in Bugzilla using the above URL to reply. You are receiving this mail because: You are watching all bug changes.
https://bugs.winehq.org/show_bug.cgi?id=55487 Alexandre Julliard <julliard(a)winehq.org> changed: What |Removed |Added ---------------------------------------------------------------------------- Status|RESOLVED |CLOSED --- Comment #8 from Alexandre Julliard <julliard(a)winehq.org> --- Closing bugs fixed in 9.4. -- Do not reply to this email, post in Bugzilla using the above URL to reply. You are receiving this mail because: You are watching all bug changes.
participants (1)
-
WineHQ Bugzilla