1PCAP_GET_SELECTABLE_FD(3PCAP) PCAP_GET_SELECTABLE_FD(3PCAP)
2
3
4
6 pcap_get_selectable_fd - get a file descriptor on which a select() can
7 be done for a live capture
8
10 #include <pcap/pcap.h>
11
12 int pcap_get_selectable_fd(pcap_t *p);
13
15 pcap_get_selectable_fd() returns, on UNIX, a file descriptor number for
16 a file descriptor on which one can do a select() or poll() to wait for
17 it to be possible to read packets without blocking, if such a descrip‐
18 tor exists, or -1, if no such descriptor exists. Some network devices
19 opened with pcap_create() and pcap_activate(), or with
20 pcap_open_live(), do not support select() or poll() (for example, regu‐
21 lar network devices on FreeBSD 4.3 and 4.4, and Endace DAG devices), so
22 -1 is returned for those devices.
23
24 Note that on most versions of most BSDs (including Mac OS X) select()
25 and poll() do not work correctly on BPF devices;
26 pcap_get_selectable_fd() will return a file descriptor on most of those
27 versions (the exceptions being FreeBSD 4.3 and 4.4), a simple select()
28 or poll() will not return even after the read timeout expires. To work
29 around this, an application that uses select() or poll() to wait for
30 packets to arrive must put the pcap_t in non-blocking mode, and must
31 arrange that the select() or poll() have a timeout less than or equal
32 to the read timeout, and must try to read packets after that timeout
33 expires, regardless of whether select() or poll() indicated that the
34 file descriptor for the pcap_t is ready to be read or not. (That work‐
35 around will not work in FreeBSD 4.3 and later; however, in FreeBSD 4.6
36 and later, select() and poll() work correctly on BPF devices, so the
37 workaround isn't necessary, although it does no harm.)
38
39 Note also that poll() doesn't work on character special files, includ‐
40 ing BPF devices, in Mac OS X 10.4 and 10.5, so, while select() can be
41 used on the descriptor returned by pcap_get_selectable_fd(), poll()
42 cannot be used on it those versions of Mac OS X. Kqueues also don't
43 work on that descriptor. poll(), but not kqueues, work on that
44 descriptor in Mac OS X releases prior to 10.4; poll() and kqueues work
45 on that descriptor in Mac OS X 10.6 and later.
46
47 pcap_get_selectable_fd() is not available on Windows.
48
50 A selectable file descriptor is returned if one exists; otherwise, -1
51 is returned.
52
54 pcap(3PCAP), select(2), poll(2)
55
56
57
58 5 April 2008 PCAP_GET_SELECTABLE_FD(3PCAP)