[Winpcap-bugs] [bug?] pcap_next_ex() blocks forever after
pcap_setnonblock(, 0, )
Leo Breuss
lbreuss at scs.ch
Sun Jul 10 13:47:35 GMT 2005
Hi,
in general the winpcap library works very well on my system. Besides having it
running with my own code, I also have Ethereal installed and working. There is
just one problem I am not able to solve, I even believe it might be a bug in
winpcap.
Observation:
when I'm calling pcap_setnonblock(p,0,0) to put the interface to blocking state,
a subsequent pcap_next_ex() will never ever return, not even when the timeout is
due. The same behaviour is observable if I'm using the pcap_setbuff() function
instead of pcap_setnonblock(,0,).
Both Method 1 and Method 2 (see my Code Snippet below) will make the
pcap_next_ex() in the while() loop block forever, no matter if there are
packets in the buffer or if packets arrive or a timeout is due.
I have a packet generator on the same net which produces packets at a rate of
50Hz. I am able to catch these packets using pcap_next_ex() as long as I don't
call pcap_setnonblock(,0,) or pcap_setbuff(). Method 2 without using
pcap_setnonblock(,1,) is not an option, as it's not possible to break out of
the loop with "timeout" because the packet generator on the net sends a packet
every 20ms. I don't like to use a workaround like re-open the Adapter, other
threads could not send packets meanwhile and they would need to receive again
the handle to the adapter.
I appreciate any help on this.
Best regards,
Leo
-----
AMD 1.7GHz, 1GB, 1 Ethernet card
1.\Device\NPF_{2A67F6A8-FD7B-4646-BDF6-DF9318129D0A}
(Realtek RTL8139/810x Family Fast Ethernet NIC)
tried WinPcap 3.0 and WinPcap 3.1beta4
Windows 2000 Professional
Windump 3.0alpha (which is labeled 3.8alphaWindump on your server) does not
generate any files, just the two lines with the adapter info
====================================
=== Code Snippet:
====================================
// open interface with timeout of 300ms on interface (packets arrive
// at least every 20ms from packet generator on the same net)
pcap_open(..., to_ms = 300, ...);
// adapter is now capturing ot adapters buffer
- Send some ethernet control frames (that's why I have to pcap_open() here)
- Initialize my system. this takes about a second or two.
// now discard already received ethernet frames from the adapters buffer
// because they are not needed anymore (typically 50 packets already in buffer)
//---Method 1:-------------
setbuff(p, 1<<20); // forget old buffer, allocate new one
//---Method 2:-------------
// the interface is in blocking state per default
pcap_setnonblock(p,1,0); // put interface to nonblocking state
while( 1 == pcap_next_ex(p,hdr,data) ); // quickly flush the buffer
pcap_setnonblock(p,0,0); // put interface back to blocking state
//-------------------------
// now listen on adapter, use blocking pcap_next_ex() to save CPU cycles
while(!stopRequest)
{
// read from buf immediately or wait until packet arrives or until timeout
r = pcap_next_ex(p,hdr,data);
if(1==r) HandlePacket(hdr,data);
}
----------------------------------------------------------------
This message was sent using IMP, the Internet Messaging Program.
More information about the Winpcap-bugs
mailing list