BIO_CONNECT(3ossl)

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

πŸ’– NAME πŸ’–

Okay bestie, welcome to BIO_CONNECT(3ossl) β€” the OpenSSL page for the BIO socket communication setup routines. We're talking BIO_socket, BIO_bind, BIO_connect, BIO_listen, BIO_accept_ex, and BIO_closesocket. Socket era, but make it make sense. πŸ’…βœ¨


✨ SYNOPSIS ✨

#include <openssl/bio.h>

int BIO_socket(int domain, int socktype, int protocol, int options);
int BIO_bind(int sock, const BIO_ADDR *addr, int options);
int BIO_connect(int sock, const BIO_ADDR *addr, int options);
int BIO_listen(int sock, const BIO_ADDR *addr, int options);
int BIO_accept_ex(int accept_sock, BIO_ADDR *peer, int options);
int BIO_closesocket(int sock);

πŸ¦‹ DESCRIPTION πŸ¦‹

  • BIO_socket() β€” creates a socket in the domain domain, of type socktype, and with protocol. The options argument is currently unused, but it's present for future use, bestie. No cap. 🫢
  • BIO_bind() β€” binds the source address and service to a socket, and it may be useful before calling BIO_connect(). The options may include BIO_SOCK_REUSEADDR, which is described in "FLAGS" below.
  • BIO_connect() β€” connects sock to the address and service given by addr. Connection options may be zero or any combination of BIO_SOCK_KEEPALIVE, BIO_SOCK_NONBLOCK, and BIO_SOCK_NODELAY. The flags are described in "FLAGS" below.
  • BIO_listen() β€” has sock start listening on the address and service given by addr. Connection options may be zero or any combination of BIO_SOCK_KEEPALIVE, BIO_SOCK_NONBLOCK, BIO_SOCK_NODELAY, BIO_SOCK_REUSEADDR, and BIO_SOCK_V6_ONLY. The flags are described in "FLAGS" below.
  • BIO_accept_ex() β€” waits for incoming connections on the given socket accept_sock. When it gets a connection, the address and port of the peer get stored in peer if that one is non-NULL. Accept options may be zero or BIO_SOCK_NONBLOCK, and it's applied on the accepted socket. The flags are described in "FLAGS" below.
  • BIO_closesocket() β€” closes sock. That's it. That's the whole job. πŸ’€

πŸŽ€ FLAGS πŸŽ€

Here's the flag lineup, and yes, they're all iconic in their own way:

  • BIO_SOCK_KEEPALIVE β€” enables regular sending of keep-alive messages. Keeping the vibe alive, literally. πŸ’–
  • BIO_SOCK_NONBLOCK β€” sets the socket to nonblocking mode.
  • BIO_SOCK_NODELAY β€” corresponds to TCP_NODELAY, and disables the Nagle algorithm. With this set, any data will be sent as soon as possible instead of being buffered until there's enough for the socket to send out in one go.
  • BIO_SOCK_REUSEADDR β€” try to reuse the address and port combination for a recently closed port.
  • BIO_SOCK_V6_ONLY β€” when creating an IPv6 socket, make it only listen for IPv6 addresses and not IPv4 addresses mapped to IPv6.
  • BIO_SOCK_TFO β€” enables TCP Fast Open on the socket. Uses appropriate APIs on supported operating systems, including Linux, macOS, and FreeBSD. Can be used with BIO_connect(), BIO_set_conn_mode(), BIO_set_bind_mode(), and BIO_listen(). On Linux kernels before 4.14, use BIO_set_conn_address() to specify the peer address before starting the TLS handshake.

These flags are bit flags, so they are to be combined with the "|" operator, for example:

BIO_connect(sock, addr, BIO_SOCK_KEEPALIVE | BIO_SOCK_NONBLOCK);

🌸 RETURN VALUES 🌸

  • BIO_socket() returns the socket number on success or INVALID_SOCKET (-1) on error. When an error has occurred, the OpenSSL error stack will hold the error data and errno has the system error.
  • BIO_bind(), BIO_connect(), and BIO_listen() return 1 on success or 0 on error. When an error has occurred, the OpenSSL error stack will hold the error data and errno has the system error.
  • BIO_accept_ex() returns the accepted socket on success or INVALID_SOCKET (-1) on error. When an error has occurred, the OpenSSL error stack will hold the error data and errno has the system error.

🫢 SEE ALSO 🫢

πŸ’… HISTORY πŸ’…

BIO_gethostname(), BIO_get_port(), BIO_get_host_ip(), BIO_get_accept_socket(), and BIO_accept() were deprecated in OpenSSL 1.1.0. Use the functions described above instead. We love an upgrade, bestie. ✨

Copyright 2016-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>.


This page is from OpenSSL 3.5.6, dated 2026-04-07. Bye bestie, go make those sockets behave! πŸŽ€πŸ’–

πŸ“¦ where this page comes from