mirror of
https://github.com/nmap/nmap.git
synced 2026-01-29 09:39:03 +00:00
This is designed to solve the following problem: On Solaris 10 (maybe other platforms), doing a select on a pcap fd works, in that it returns true when there are frames available to be read. However, after finding the fd selectable and calling pcap_dispatch (or pcap_next, etc.), libpcap may read more than one frame and buffer them internally. This means that later calls to select will return false. So there may be a frame to be read, but you can't know without calling pcap_dispatch to check, and that blocks indefinitely (on Solaris) if you're wrong. The way this works is that we do a non-blocking read on the pcap fd to see if there is anything available. If not, we do a select with a timeout as usual. (The select is to enforce the timeout and prevent spinning CPU by repeatedly trying non-blocking reads.) I don't know if this phenomenon affects other platforms than Solaris 10 (more specifically, platforms using DLPI for libpcap). This same thing may be safe or necessary on other platforms. But I have limited it to Solaris for now. Solaris 11 uses BPF, not DLPI, for libpcap, but we can unconditionally follow this code path on Solaris because BPF pcap fds can't be selected on.