1PCAP_SETNONBLOCK(3PCAP)                                PCAP_SETNONBLOCK(3PCAP)
2
3
4

NAME

6       pcap_setnonblock, pcap_getnonblock - set or get the state of non-block‐
7       ing mode on a capture device
8

SYNOPSIS

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

DESCRIPTION

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;  pcap_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

RETURN VALUE

41       pcap_getnonblock() returns the current ``non-blocking''  state  of  the
42       capture descriptor; it always returns 0 on ``savefiles''.  If called on
43       a capture handle that has been  created  but  not  activated,  PCAP_ER‐
44       ROR_NOT_ACTIVATED  is  returned.  If there is another error, PCAP_ERROR
45       is returned and errbuf is filled in with an appropriate error message.
46
47       errbuf is assumed to be able to hold at least PCAP_ERRBUF_SIZE chars.
48

SEE ALSO

50       pcap(3PCAP), pcap_next_ex(3PCAP), pcap_geterr(3PCAP)
51
52
53
54                                 5 March 2022          PCAP_SETNONBLOCK(3PCAP)
Impressum