---
name: "pcap_getnonblock"
section: "3pcap"
platform: "linux"
package: "libpcap"
version: "1.11.0-1"
release: "Arch Linux 2026-11-01"
platforms: ["linux"]
url: "https://new.carta.tech/pcap_setnonblock/3pcap"
---

# pcap\_getnonblock(3pcap)

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

Part of [pcap\_setnonblock(3pcap)](/pcap_setnonblock/3pcap.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**(3PCAP) and **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) will loop forever, consuming CPU time when no packets are currently available; **pcap\_dispatch**() should be used instead. **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) or opened with **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

**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**(3PCAP), **pcap\_next\_ex**(3PCAP), **pcap\_geterr**(3PCAP)
