tcpdump mailing list archives
Re: Compatibility Libpcap/Winpcap and timout of
From: Benoit <benpaka.spam () gmail com>
Date: Wed, 28 Jan 2009 10:48:55 +0100
Okay so I should use something like this: int ret=0; if((ret =pcap_select_ms(ifhard->adhandle,ifhard->timeout)<=0)) { if((ret=pcap_next_ex(ifhard->adhandle, &(ifhard->header), (const u_char**)(&p_pkt))> 0) { ... } } return ret; This let me be sure that if no packet are received the pcap_select_ms() will return 0 after timeout. Then it will return a packet after the N ms (timeout setup during open_live()). This might work only on Windows and Linux (This is okay for me because we don't use OSX in our lab). Moreover sometimes I need to loop 10 times to be sure to receive
correctly the packet,
Why? Does pcap_next_ex() return 0 or a negative value? it return 0 because the timeout is less than the time for: t(PC -> FPGA) + t(FPGA setup) + t(FPGA -> PC). Thanks for your help. -- Benoit RAT www.neub.co.nr On Wed, Jan 28, 2009 at 1:26 AM, Guy Harris <guy () alum mit edu> wrote:
On Jan 27, 2009, at 9:17 AM, Benoit wrote: I've start a simple protocol to communicate with FPGA using only MAClayer. This software should run under linux and windows, however i've a problem with the timeout of pcap_next_ex() function under linux.There is no guarantee that, with a timeout value of N milliseconds, pcap_next_ex() will return within N milliseconds. It might *never* return if no packets arrive. The only *guarantee* that libpcap/WinPcap offers is that it will return within N milliseconds of the arrival of a packet. On some platforms , the timer starts when pcap_next() or pcap_next_ex() or pcap_dispatch() or pcap_loop() is called. On other platforms, the timer starts when the first packet arrives. On other platforms, there isn't any timer. The timeout is *NOT* intended to be used to make sure you don't block forever waiting for a packet. The timeout is intended to be used so that, on platforms where the underlying packet capture mechanism will wait some amount of time to try to deliver multiple packets in one read, rather than waking up the process for every packet (to reduce the number of wakeups and user->kernel and kernel->user transitions), it won't wait forever if at least one packet has arrived. If you want a timeout, so you don't wait forever for a packet to arrived, I'd suggest using select() or poll() on UN*X systems (other than *BSD and Mac OS X, where select() and poll() might not work correctly on BPF devices - and, in the case of Mac OS X, where poll() doesn't work *at all* on "character" devices such as BPF devices or ttys). Moreover sometimes I need to loop 10 times to be sure to receivecorrectly the packet,Why? Does pcap_next_ex() return 0 or a negative value? - This is the tcpdump-workers list. Visit https://cod.sandelman.ca/ to unsubscribe.
- This is the tcpdump-workers list. Visit https://cod.sandelman.ca/ to unsubscribe.
Current thread:
- Compatibility Libpcap/Winpcap and timout of pcap_next_ex(). Benoit (Jan 27)
- Re: Compatibility Libpcap/Winpcap and timout of pcap_next_ex(). Guy Harris (Jan 27)
- Re: Compatibility Libpcap/Winpcap and timout of Matthew Luckie (Jan 27)
- Re: Compatibility Libpcap/Winpcap and timout of Guy Harris (Jan 27)
- Re: Compatibility Libpcap/Winpcap and timout of Aaron Turner (Jan 27)
- Re: Compatibility Libpcap/Winpcap and timout of Guy Harris (Jan 27)
- Re: Compatibility Libpcap/Winpcap and timout of Benoit (Jan 28)
- Re: Compatibility Libpcap/Winpcap and timout of Guy Harris (Jan 28)
- Re: Compatibility Libpcap/Winpcap and timout of Matthew Luckie (Jan 27)
- Re: Compatibility Libpcap/Winpcap and timout of pcap_next_ex(). Guy Harris (Jan 27)