[Winpcap-users] How does windows see that the NIC has received data?

Gianluca Varenni gianluca.varenni at cacetech.com
Thu Mar 16 15:35:55 GMT 2006


----- Original Message ----- 
From: "Ramiro Polla" <ramiro86 at hotmail.com>
To: <winpcap-users at winpcap.org>
Sent: Wednesday, March 15, 2006 12:54 PM
Subject: [Winpcap-users] How does windows see that the NIC has received 
data?


>I was wondering... Is it absolutely necessary for winpcap to keep checking 
>the status of the NIC to see if there is any data?

What do you mean by that? If you mean "polling", WinPcap does *not* poll: at 
the driver level, WinPcap gets basically called by the NIC to receive a 
notification of an available packet (this is actually a bit more 
complicated, NDIS notifies WinPcap on behalf of the NIC driver). At user 
level, basically packet.dll (and it turn wpcap.dll) blocks on an event that 
gets signalled by the WinPcap driver when "enough" packets are available to 
be trasferred to the WinPcap based application. So, even if you are thinking 
of polling because you have a "while(pcap_next_ex){}" loop, you are not 
actually polling (or better, it's not a busy wait loop). pcap_next_ex (or 
pcap_loop/pcap_dispatch, with a slightly different behavior) will block for 
at most "timeout" milliseconds before returning if no packets are available.

> Doesn't the NIC call some interrupt when it receives data. And that 
> interrupt could be used to call the callback function.
>
> If it really is absolutely necessary to constantly check the NIC, how does 
> windows do it, and couldn't a function be made to call the callback 
> function at every packet received? (without the user having to ask every 
> time).
>

This is basically how pcap_loop/dispatch works, *but* they are basically 
implemented in the same exact way as a "while(pcap_next_ex){}" loop.

Basically, if you set mintocopy and timeout to reasonable values (i.e. you 
don't change the default value of mintocopy, and you set a timeout != 0, 
where by 0 I mean "return immediately, do not block", in pcap_open_live 
"immediate" is -1) your app will not spend 100% of your time busy waiting on 
pcap_next_ex.

Have a nice day
GV



> I know nothing about the driver, so I'm just wondering here...
>
>
> _______________________________________________
> Winpcap-users mailing list
> Winpcap-users at winpcap.org
> https://www.winpcap.org/mailman/listinfo/winpcap-users
> 



More information about the Winpcap-users mailing list