1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
|
.\" $OpenBSD: BIO_ctrl.3,v 1.9 2018/03/20 19:33:16 schwarze Exp $
.\" OpenSSL b055fceb Thu Oct 20 09:56:18 2016 +0100
.\"
.\" This file was written by Dr. Stephen Henson <steve@openssl.org>.
.\" Copyright (c) 2000, 2016 The OpenSSL Project. All rights reserved.
.\"
.\" Redistribution and use in source and binary forms, with or without
.\" modification, are permitted provided that the following conditions
.\" are met:
.\"
.\" 1. Redistributions of source code must retain the above copyright
.\" notice, this list of conditions and the following disclaimer.
.\"
.\" 2. Redistributions in binary form must reproduce the above copyright
.\" notice, this list of conditions and the following disclaimer in
.\" the documentation and/or other materials provided with the
.\" distribution.
.\"
.\" 3. All advertising materials mentioning features or use of this
.\" software must display the following acknowledgment:
.\" "This product includes software developed by the OpenSSL Project
.\" for use in the OpenSSL Toolkit. (http://www.openssl.org/)"
.\"
.\" 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
.\" endorse or promote products derived from this software without
.\" prior written permission. For written permission, please contact
.\" openssl-core@openssl.org.
.\"
.\" 5. Products derived from this software may not be called "OpenSSL"
.\" nor may "OpenSSL" appear in their names without prior written
.\" permission of the OpenSSL Project.
.\"
.\" 6. Redistributions of any form whatsoever must retain the following
.\" acknowledgment:
.\" "This product includes software developed by the OpenSSL Project
.\" for use in the OpenSSL Toolkit (http://www.openssl.org/)"
.\"
.\" THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
.\" EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
.\" PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
.\" ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
.\" SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
.\" NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
.\" LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
.\" STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
.\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
.\" OF THE POSSIBILITY OF SUCH DAMAGE.
.\"
.Dd $Mdocdate: March 20 2018 $
.Dt BIO_CTRL 3
.Os
.Sh NAME
.Nm BIO_ctrl ,
.Nm BIO_callback_ctrl ,
.Nm BIO_ptr_ctrl ,
.Nm BIO_int_ctrl ,
.Nm BIO_reset ,
.Nm BIO_seek ,
.Nm BIO_tell ,
.Nm BIO_flush ,
.Nm BIO_eof ,
.Nm BIO_set_close ,
.Nm BIO_get_close ,
.Nm BIO_pending ,
.Nm BIO_wpending ,
.Nm BIO_ctrl_pending ,
.Nm BIO_ctrl_wpending ,
.Nm BIO_get_info_callback ,
.Nm BIO_set_info_callback ,
.Nm bio_info_cb
.Nd BIO control operations
.Sh SYNOPSIS
.In openssl/bio.h
.Ft long
.Fo BIO_ctrl
.Fa "BIO *bp"
.Fa "int cmd"
.Fa "long larg"
.Fa "void *parg"
.Fc
.Ft long
.Fo BIO_callback_ctrl
.Fa "BIO *b"
.Fa "int cmd"
.Fa "bio_info_cb cb"
.Fc
.Ft char *
.Fo BIO_ptr_ctrl
.Fa "BIO *bp"
.Fa "int cmd"
.Fa "long larg"
.Fc
.Ft long
.Fo BIO_int_ctrl
.Fa "BIO *bp"
.Fa "int cmd"
.Fa "long larg"
.Fa "int iarg"
.Fc
.Ft int
.Fo BIO_reset
.Fa "BIO *b"
.Fc
.Ft int
.Fo BIO_seek
.Fa "BIO *b"
.Fa "int ofs"
.Fc
.Ft int
.Fo BIO_tell
.Fa "BIO *b"
.Fc
.Ft int
.Fo BIO_flush
.Fa "BIO *b"
.Fc
.Ft int
.Fo BIO_eof
.Fa "BIO *b"
.Fc
.Ft int
.Fo BIO_set_close
.Fa "BIO *b"
.Fa "long flag"
.Fc
.Ft int
.Fo BIO_get_close
.Fa "BIO *b"
.Fc
.Ft int
.Fo BIO_pending
.Fa "BIO *b"
.Fc
.Ft int
.Fo BIO_wpending
.Fa "BIO *b"
.Fc
.Ft size_t
.Fo BIO_ctrl_pending
.Fa "BIO *b"
.Fc
.Ft size_t
.Fo BIO_ctrl_wpending
.Fa "BIO *b"
.Fc
.Ft int
.Fo BIO_get_info_callback
.Fa "BIO *b"
.Fa "bio_info_cb **cbp"
.Fc
.Ft int
.Fo BIO_set_info_callback
.Fa "BIO *b"
.Fa "bio_info_cb *cb"
.Fc
.Ft typedef void
.Fo bio_info_cb
.Fa "BIO *b"
.Fa "int oper"
.Fa "const char *ptr"
.Fa "int arg1"
.Fa "long arg2"
.Fa "long arg3"
.Fc
.Sh DESCRIPTION
.Fn BIO_ctrl ,
.Fn BIO_callback_ctrl ,
.Fn BIO_ptr_ctrl ,
and
.Fn BIO_int_ctrl
are BIO "control" operations taking arguments of various types.
These functions are not normally called directly -
various macros are used instead.
The standard macros are described below.
Macros specific to a particular type of BIO
are described in the specific BIO's manual page
as well as any special features of the standard calls.
.Pp
.Fn BIO_reset
typically resets a BIO to some initial state.
In the case of file related BIOs, for example,
it rewinds the file pointer to the start of the file.
.Pp
.Fn BIO_seek
resets a file related BIO's (that is file descriptor and
FILE BIOs) file position pointer to
.Fa ofs
bytes from start of file.
.Pp
.Fn BIO_tell
returns the current file position of a file related BIO.
.Pp
.Fn BIO_flush
normally writes out any internally buffered data.
In some cases it is used to signal EOF and that no more data will be written.
.Pp
.Fn BIO_eof
returns 1 if the BIO has read EOF.
The precise meaning of "EOF" varies according to the BIO type.
.Pp
.Fn BIO_set_close
sets the BIO
.Fa b
close flag to
.Fa flag .
.Fa flag
can take the value
.Dv BIO_CLOSE
or
.Dv BIO_NOCLOSE .
Typically
.Dv BIO_CLOSE
is used in a source/sink BIO to indicate that the underlying I/O stream
should be closed when the BIO is freed.
.Pp
.Fn BIO_get_close
returns the BIO's close flag.
.Pp
.Fn BIO_pending ,
.Fn BIO_ctrl_pending ,
.Fn BIO_wpending ,
and
.Fn BIO_ctrl_wpending
return the number of pending characters in the BIO's read and write buffers.
Not all BIOs support these calls.
.Fn BIO_ctrl_pending
and
.Fn BIO_ctrl_wpending
return a
.Vt size_t
type and are functions.
.Fn BIO_pending
and
.Fn BIO_wpending
are macros which call
.Fn BIO_ctrl .
.Sh RETURN VALUES
.Fn BIO_reset
normally returns 1 for success and 0 or -1 for failure.
File BIOs are an exception, returning 0 for success and -1 for failure.
.Pp
.Fn BIO_seek
and
.Fn BIO_tell
both return the current file position on success
and -1 for failure, except file BIOs which for
.Fn BIO_seek
always return 0 for success and -1 for failure.
.Pp
.Fn BIO_flush
returns 1 for success and 0 or -1 for failure.
.Pp
.Fn BIO_eof
returns 1 if EOF has been reached or 0 otherwise.
.Pp
.Fn BIO_set_close
always returns 1.
.Pp
.Fn BIO_get_close
returns the close flag value
.Dv BIO_CLOSE
or
.Dv BIO_NOCLOSE .
.Pp
.Fn BIO_pending ,
.Fn BIO_ctrl_pending ,
.Fn BIO_wpending ,
and
.Fn BIO_ctrl_wpending
return the amount of pending data.
.Sh NOTES
Because it can write data,
.Fn BIO_flush
may return 0 or -1 indicating that the call should be retried later
in a similar manner to
.Xr BIO_write 3 .
The
.Xr BIO_should_retry 3
call should be used and appropriate action taken if the call fails.
.Pp
The return values of
.Fn BIO_pending
and
.Fn BIO_wpending
may not reliably determine the amount of pending data in all cases.
For example in the case of a file BIO some data may be available in the
.Vt FILE
structure's internal buffers but it is not possible
to determine this in a portable way.
For other types of BIO they may not be supported.
.Pp
If they do not internally handle a particular
.Fn BIO_ctrl
operation, filter BIOs usually pass the operation
to the next BIO in the chain.
This often means there is no need to locate the required BIO for
a particular operation: it can be called on a chain and it will
be automatically passed to the relevant BIO.
However this can cause unexpected results.
For example no current filter BIOs implement
.Fn BIO_seek ,
but this may still succeed if the chain ends
in a FILE or file descriptor BIO.
.Pp
Source/sink BIOs return an 0 if they do not recognize the
.Fn BIO_ctrl
operation.
.Sh SEE ALSO
.Xr BIO_meth_new 3 ,
.Xr BIO_new 3
.Sh HISTORY
.Fn BIO_ctrl ,
.Fn BIO_ctrl_int ,
.Fn BIO_reset ,
.Fn BIO_flush ,
.Fn BIO_eof ,
.Fn BIO_set_close ,
.Fn BIO_get_close ,
.Fn BIO_pending ,
and
.Fn BIO_wpending
appeared in SSLeay 0.8.1b or earlier and have been available since
.Ox 2.4 .
.Sh BUGS
Some of the return values are ambiguous and care should be taken.
In particular a return value of 0 can be returned if an operation
is not supported, if an error occurred, if EOF has not been reached
and in the case of
.Fn BIO_seek
on a file BIO for a successful operation.
|