]> The Tcpdump Group git mirrors - libpcap/blob - pcap_setnonblock.3pcap
Fixup indentation in init_linktype().
[libpcap] / pcap_setnonblock.3pcap
1 .\" Copyright (c) 1994, 1996, 1997
2 .\" The Regents of the University of California. All rights reserved.
3 .\"
4 .\" Redistribution and use in source and binary forms, with or without
5 .\" modification, are permitted provided that: (1) source code distributions
6 .\" retain the above copyright notice and this paragraph in its entirety, (2)
7 .\" distributions including binary code include the above copyright notice and
8 .\" this paragraph in its entirety in the documentation or other materials
9 .\" provided with the distribution, and (3) all advertising materials mentioning
10 .\" features or use of this software display the following acknowledgement:
11 .\" ``This product includes software developed by the University of California,
12 .\" Lawrence Berkeley Laboratory and its contributors.'' Neither the name of
13 .\" the University nor the names of its contributors may be used to endorse
14 .\" or promote products derived from this software without specific prior
15 .\" written permission.
16 .\" THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED
17 .\" WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
18 .\" MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
19 .\"
20 .TH PCAP_SETNONBLOCK 3PCAP "30 November 2023"
21 .SH NAME
22 pcap_setnonblock, pcap_getnonblock \- set or get the state of
23 non-blocking mode on a capture device
24 .SH SYNOPSIS
25 .nf
26 .ft B
27 #include <pcap/pcap.h>
28 .ft
29 .LP
30 .nf
31 .ft B
32 char errbuf[PCAP_ERRBUF_SIZE];
33 .ft
34 .LP
35 .ft B
36 int pcap_setnonblock(pcap_t *p, int nonblock, char *errbuf);
37 int pcap_getnonblock(pcap_t *p, char *errbuf);
38 .ft
39 .fi
40 .SH DESCRIPTION
41 .BR pcap_setnonblock ()
42 puts a capture handle into ``non-blocking'' mode, or takes it out
43 of ``non-blocking'' mode, depending on whether the
44 .I nonblock
45 argument is non-zero or zero. It has no effect on ``savefiles''.
46 .I errbuf
47 is a buffer large enough to hold at least
48 .B PCAP_ERRBUF_SIZE
49 chars.
50 .PP
51 In
52 ``non-blocking'' mode, an attempt to read from the capture descriptor
53 with
54 .BR pcap_dispatch (3PCAP)
55 and
56 .BR pcap_next_ex (3PCAP)
57 will, if no packets are currently available to be read, return
58 .B 0
59 immediately rather than blocking waiting for packets to arrive.
60 .PP
61 .BR pcap_loop (3PCAP)
62 will loop forever, consuming CPU time when no packets are currently
63 available;
64 .BR pcap_dispatch ()
65 should be used instead.
66 .BR pcap_next (3PCAP)
67 will return
68 .B NULL
69 if there are no packets currently available to read;
70 this is indistinguishable from an error, so
71 .BR pcap_next_ex ()
72 should be used instead.
73 .PP
74 When first activated with
75 .BR pcap_activate (3PCAP)
76 or opened with
77 .BR pcap_open_live (3PCAP),
78 a capture handle is not in ``non-blocking mode''; a call to
79 .BR pcap_setnonblock ()
80 is required in order to put it into ``non-blocking'' mode.
81 .SH RETURN VALUE
82 .BR pcap_setnonblock()
83 return 0 on success,
84 .B PCAP_ERROR_NOT_ACTIVATED
85 if called on a capture handle that has been created but not activated,
86 and
87 .B PCAP_ERROR
88 for other errors.
89 .BR pcap_getnonblock ()
90 returns the current ``non-blocking'' state of the capture descriptor on
91 success; it always returns
92 .B 0
93 on ``savefiles''.
94 It returns
95 .B PCAP_ERROR_NOT_ACTIVATED
96 if called on a capture handle that has been created but not activated,
97 and
98 .B PCAP_ERROR
99 for other errors.
100 If
101 .B PCAP_ERROR
102 is returned,
103 .I errbuf
104 is filled in with an appropriate error message.
105 .SH SEE ALSO
106 .BR pcap (3PCAP),
107 .BR pcap_next_ex (3PCAP),
108 .BR pcap_geterr (3PCAP)