1PCAP_SETNONBLOCK(3PCAP) PCAP_SETNONBLOCK(3PCAP)
2
3
4
6 pcap_setnonblock, pcap_getnonblock - set or get the state of non-block‐
7 ing mode on a capture device
8
10 #include <pcap/pcap.h>
11
12 char errbuf[PCAP_ERRBUF_SIZE];
13
14 int pcap_setnonblock(pcap_t *p, int nonblock, char *errbuf);
15 int pcap_getnonblock(pcap_t *p, char *errbuf);
16
18 pcap_setnonblock() puts a capture handle into ``non-blocking'' mode, or
19 takes it out of ``non-blocking'' mode, depending on whether the non‐
20 block argument is non-zero or zero. It has no effect on ``savefiles''.
21 If there is an error, PCAP_ERROR is returned and errbuf is filled in
22 with an appropriate error message; otherwise, 0 is returned.
23
24 In ``non-blocking'' mode, an attempt to read from the capture descrip‐
25 tor with pcap_dispatch(3PCAP) and pcap_next_ex(3PCAP) will, if no pack‐
26 ets are currently available to be read, return 0 immediately rather
27 than blocking waiting for packets to arrive.
28
29 pcap_loop(3PCAP) will loop forever, consuming CPU time when no packets
30 are currently available; pacp_dispatch() should be used instead.
31 pcap_next(3PCAP) will return NULL if there are no packets currently
32 available to read; this is indistinguishable from an error, so
33 pcap_next_ex() should be used instead.
34
35 When first activated with pcap_activate(3PCAP) or opened with
36 pcap_open_live(3PCAP), a capture handle is not in ``non-blocking
37 mode''; a call to pcap_setnonblock() is required in order to put it
38 into ``non-blocking'' mode.
39
41 pcap_getnonblock() returns the current ``non-blocking'' state of the
42 capture descriptor; it always returns 0 on ``savefiles''. If there is
43 an error, PCAP_ERROR is returned and errbuf is filled in with an appro‐
44 priate error message.
45
46 errbuf is assumed to be able to hold at least PCAP_ERRBUF_SIZE chars.
47
49 pcap(3PCAP), pcap_next_ex(3PCAP), pcap_geterr(3PCAP)
50
51
52
53 25 July 2018 PCAP_SETNONBLOCK(3PCAP)