On Jul 7, 2005, at 7:45 PM, hong liu wrote:
Hello, I am using libpcap library to capture ip data from data link. I am wondering if there is a way to time out reading a packet from data link. For example, if there is no data coming in 1 second, timer times out and process will do other things, like nonblocking.
No, there's no way to time out reading packets from the network on all platforms. On *some* platforms the underlying packet capture mechanism supports a timeout, and starts the timer as soon as a read is done, so that it returns after the timeout expires even if no packets have arrived. On other platforms, either the underlying packet capture mechanism doesn't support a timeout, or it does, but the timeout starts only after the first packet arrives. (The primary purpose of the timeouts is to allow multiple packets to be delivered in one read, by waiting for a full buffer's worth of packets to arrive, or a timeout to expire, before returning from the read.)
However, on most UN*Xes, you can use "select()" on the file descriptor for the pcap_t, so that your program can wait either for packets to arrive or for something else. What are the "other things" the process would do?
- This is the tcpdump-workers list. Visit https://lists.sandelman.ca/ to unsubscribe.
