1PCAP_GET_SELECTABLE_FD(3PCAP)                    PCAP_GET_SELECTABLE_FD(3PCAP)
2
3
4

NAME

6       pcap_get_selectable_fd  - get a file descriptor on which a select() can
7       be done for a live capture
8

SYNOPSIS

10       #include <pcap/pcap.h>
11
12       int pcap_get_selectable_fd(pcap_t *p);
13

DESCRIPTION

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 in:
25
26              FreeBSD prior to FreeBSD 4.6;
27
28              NetBSD prior to NetBSD 3.0;
29
30              OpenBSD prior to OpenBSD 2.4;
31
32              Mac OS X prior to Mac OS X 10.7;
33
34       select()   and   poll()   do   not   work  correctly  on  BPF  devices;
35       pcap_get_selectable_fd() will return a file descriptor on most of those
36       versions  (the  exceptions  being  FreeBSD  4.3  and 4.4), but a simple
37       select() or poll() will not indicate that the  descriptor  is  readable
38       until  a  full  buffer's worth of packets is received, even if the read
39       timeout expires before then.  To work around this, an application  that
40       uses  select()  or  poll()  to  wait for packets to arrive must put the
41       pcap_t in non-blocking mode, and must  arrange  that  the  select()  or
42       poll()  have a timeout less than or equal to the read timeout, and must
43       try to read packets after that timeout expires, regardless  of  whether
44       select() or poll() indicated that the file descriptor for the pcap_t is
45       ready to be read or not.  (That workaround will not work in FreeBSD 4.3
46       and  later; however, in FreeBSD 4.6 and later, select() and poll() work
47       correctly on BPF devices, so the workaround isn't  necessary,  although
48       it does no harm.)
49
50       Note  also that poll() doesn't work on character special files, includ‐
51       ing BPF devices, in Mac OS X 10.4 and 10.5, so, while select()  can  be
52       used  on  the  descriptor  returned by pcap_get_selectable_fd(), poll()
53       cannot be used on it those versions of Mac OS X.   Kqueues  also  don't
54       work  on  that  descriptor.   poll(),  but  not  kqueues,  work on that
55       descriptor in Mac OS X releases prior to 10.4; poll() and kqueues  work
56       on that descriptor in Mac OS X 10.6 and later.
57
58       pcap_get_selectable_fd() is not available on Windows.
59

RETURN VALUE

61       A  selectable  file descriptor is returned if one exists; otherwise, -1
62       is returned.
63

SEE ALSO

65       pcap(3PCAP), select(2), poll(2)
66
67
68
69                                 5 April 2008    PCAP_GET_SELECTABLE_FD(3PCAP)
Impressum