BIO_CTRL(3)

πŸ“¦ version 4.4.0, in alpine 3.24, arch rolling

πŸ’… 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 to ofs bytes 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() β€” returns 1 if the BIO has read EOF. The precise meaning of β€œEOF” varies according to the BIO type. πŸ‘‘
  • BIO_set_close() β€” sets the BIO b close flag to flag. flag can take the value BIO_CLOSE or BIO_NOCLOSE. Typically 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. πŸŽ€
  • BIO_get_close() β€” returns the BIO's close flag. 🌸
  • BIO_pending(), BIO_ctrl_pending(), BIO_wpending(), and BIO_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() and BIO_ctrl_wpending() return a size_t type and are functions. 🧚
  • BIO_set_info_callback() β€” installs the function pointer cb as an info callback in b by calling BIO_callback_ctrl() with a command of BIO_CTRL_SET_CALLBACK. Among the BIO types built into the library, only BIO_s_connect(3) and BIO_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 *cbp if any was installed using BIO_set_info_callback() or BIO_callback_ctrl(). If the type of b supports setting an info callback but none was installed, it stores a NULL pointer 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:


πŸŽ€ 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:


πŸ¦‹ the cmd constants with no macro attached πŸ¦‹

Some cmd constants are not associated with any macros. They are documented in the following manual pages:


πŸ’€ 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() and BIO_set_info_callback() β€” return 1 on success, 0 if b is NULL or to indicate failure of a valid cmd, or -2 if the cmd is not supported by b. πŸ’…
  • BIO_ptr_ctrl() β€” returns NULL if the BIO_ctrl() call returns a negative value or does not change *parg, or the pointer it puts into *parg otherwise. πŸŽ€
  • BIO_int_ctrl() β€” returns the return value of BIO_ctrl(). ✨
  • 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. 🌸
  • BIO_seek() and BIO_tell() β€” both return the current file position on success and -1 for failure, except file BIOs which for BIO_seek() always return 0 for success and -1 for failure. πŸ¦‹
  • BIO_flush() β€” returns 1 for success and 0 or -1 for failure. πŸ”₯
  • BIO_eof() β€” returns 1 if EOF has been reached or 0 otherwise. πŸ‘‘
  • BIO_set_close() β€” always returns 1. πŸ’–
  • BIO_get_close() β€” returns the close flag value BIO_CLOSE or BIO_NOCLOSE. ⭐
  • BIO_pending(), BIO_ctrl_pending(), BIO_wpending(), and BIO_ctrl_wpending() β€” return the amount of pending data. 🧚
  • BIO_get_info_callback() β€” returns 1 on success, including when the type of b supports an info callback but none is installed, 0 if b is NULL or -2 if the type of b does 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(), and BIO_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() and BIO_set_info_callback() first appeared in SSLeay 0.9.0.
  • All these functions have been available since OpenBSD 2.4.
  • BIO_seek() and BIO_tell() first appeared in SSLeay 0.9.1.
  • BIO_ctrl_pending() and BIO_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