BIO_CTRL(3ossl)

πŸ“¦
version 15.1 Β· 3 versions
, in freebsd 15.1

πŸ’– BIO_CTRL(3ossl) β€” BIO control operations: group-chat edition πŸ’–

okay so bestie, welcome to the OpenSSL manual page BIO_CTRL(3ossl) β€” the one all about poking a BIO with control ops. It’s giving β€œtiny remote control for your I/O stream” energy, and the function list is long, but we’re gonna slay it together. πŸŽ€βœ¨


✨ 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_get_ktls_send, BIO_get_ktls_recv, BIO_set_conn_mode, BIO_get_conn_mode, BIO_set_tfo β€” BIO control operations.


🌸 SYNOPSIS 🌸

#include <openssl/bio.h>

typedef int BIO_info_cb(BIO *b, int state, int res);

long BIO_ctrl(BIO *bp, int cmd, long larg, void *parg);
long BIO_callback_ctrl(BIO *b, int cmd, BIO_info_cb *cb);
void *BIO_ptr_ctrl(BIO *bp, int cmd, long larg);
long BIO_int_ctrl(BIO *bp, 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);

int BIO_get_ktls_send(BIO *b);
int BIO_get_ktls_recv(BIO *b);

int BIO_set_conn_mode(BIO *b, int mode);
int BIO_get_conn_mode(BIO *b);

int BIO_set_tfo(BIO *b, int onoff);

πŸ¦‹ DESCRIPTION πŸ¦‹

okay so here’s the vibe check on each little control-ish thing:

  • BIO_ctrl(), BIO_callback_ctrl(), BIO_ptr_ctrl(), BIO_int_ctrl() β€” these are the BIO β€œcontrol” operations, and they take arguments of various types. Ngl, you don’t normally call these directly; various macros are used instead. The standard macros are described below, and macros specific to a particular type of BIO are described in the specific BIOs manual page as well as any special features of the standard calls.
  • 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. Rewind era. πŸ’…
  • BIO_seek() β€” resets a file-related BIO’s file position pointer (that is, file descriptor and FILE BIOs) to ofs bytes from the start of the 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’s 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, iykyk.
  • 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(), 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_pending() and BIO_wpending() are macros which call BIO_ctrl().
  • BIO_get_ktls_send() β€” returns 1 if the BIO is using the Kernel TLS data-path for sending. Otherwise, it returns zero. BIO_get_ktls_recv() β€” returns 1 if the BIO is using the Kernel TLS data-path for receiving. Otherwise, it returns zero.
  • BIO_get_conn_mode() β€” returns the BIO connection mode. BIO_set_conn_mode() β€” sets the BIO connection mode.
  • BIO_set_tfo() β€” disables TCP Fast Open when onoff is 0, and enables TCP Fast Open when onoff is nonzero. Setting the value to 1 is equivalent to setting BIO_SOCK_TFO in BIO_set_conn_mode().

πŸŽ€ RETURN VALUES πŸŽ€

  • BIO_reset() β€” normally returns 1 for success and <=0 for failure. File BIOs are an exception: they return 0 for success and -1 for failure. Not me getting special-case energy from a file BIO 😭
  • 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 for failure.
  • BIO_eof() β€” returns 1 if EOF has been reached, 0 if not, or negative values for failure.
  • BIO_set_close() β€” returns 1 on success or <=0 for failure.
  • BIO_get_close() β€” returns the close flag value: BIO_CLOSE or BIO_NOCLOSE. It also returns other negative values if an error occurs.
  • BIO_pending(), BIO_ctrl_pending(), BIO_wpending(), BIO_ctrl_wpending() β€” return the amount of pending data. BIO_pending() and BIO_wpending() return negative value or 0 on error. BIO_ctrl_pending() and BIO_ctrl_wpending() return 0 on error.
  • BIO_get_ktls_send() β€” returns 1 if the BIO is using the Kernel TLS data-path for sending. Otherwise, it returns zero. BIO_get_ktls_recv() β€” returns 1 if the BIO is using the Kernel TLS data-path for receiving. Otherwise, it returns zero.
  • BIO_set_conn_mode() β€” returns 1 for success and 0 for failure.
  • BIO_get_conn_mode() β€” returns the current connection mode. Which may contain the bitwise-or of the following flags:
    • BIO_SOCK_REUSEADDR
    • BIO_SOCK_V6_ONLY
    • BIO_SOCK_KEEPALIVE
    • BIO_SOCK_NONBLOCK
    • BIO_SOCK_NODELAY
    • BIO_SOCK_TFO
  • BIO_set_tfo() β€” returns 1 for success, and 0 for failure.

🌈 NOTES 🌈

BIO_flush(), because it can write data, may return 0 or -1 indicating that the call should be retried later in a similar manner to BIO_write_ex(). The BIO_should_retry() call should be used and appropriate action taken if the call fails. bestie please use the retry check, fr fr 🫢

The return values of BIO_pending() and 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 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.

Filter BIOs, if they do not internally handle a particular BIO_ctrl() operation, 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 BIO_seek(), but this may still succeed if the chain ends in a FILE or file descriptor BIO.

Source/sink BIOs return an 0 if they do not recognize the BIO_ctrl() operation.


πŸ’€ 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 BIO_seek() on a file BIO for a successful operation. so yes, 0 is out here wearing many hats 😭

In older versions of OpenSSL the BIO_ctrl_pending() and BIO_ctrl_wpending() could return values greater than INT_MAX on error.


πŸ‘‘ HISTORY πŸ‘‘

The BIO_get_ktls_send() and BIO_get_ktls_recv() macros were added in OpenSSL 3.0. They were modified to never return -1 in OpenSSL 3.0.4.

The BIO_get_conn_mode(), BIO_set_conn_mode() and BIO_set_tfo() functions were added in OpenSSL 3.2.


Copyright 2000-2022 The OpenSSL Project Authors. All Rights Reserved.

Licensed under the Apache License 2.0 (the β€œLicense”). You may not use this file except in compliance with the License. You can obtain a copy in the file LICENSE in the source distribution or at <https://www.openssl.org/source/license.html>.


okay bestie, that’s the whole BIO_CTRL(3ossl) page. Cute sign-off time: it’s from OpenSSL source/version 3.5.6, dated 2026-04-07, and this page is BIO_CTRL(3ossl). Now go control those BIOs, you main character. πŸ’…βœ¨πŸ¦‹

πŸ“¦ where this page comes from