BIO_CTRL(3)
π BIO_CTRL(3) π
okay so this is from the Library Functions Manual, bestie, and it is literally the whole group chat of BIO control operations. We are talking libcrypto energy, no cap. β¨
πΈ NAME πΈ
BIO_ctrl,BIO_callback_ctrl,BIO_ptr_ctrl,BIO_int_ctrl,BIO_reset,BIO_seek,BIO_tell,BIO_flush,BIO_eof,BIO_set_close,BIO_get_close,BIO_pending,BIO_wpending,BIO_ctrl_pending,BIO_ctrl_wpending,BIO_get_info_callback,BIO_set_info_callback,BIO_info_cb,bio_info_cbβ BIO control operations π
π¦ SYNOPSIS π¦
the library line and every prototype, exactly as printed, no cap π«Ά
library βlibcryptoβ #include <openssl/bio.h>
long
BIO_ctrl(BIO *b, int cmd, long larg, void *parg);
long
BIO_callback_ctrl(BIO *b, int cmd, BIO_info_cb *cb);
char *
BIO_ptr_ctrl(BIO *b, int cmd, long larg);
long
BIO_int_ctrl(BIO *b, int cmd, long larg, int iarg);
int
BIO_reset(BIO *b);
int
BIO_seek(BIO *b, int ofs);
int
BIO_tell(BIO *b);
int
BIO_flush(BIO *b);
int
BIO_eof(BIO *b);
int
BIO_set_close(BIO *b, long flag);
int
BIO_get_close(BIO *b);
int
BIO_pending(BIO *b);
int
BIO_wpending(BIO *b);
size_t
BIO_ctrl_pending(BIO *b);
size_t
BIO_ctrl_wpending(BIO *b);
int
BIO_get_info_callback(BIO *b, BIO_info_cb **cbp);
int
BIO_set_info_callback(BIO *b, BIO_info_cb *cb);
typedef int
BIO_info_cb(BIO *b, int state, int res);
typedef int
bio_info_cb(BIO *b, int state, int res);
β¨ DESCRIPTION β¨
okay so BIO_ctrl(), BIO_callback_ctrl(), BIO_ptr_ctrl(), and BIO_int_ctrl() are the BIO βcontrolβ operations β they take arguments of various types. You do not normally call these directly, bestie: the standard macros are the move. The standard macros are described below, and macros specific to a particular type of BIO are described in that BIO's own manual page, along with any special features of the standard calls. π
Depending on cmd and on the type of b, BIO_ctrl() may have a read-only effect on b, or it may change data in b or in its sub-structures. It may also have a side effect of changing the memory pointed to by parg. π¦
BIO_callback_ctrl() does not call BIO_ctrl() β nope β instead it requires that the BIO type of b provides a dedicated callback_ctrl function pointer. That pointer is built into the library for some standard BIO types, and you can provide it with BIO_meth_set_callback_ctrl(3) for application-defined BIO types. The only cmd supported by BIO_callback_ctrl() is BIO_CTRL_SET_CALLBACK. β¨
BIO_ptr_ctrl() calls BIO_ctrl() with parg pointing to the location of a temporary pointer variable initialized to NULL. π
BIO_int_ctrl() calls BIO_ctrl() with parg pointing to the location of a temporary int variable initialized to iarg. If BIO_ctrl() changes the value stored at *parg, the new value is ignored. π
BIO_reset()β typically resets a BIO to some initial state. For file related BIOs, for example, it rewinds the file pointer to the start of the file. πBIO_seek()β resets a file related BIO's (that is file descriptor and FILE BIOs) file position pointer toofsbytes from start of file. βBIO_tell()β returns the current file position of a file related BIO. π₯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. π«BIO_eof()β returns1if the BIO has read EOF. The precise meaning of βEOFβ varies according to the BIO type. πBIO_set_close()β sets the BIObclose flag toflag.flagcan take the valueBIO_CLOSEorBIO_NOCLOSE. TypicallyBIO_CLOSEis used in a source/sink BIO to indicate that the underlying I/O stream should be closed when the BIO is freed. πBIO_get_close()β returns the BIO's close flag. πΈBIO_pending(),BIO_ctrl_pending(),BIO_wpending(), andBIO_ctrl_wpending()β return the number of pending characters in the BIO's read and write buffers. Not all BIOs support these calls.BIO_ctrl_pending()andBIO_ctrl_wpending()return asize_ttype and are functions. π§BIO_set_info_callback()β installs the function pointercbas an info callback inbby callingBIO_callback_ctrl()with a command ofBIO_CTRL_SET_CALLBACK. Among the BIO types built into the library, onlyBIO_s_connect(3)andBIO_f_ssl(3)support this functionality. Some filter BIO types forward this control call to the next BIO in the chain instead of processing it themselves. π₯BIO_get_info_callback()β places the function pointer to the info callback into*cbpif any was installed usingBIO_set_info_callback()orBIO_callback_ctrl(). If the type ofbsupports setting an info callback but none was installed, it stores aNULLpointer in*cbp. π
The function type name bio_info_cb is a deprecated synonym for BIO_info_cb provided for backward compatibility with some existing application software. β οΈ
π
the cmd constants that correspond to macros π
The following cmd constants correspond to macros β every single one, no skipping, bestie:
BIO_C_DESTROY_BIO_PAIRβBIO_destroy_bio_pair(3)BIO_C_DO_STATE_MACHINEβBIO_do_handshake(3)BIO_C_FILE_SEEKβBIO_seek()BIO_C_FILE_TELLβBIO_tell()BIO_C_GET_ACCEPTβBIO_get_accept_port(3)BIO_C_GET_BIND_MODEβBIO_get_bind_mode(3)BIO_C_GET_BUF_MEM_PTRβBIO_get_mem_ptr(3)BIO_C_GET_BUFF_NUM_LINESβBIO_get_buffer_num_lines(3)BIO_C_GET_CIPHER_CTXβBIO_get_cipher_ctx(3)BIO_C_GET_CIPHER_STATUSβBIO_get_cipher_status(3)BIO_C_GET_FDβBIO_get_fd(3)BIO_C_GET_FILE_PTRβBIO_get_fp(3)BIO_C_GET_MDβBIO_get_md(3)BIO_C_GET_MD_CTXβBIO_get_md_ctx(3)BIO_C_GET_READ_REQUESTβBIO_get_read_request(3)BIO_C_GET_SSLβBIO_get_ssl(3)BIO_C_GET_SSL_NUM_RENEGOTIATESβBIO_get_num_renegotiates(3)BIO_C_GET_WRITE_BUF_SIZEβBIO_get_write_buf_size(3)BIO_C_GET_WRITE_GUARANTEEβBIO_get_write_guarantee(3)BIO_C_MAKE_BIO_PAIRβBIO_make_bio_pair(3)BIO_C_RESET_READ_REQUESTβBIO_ctrl_reset_read_request(3)BIO_C_SET_BIND_MODEβBIO_set_bind_mode(3)BIO_C_SET_BUF_MEMβBIO_set_mem_buf(3)BIO_C_SET_BUF_MEM_EOF_RETURNβBIO_set_mem_eof_return(3)BIO_C_SET_BUFF_READ_DATAβBIO_set_buffer_read_data(3)BIO_C_SET_FDβBIO_set_fd(3)BIO_C_SET_FILE_PTRβBIO_set_fp(3)BIO_C_SET_MDβBIO_set_md(3)BIO_C_SET_MD_CTXβBIO_set_md_ctx(3)BIO_C_SET_NBIOβBIO_set_nbio(3)BIO_C_SET_SSLβBIO_set_ssl(3)BIO_C_SET_SSL_RENEGOTIATE_BYTESβBIO_set_ssl_renegotiate_bytes(3)BIO_C_SET_SSL_RENEGOTIATE_TIMEOUTβBIO_set_ssl_renegotiate_timeout(3)BIO_C_SET_WRITE_BUF_SIZEβBIO_set_write_buf_size(3)BIO_C_SHUTDOWN_WRβBIO_shutdown_wr(3)BIO_C_SSL_MODEβBIO_set_ssl_mode(3)BIO_CTRL_DGRAM_CONNECTβBIO_ctrl_dgram_connect(3)BIO_CTRL_DGRAM_GET_PEERβBIO_dgram_get_peer(3)BIO_CTRL_DGRAM_GET_RECV_TIMER_EXPβBIO_dgram_recv_timedout(3)BIO_CTRL_DGRAM_GET_SEND_TIMER_EXPβBIO_dgram_send_timedout(3)BIO_CTRL_DGRAM_SET_CONNECTEDβBIO_ctrl_set_connected(3)BIO_CTRL_DGRAM_SET_PEERβBIO_dgram_set_peer(3)BIO_CTRL_DUPβBIO_dup_state(3)BIO_CTRL_EOFβBIO_eof()BIO_CTRL_FLUSHβBIO_flush()BIO_CTRL_GET_CALLBACKβBIO_get_info_callback()BIO_CTRL_GET_CLOSEβBIO_get_close()BIO_CTRL_INFOβBIO_get_mem_data(3)BIO_CTRL_PENDINGβBIO_pending()BIO_CTRL_RESETβBIO_reset()BIO_CTRL_SET_CALLBACKβBIO_set_info_callback()BIO_CTRL_SET_CLOSEβBIO_set_close()BIO_CTRL_WPENDINGβBIO_wpending()
π the cmd constants that serve more than one macro π
A few cmd constants serve more than one macro each and are documented in the following manual pages:
BIO_C_GET_CONNECTβBIO_s_connect(3)BIO_C_SET_ACCEPTβBIO_s_accept(3)BIO_C_SET_BUFF_SIZEβBIO_f_buffer(3)BIO_C_SET_CONNECTβBIO_s_connect(3)BIO_C_SET_FILENAMEβBIO_s_file(3)
π¦ the cmd constants with no macro attached π¦
Some cmd constants are not associated with any macros. They are documented in the following manual pages:
BIO_CTRL_DGRAM_GET_FALLBACK_MTUβBIO_dgram_set_peer(3)BIO_CTRL_DGRAM_GET_MTUβBIO_dgram_set_peer(3)BIO_CTRL_DGRAM_GET_RECV_TIMEOUTβBIO_dgram_recv_timedout(3)BIO_CTRL_DGRAM_GET_SEND_TIMEOUTβBIO_dgram_send_timedout(3)BIO_CTRL_DGRAM_SET_MTUβBIO_dgram_set_peer(3)BIO_CTRL_DGRAM_SET_NEXT_TIMEOUTβBIO_dgram_recv_timedout(3)BIO_CTRL_DGRAM_SET_RECV_TIMEOUTβBIO_dgram_recv_timedout(3)BIO_CTRL_DGRAM_SET_SEND_TIMEOUTβBIO_dgram_send_timedout(3)BIO_CTRL_DGRAM_MTU_EXCEEDEDβBIO_s_datagram(3)BIO_CTRL_POPβBIO_pop(3)BIO_CTRL_PUSHβBIO_push(3)
π RETURN VALUES π
The meaning of the return values of BIO_ctrl(), BIO_callback_ctrl(), and BIO_int_ctrl() depends on both the type of b and on the cmd. If b is a NULL pointer, no action occurs and 0 is returned. The return value -2 usually indicates a fatal error. In particular, it is returned if the cmd is unsupported by the type of b. π
BIO_callback_ctrl()andBIO_set_info_callback()β return1on success,0ifbisNULLor to indicate failure of a validcmd, or-2if thecmdis not supported byb. πBIO_ptr_ctrl()β returnsNULLif theBIO_ctrl()call returns a negative value or does not change*parg, or the pointer it puts into*pargotherwise. πBIO_int_ctrl()β returns the return value ofBIO_ctrl(). β¨BIO_reset()β normally returns1for success and0or-1for failure. File BIOs are an exception, returning0for success and-1for failure. πΈBIO_seek()andBIO_tell()β both return the current file position on success and-1for failure, except file BIOs which forBIO_seek()always return0for success and-1for failure. π¦BIO_flush()β returns1for success and0or-1for failure. π₯BIO_eof()β returns1if EOF has been reached or0otherwise. πBIO_set_close()β always returns1. πBIO_get_close()β returns the close flag valueBIO_CLOSEorBIO_NOCLOSE. βBIO_pending(),BIO_ctrl_pending(),BIO_wpending(), andBIO_ctrl_wpending()β return the amount of pending data. π§BIO_get_info_callback()β returns1on success, including when the type ofbsupports an info callback but none is installed,0ifbisNULLor-2if the type ofbdoes not support an info callback. π
If a callback was installed in b using BIO_set_callback_ex(3) or BIO_set_callback(3), it can modify the return values of all these functions. π
β¨ NOTES β¨
Okay so bestie, BIO_flush() can write data, which means it may return 0 or -1 to tell you the call should be retried later β basically the same way BIO_write(3) does. Use BIO_should_retry(3) and take the appropriate action if the call fails. No cap.
The return values of BIO_pending() and BIO_wpending() might not reliably tell you how much pending data there is in every case. For example, with a file BIO, some data may be available in the FILE structure's internal buffers, but there is no portable way to determine that. For other types of BIO, those calls may not be supported at all. π
If filter BIOs do not internally handle a particular BIO_ctrl() operation, they 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: you can call it 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 BIO_seek(), but this may still succeed if the chain ends in a FILE or file descriptor BIO. It's giving plot twist energy. π
Source/sink BIOs return a 0 if they do not recognize the BIO_ctrl() operation.
π SEE ALSO π
π°οΈ HISTORY π°οΈ
BIO_ctrl(),BIO_reset(),BIO_flush(),BIO_eof(),BIO_set_close(),BIO_get_close(), andBIO_pending()first appeared in SSLeay 0.6.0.BIO_wpending()first appeared in SSLeay 0.8.1.BIO_ptr_ctrl(),BIO_int_ctrl(),BIO_get_info_callback()andBIO_set_info_callback()first appeared in SSLeay 0.9.0.- All these functions have been available since OpenBSD 2.4.
BIO_seek()andBIO_tell()first appeared in SSLeay 0.9.1.BIO_ctrl_pending()andBIO_ctrl_wpending()first appeared in OpenSSL 0.9.4. These functions have been available since OpenBSD 2.6.BIO_callback_ctrl()first appeared in OpenSSL 0.9.5 and has been available since OpenBSD 2.7.bio_info_cb()first appeared with a more complicated prototype in OpenSSL 0.9.6 and has been available since OpenBSD 2.9.BIO_info_cb()first appeared in OpenSSL 1.1.0h and has been available since OpenBSD 6.3.
π BUGS π
Some of the return values are ambiguous, so 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 BIO_seek() on a file BIO for a successful operation. So yeah β 0 is lowkey wearing a disguise sometimes. π
Source/version is Debian, the date is June 8, 2025, and this iconic lil' page is BIO_CTRL(3). Periodt. π
π
π¦ where this page comes from
- alpine 3.24: libressl-doc 4.3.1-r0 Β· custom
- arch rolling: libressl 4.4.0-1 Β· ISC AND custom:OpenSSL
- Copyright (c) 2023 Ingo Schwarze <schwarze@openbsd.org>
- Copyright (c) 2000, 2016 The OpenSSL Project. All rights reserved
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms