]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/libpcap/pcap_get_required_select_timeout.3pcap
sqlite3: Vendor import of sqlite3 3.45.0
[FreeBSD/FreeBSD.git] / contrib / libpcap / pcap_get_required_select_timeout.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_REQUIRED_SELECT_TIMEOUT 3PCAP "29 January 2020"
21 .SH NAME
22 pcap_get_required_select_timeout \- get a timeout to be used when doing
23 select() 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 const struct timeval *pcap_get_required_select_timeout(pcap_t *p);
32 .ft
33 .fi
34 .SH DESCRIPTION
35 .BR pcap_get_required_select_timeout ()
36 returns, on UNIX, a pointer to a
37 .B struct timeval
38 containing a value that must be used as the minimum timeout in
39 .BR select (2),
40 .BR poll (2),
41 .BR epoll_wait (2),
42 and
43 .BR kevent (2)
44 calls, or
45 .B NULL
46 if there is no such timeout.
47 If a
48 .RB non- NULL
49 value is returned, it must be used regardless of whether
50 .BR pcap_get_selectable_fd (3PCAP)
51 returns
52 .B \-1
53 for any descriptor on which those calls are being done.
54 .BR pcap_get_required_select_timeout ()
55 should be called for all
56 .BR pcap_t s
57 before a call to
58 .BR select (),
59 .BR poll (),
60 .BR epoll_wait (),
61 or
62 .BR kevent (),
63 and any timeouts used for those calls should be updated as appropriate
64 given the new value of the timeout.
65 .PP
66 For
67 .BR kevent (),
68 one
69 .B EVFILT_TIMER
70 filter per selectable descriptor can be used, rather than using the
71 timeout argument to
72 .BR kevent ();
73 if the
74 .B EVFILT_TIMER
75 event for a particular selectable descriptor signals an event,
76 .BR pcap_dispatch (3PCAP)
77 should be called for the corresponding
78 .BR pcap_t .
79 .PP
80 On Linux systems with
81 .BR timerfd_create (2),
82 one timer object created by
83 .BR timerfd_create ()
84 per selectable descriptor can be used, rather than using the timeout
85 argument to
86 .BR epoll_wait ();
87 if the
88 timer object for a particular selectable descriptor signals an event,
89 .BR pcap_dispatch (3PCAP)
90 should be called for the corresponding
91 .BR pcap_t .
92 .PP
93 Otherwise, a timeout value no larger than
94 the smallest of all timeouts returned by
95 .BR \%pcap_get_required_select_timeout ()
96 for devices from which packets will be captured and any other timeouts
97 to be used in the call should be used as the timeout for the call, and,
98 when the call returns,
99 .BR pcap_dispatch (3PCAP)
100 should be called for all
101 .BR pcap_t s
102 for which a
103 .RB non- NULL
104 timeout was returned, regardless of whether it's indicated as having
105 anything to read from it or not.
106 .PP
107 All devices with a
108 .RB non- NULL
109 timeout must be put in non-blocking mode with
110 .BR pcap_setnonblock (3PCAP).
111 .PP
112 Note that a device on which a read can be done without blocking may,
113 on some platforms, not have any packets to read if the packet buffer
114 timeout has expired.  A call to
115 .BR pcap_dispatch ()
116 or
117 .BR pcap_next_ex (3PCAP)
118 will return
119 .B 0
120 in this case, but will not block.
121 .PP
122 .BR pcap_get_required_select_timeout ()
123 is not available on Windows.
124 .SH RETURN VALUE
125 A pointer to a
126 .B struct timeval
127 is returned if the timeout is required; otherwise
128 .B NULL
129 is returned.
130 .SH BACKWARD COMPATIBILITY
131 This function became available in libpcap release 1.9.0.  In previous
132 releases,
133 .BR select (),
134 .BR poll (),
135 .BR epoll_wait (),
136 and
137 .BR kevent ()
138 could not be used for devices that don't provide a selectable file
139 descriptor (in other words, on any capture source for that
140 .BR pcap_get_selectable_fd ()
141 returns
142 .BR \-1 ).
143 .PP
144 In libpcap release 1.10.0 and later, the timeout value can change from
145 call to call, so
146 .BR pcap_get_required_select_timeout ()
147 must be called before each call to
148 .BR select (),
149 .BR poll (),
150 .BR epoll_wait (),
151 or
152 .BR kevent (),
153 and the new value must be used to calculate timeouts for the call.  Code
154 that does that will also work with libpcap 1.9.x releases, so code
155 using
156 .BR pcap_get_required_select_timeout ()
157 should be changed to call it for each call to
158 .BR select (),
159 .BR poll (),
160 .BR epoll_wait (),
161 or
162 .BR kevent ()
163 even if the code must also work with libpcap 1.9.x.
164 .SH SEE ALSO
165 .BR pcap (3PCAP),
166 .BR pcap_get_selectable_fd (3PCAP),
167 .BR select (2),
168 .BR poll (2),
169 .BR epoll_wait (2),
170 .BR kqueue (2)