---
name: "pcap_get_required_select_timeout"
section: "3"
platform: "freebsd"
package: "base"
version: "16.0-CURRENT-20261027-61c70dc16a79"
release: "FreeBSD 16.0-CURRENT (2026-10-27)"
platforms: ["freebsd"]
url: "https://new.carta.tech/pcap_get_required_select_timeout"
---

# pcap\_get\_required\_select\_timeout(3)

get a timeout to be used when doing select() for a live capture

## NAME

pcap\_get\_required\_select\_timeout - get a timeout to be used when doing select() for a live capture

## SYNOPSIS

```
#include <pcap/pcap.h>
```

**const struct timeval \*pcap\_get\_required\_select\_timeout(pcap\_t \*p);**

## DESCRIPTION

**pcap\_get\_required\_select\_timeout**() returns, on UNIX, a pointer to a **struct timeval** containing a value that must be used as the minimum timeout in [**select**(2)](/select/2.md), [**poll**(2)](/poll/2.md), [**epoll\_wait**(2)](/epoll_wait/2.md), and [**kevent**(2)](/kevent/2.md) calls, or **NULL** if there is no such timeout. If a non-**NULL** value is returned, it must be used regardless of whether [**pcap\_get\_selectable\_fd**(3)](/pcap_get_selectable_fd/3.md) returns **-1** for any descriptor on which those calls are being done. **pcap\_get\_required\_select\_timeout**() should be called for all **pcap\_t**s before a call to **select**(), **poll**(), **epoll\_wait**(), or **kevent**(), and any timeouts used for those calls should be updated as appropriate given the new value of the timeout.

For **kevent**(), one **EVFILT\_TIMER** filter per selectable descriptor can be used, rather than using the timeout argument to **kevent**(); if the **EVFILT\_TIMER** event for a particular selectable descriptor signals an event, [**pcap\_dispatch**(3)](/pcap_dispatch/3.md) should be called for the corresponding **pcap\_t**.

On Linux systems with [**timerfd\_create**(2)](/timerfd_create/2.md), one timer object created by **timerfd\_create**() per selectable descriptor can be used, rather than using the timeout argument to **epoll\_wait**(); if the timer object for a particular selectable descriptor signals an event, [**pcap\_dispatch**(3)](/pcap_dispatch/3.md) should be called for the corresponding **pcap\_t**.

Otherwise, a timeout value no larger than the smallest of all timeouts returned by **pcap\_get\_required\_select\_timeout**() for devices from which packets will be captured and any other timeouts to be used in the call should be used as the timeout for the call, and, when the call returns, [**pcap\_dispatch**(3)](/pcap_dispatch/3.md) should be called for all **pcap\_t**s for which a non-**NULL** timeout was returned, regardless of whether it's indicated as having anything to read from it or not.

All devices with a non-**NULL** timeout must be put in non-blocking mode with [**pcap\_setnonblock**(3)](/pcap_setnonblock/3.md).

Note that a device on which a read can be done without blocking may, on some platforms, not have any packets to read if the packet buffer timeout has expired.  A call to **pcap\_dispatch**() or [**pcap\_next\_ex**(3)](/pcap_next_ex/3.md) will return **0** in this case, but will not block.

**pcap\_get\_required\_select\_timeout**() is not available on Windows.

## RETURN VALUE

A pointer to a **struct timeval** is returned if the timeout is required; otherwise **NULL** is returned.

## BACKWARD COMPATIBILITY

This function became available in libpcap release 1.9.0.  In previous releases, **select**(), **poll**(), **epoll\_wait**(), and **kevent**() could not be used for devices that don't provide a selectable file descriptor (in other words, on any capture source for that **pcap\_get\_selectable\_fd**() returns **-1**).

In libpcap release 1.10.0 and later, the timeout value can change from call to call, so **pcap\_get\_required\_select\_timeout**() must be called before each call to **select**(), **poll**(), **epoll\_wait**(), or **kevent**(), and the new value must be used to calculate timeouts for the call.  Code that does that will also work with libpcap 1.9.x releases, so code using **pcap\_get\_required\_select\_timeout**() should be changed to call it for each call to **select**(), **poll**(), **epoll\_wait**(), or **kevent**() even if the code must also work with libpcap 1.9.x.

## SEE ALSO

[**pcap**(3)](/pcap/3.md), [**pcap\_get\_selectable\_fd**(3)](/pcap_get_selectable_fd/3.md), [**select**(2)](/select/2.md), [**poll**(2)](/poll/2.md), [**epoll\_wait**(2)](/epoll_wait/2.md), [**kqueue**(2)](/kqueue/2.md)
