PCAP\_SETNONBLOCK(3PCAP) PCAP\_SETNONBLOCK(3PCAP)

# [NAME](#NAME)

pcap\_setnonblock, pcap\_getnonblock - set or get the state of non-blocking mode on a capture device

# [SYNOPSIS](#SYNOPSIS)

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

```


char errbuf[PCAP_ERRBUF_SIZE];
```

```
int pcap_setnonblock(pcap_t *p, int nonblock, char *errbuf);
int pcap_getnonblock(pcap_t *p, char *errbuf);
```

# [DESCRIPTION](#DESCRIPTION)

**pcap\_setnonblock**() puts a capture handle into \`\`non-blocking'' mode, or takes it out of \`\`non-blocking'' mode, depending on whether the *nonblock* argument is non-zero or zero. It has no effect on \`\`savefiles''. *errbuf* is a buffer large enough to hold at least **PCAP\_ERRBUF\_SIZE** chars.

In \`\`non-blocking'' mode, an attempt to read from the capture descriptor with [**pcap\_dispatch**(3PCAP)](/man/os/libpcap/pcap_dispatch.3PCAP) and [**pcap\_next\_ex**(3PCAP)](/man/os/libpcap/pcap_next_ex.3PCAP) will, if no packets are currently available to be read, return **0** immediately rather than blocking waiting for packets to arrive.

[**pcap\_loop**(3PCAP)](/man/os/libpcap/pcap_loop.3PCAP) will loop forever, consuming CPU time when no packets are currently available; **pcap\_dispatch**() should be used instead. [**pcap\_next**(3PCAP)](/man/os/libpcap/pcap_next.3PCAP) will return a null pointer if there are no packets currently available to read; this is indistinguishable from an error, so **pcap\_next\_ex**() should be used instead.

When first activated with [**pcap\_activate**(3PCAP)](/man/os/libpcap/pcap_activate.3PCAP) or opened with [**pcap\_open\_live**(3PCAP)](/man/os/libpcap/pcap_open_live.3PCAP), a capture handle is not in \`\`non-blocking mode''; a call to **pcap\_setnonblock**() is required in order to put it into \`\`non-blocking'' mode.

# [RETURN VALUE](#RETURN_VALUE)

**pcap\_setnonblock()** return 0 on success, **PCAP\_ERROR\_NOT\_ACTIVATED** if called on a capture handle that has been created but not activated, and **PCAP\_ERROR** for other errors. **pcap\_getnonblock**() returns the current \`\`non-blocking'' state of the capture descriptor on success; it always returns **0** on \`\`savefiles''. It returns **PCAP\_ERROR\_NOT\_ACTIVATED** if called on a capture handle that has been created but not activated, and **PCAP\_ERROR** for other errors. If **PCAP\_ERROR** is returned, *errbuf* is filled in with an appropriate error message.

# [SEE ALSO](#SEE_ALSO)

[**pcap**(3PCAP)](/man/os/libpcap/pcap.3PCAP), [**pcap\_next\_ex**(3PCAP)](/man/os/libpcap/pcap_next_ex.3PCAP), [**pcap\_geterr**(3PCAP)](/man/os/libpcap/pcap_geterr.3PCAP)

6 September 2026

---

Document: pcap_getnonblock(3pcap) from libpcap 1.11.0-r0 (Chainguard OS)
Source: https://github.com/the-tcpdump-group/libpcap.git
