nmap / npcap

Nmap Project's Windows packet capture and transmission library
https://npcap.com
Other
2.97k stars 514 forks source link

Sometimes pcap_sendpacket takes longer in some situations #619

Open s5suzuki opened 2 years ago

s5suzuki commented 2 years ago

I have noticed that pcap_sendpacket sometimes takes a long time while playing a video in Windows Media Player or any other video player. Usually, this function finishes in about 20us, but it frequently takes up to 1000us while playing video. The same problem occurs when opening sites such as YouTube with Chrome, while normal browsing does not cause the problem. I just executed the "Examples-pcap/sendpack" example included in the Npcap SDK.

Interestingly, this problem occurs with "Realtek PCIe GBE Family Controller" and "Intel(R) Gigabit CT Desktop Adapter," but not with "ASIX AX88179 USB 3.0 to Gigabit Ethernet Adapter".

Does anyone have any idea what might be causing this problem?

Diagnostic information

SylvainSalle commented 2 years ago

We have a similar issue, using pcap_sendqueue_transmit. Sending a paquet will sometimes (randomly) take more than 20 seconds instead of a few milliseconds. The circonstances of this bug are not really clear. One thing we did that seemed to help is to stop using the last milliseconds of the current second when we use the transmit function, like in the following code:

//avoid pcap end second bug
ts = std::chrono::duration_cast<std::chrono::milliseconds>(std::chrono::system_clock::now().time_since_epoch()).count();
if (ts % 1000 > 900)
    std::this_thread::sleep_for(std::chrono::milliseconds(1000 - (ts % 1000)));
unsigned int res = pcap_sendqueue_transmit(mp_adapter, squeue, TRUE);

It helps, but doesn't really solve the issue. Has anyone else encountered this?

Diagnostic information

lk-davidegironi commented 1 year ago

As @kayoub5 mentioned, I've also a latency issue with pcap_sendpacket, mine is called by sharppcap. Tried different NIC and different PC but things does not change.

s5suzuki commented 1 year ago

FYI, I have noticed that this problem also occurs when playing a local video and when Microsoft Teams is running (even in the background).

lk-davidegironi commented 1 year ago

FYI, I have noticed that this problem also occurs when playing a local video and when Microsoft Teams is running (even in the background).

Thanks you! Not my case unluckily