Import libpcap-1.8.1.
[dragonfly.git] / contrib / libpcap / pcap_get_selectable_fd.3pcap
1 .\" Copyright (c) 1994, 1996, 1997
2 .\"     The Regents of the University of California.  All rights reserved.
3 .\"
4 .\" Redistribution and use in source and binary forms, with or without
5 .\" modification, are permitted provided that: (1) source code distributions
6 .\" retain the above copyright notice and this paragraph in its entirety, (2)
7 .\" distributions including binary code include the above copyright notice and
8 .\" this paragraph in its entirety in the documentation or other materials
9 .\" provided with the distribution, and (3) all advertising materials mentioning
10 .\" features or use of this software display the following acknowledgement:
11 .\" ``This product includes software developed by the University of California,
12 .\" Lawrence Berkeley Laboratory and its contributors.'' Neither the name of
13 .\" the University nor the names of its contributors may be used to endorse
14 .\" or promote products derived from this software without specific prior
15 .\" written permission.
16 .\" THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED
17 .\" WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
18 .\" MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
19 .\"
20 .TH PCAP_GET_SELECTABLE_FD 3PCAP "18 October 2014"
21 .SH NAME
22 pcap_get_selectable_fd \- get a file descriptor on which a select() can
23 be done for a live capture
24 .SH SYNOPSIS
25 .nf
26 .ft B
27 #include <pcap/pcap.h>
28 .ft
29 .LP
30 .ft B
31 int pcap_get_selectable_fd(pcap_t *p);
32 .ft
33 .fi
34 .SH DESCRIPTION
35 .B pcap_get_selectable_fd()
36 returns, on UNIX, a file descriptor number for a file descriptor on
37 which one can
38 do a
39 .BR select() ,
40 .BR poll() ,
41 or other such call
42 to wait for it to be possible to read packets without blocking, if such
43 a descriptor exists, or \-1, if no such descriptor exists.  Some network
44 devices opened with
45 .B pcap_create()
46 and
47 .BR pcap_activate() ,
48 or with
49 .BR pcap_open_live() ,
50 do not support
51 .B select()
52 or
53 .B poll()
54 (for example, regular network devices on FreeBSD 4.3 and 4.4, and Endace
55 DAG devices), so \-1 is returned for those devices.
56 .PP
57 Note that a descriptor on which a read can be done without blocking may,
58 on some platforms, not have any packets to read if the read timeout has
59 expired.  A call to
60 .B pcap_dispatch()
61 will return 0 in this case, but will not block.
62 .PP
63 Note that in:
64 .IP
65 FreeBSD prior to FreeBSD 4.6;
66 .IP
67 NetBSD prior to NetBSD 3.0;
68 .IP
69 OpenBSD prior to OpenBSD 2.4;
70 .IP
71 Mac OS X prior to Mac OS X 10.7;
72 .PP
73 .B select()
74 and
75 .B poll()
76 do not work correctly on BPF devices;
77 .B pcap_get_selectable_fd()
78 will return a file descriptor on most of those versions (the exceptions
79 being FreeBSD 4.3 and 4.4), but a simple
80 .B select()
81 or
82 .B poll()
83 will not indicate that the descriptor is readable until a full buffer's
84 worth of packets is received, even if the read timeout expires before
85 then.  To work around this, an application that uses
86 .B select()
87 or
88 .B poll()
89 to wait for packets to arrive must put the
90 .B pcap_t
91 in non-blocking mode, and must arrange that the
92 .B select()
93 or
94 .B poll()
95 have a timeout less than or equal to the read timeout,
96 and must try to read packets after that timeout expires, regardless of
97 whether
98 .B select()
99 or
100 .B poll()
101 indicated that the file descriptor for the
102 .B pcap_t
103 is ready to be read or not.  (That workaround will not work in FreeBSD
104 4.3 and later; however, in FreeBSD 4.6 and later,
105 .B select()
106 and
107 .B poll()
108 work correctly on BPF devices, so the workaround isn't necessary,
109 although it does no harm.)
110 .PP
111 Note also that
112 .B poll()
113 doesn't work on character special files, including BPF devices, in Mac
114 OS X 10.4 and 10.5, so, while
115 .B select()
116 can be used on the descriptor returned by
117 .BR pcap_get_selectable_fd() ,
118 .B poll()
119 cannot be used on it those versions of Mac OS X.  Kqueues also don't
120 work on that descriptor.
121 .BR poll() ,
122 but not kqueues, work on that descriptor in Mac OS X releases prior to
123 10.4;
124 .B poll()
125 and kqueues work on that descriptor in Mac OS X 10.6 and later.
126 .PP
127 .B pcap_get_selectable_fd()
128 is not available on Windows.
129 .SH RETURN VALUE
130 A selectable file descriptor is returned if one exists; otherwise, \-1
131 is returned.
132 .SH SEE ALSO
133 pcap(3PCAP), select(2), poll(2)