BIO_CONNECT(3ossl)
π BIO_CONNECT π (that's the 3ossl page from the OpenSSL manual, bestie)
okay so you wanna do raw socket stuff by hand instead of letting some library do the ~magic~ for you? iconic. this is the page for the BIO socket setup squad: BIO_socket, BIO_bind, BIO_connect, BIO_listen, BIO_accept_ex and BIO_closesocket. no cap, they do exactly what they say. let's get into it π«Ά
β¨ 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 protocol. about options? the socket options are currently unused, but it's chillin' there for future use. it's giving placeholder energy π
BIO_bind() binds the source address and service to a socket, and honestly it may be useful before calling BIO_connect(). the options may include BIO_SOCK_REUSEADDR, which is described down 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, obviously π
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 an incoming connection on the given socket accept_sock. when it gets a connection, the address and port of the peer gets stored in peer if that one is non-NULL. accept options may be zero or BIO_SOCK_NONBLOCK, and it is applied on the accepted socket. flags? FLAGS below, bestie.
BIO_closesocket() closes sock. that's it. that's the whole job. and it ate π
π FLAGS π
BIO_SOCK_KEEPALIVEβ enables regular sending of keep-alive messages. your socket is now the friend that texts "you alive??" every so often β¨BIO_SOCK_NONBLOCKβ sets the socket to nonblocking mode. no waiting around, no main character standing in line πBIO_SOCK_NODELAYβ corresponds toTCP_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. send it NOW, not later π₯BIO_SOCK_REUSEADDRβ try to reuse the address and port combination for a recently closed port. recycling era β»οΈBIO_SOCK_V6_ONLYβ when creating an IPv6 socket, make it only listen for IPv6 addresses and not IPv4 addresses mapped to IPv6. v6 only, no crossover episodes please π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 withBIO_connect(),BIO_set_conn_mode(),BIO_set_bind_mode(), andBIO_listen(). on Linux kernels before 4.14, useBIO_set_conn_address()to specify the peer address before starting the TLS handshake. fast open, fast everything, we love to see it π¦
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.
so likeβ¦ always check the return value, babe. and then peek at the OpenSSL error stack and errno, because they're two different receipts for the same mess π
π SEE ALSO π
BIO_ADDR(3) β go read it, iykyk, they're besties
π 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. rip to the old ones but they're different now πͺ¦
π COPYRIGHT π
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>.
and that's the whole page, bestie!! π this was OpenSSL 3.5.9, dated 2026-09-29, and honestly? she served. now go bind a socket and slay β¨π
π¦ where this page comes from
- fedora 43: openssl-devel 1:3.5.9-1.fc43 Β· Apache-2.0
- fedora 43: openssl-devel 1:3.5.9-1.fc43 Β· Apache-2.0
- fedora 44: openssl-devel 1:3.5.9-1.fc44 Β· Apache-2.0
- fedora 44: openssl-devel 1:3.5.9-1.fc44 Β· Apache-2.0
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms