---
name: "pcap_setnonblock"
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_getnonblock"
---

# pcap\_setnonblock(3)

set or get the state of non-blocking mode on a capture device

Part of [pcap\_getnonblock(3)](/pcap_getnonblock/3.md).

## NAME

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

## 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

**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**(3)](/pcap_dispatch/3.md) and [**pcap\_next\_ex**(3)](/pcap_next_ex/3.md) will, if no packets are currently available to be read, return **0** immediately rather than blocking waiting for packets to arrive.

[**pcap\_loop**(3)](/pcap_loop/3.md) will loop forever, consuming CPU time when no packets are currently available; **pcap\_dispatch**() should be used instead. [**pcap\_next**(3)](/pcap_next/3.md) will return **NULL** 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**(3)](/pcap_activate/3.md) or opened with [**pcap\_open\_live**(3)](/pcap_open_live/3.md), 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

**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

[**pcap**(3)](/pcap/3.md), [**pcap\_next\_ex**(3)](/pcap_next_ex/3.md), [**pcap\_geterr**(3)](/pcap_geterr/3.md)
