SSL_SET_FD(3)

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

πŸ’… SSL_SET_FD β€” bestie, let's hook your SSL object up to a file descriptor

okay so this one's from libssl and libcrypto, and you get to it like this:

#include <openssl/ssl.h>

That's the whole invite to the party, no cap. ✨


🌸 SYNOPSIS 🌸

int
SSL_set_fd(SSL *ssl, int fd);

int
SSL_set_rfd(SSL *ssl, int fd);

int
SSL_set_wfd(SSL *ssl, int fd);

three little functions, all taking an SSL *ssl and an int fd, all handing you back an int. iconic trio fr fr.


πŸ¦‹ DESCRIPTION πŸ¦‹

So SSL_set_fd() sets the file descriptor fd as the input/output facility for the TLS/SSL (encrypted) side of ssl. And fd will typically be the socket file descriptor of a network connection β€” like, that's the main character use case, iykyk. πŸ”₯

When it's doing the operation, a socket BIO is automatically created to interface between the ssl and the fd. bestie it just happens, you don't have to do it yourself πŸ’… And the BIO β€” and therefore the SSL engine β€” inherits the behaviour of fd. So if fd is non-blocking, the ssl will also have non-blocking behaviour. the vibes propagate. no take-backsies.

Also important: if there was already a BIO connected to ssl, then BIO_free(3) will be called β€” for both the reading and writing side, if they're different. so the old one gets politely yeeted 🫢

Then SSL_set_rfd() and SSL_set_wfd() do the respective action, but only for the read channel or the write channel, which can be set independently. so if you only wanna commit on one side of the relationship, that's your moment πŸŽ€


⭐ RETURN VALUES ⭐

These are the possible return values, keep 'em in mind:

  • 0 β€” the operation failed. 😭 Check the error stack to find out why (the error stack is literally the receipts).
  • 1 β€” the operation succeeded. slay! πŸ‘‘

🌈 SEE ALSO 🌈

go read those too, they're all part of the same friend group πŸ’œ


πŸŽ€ HISTORY πŸŽ€

SSL_set_fd() appeared in SSLeay 0.4 or earlier β€” like, ancient. SSL_set_rfd() and SSL_set_wfd() first appeared in SSLeay 0.6.0. And these functions have been available since OpenBSD 2.4. elders of the group chat, honestly πŸ‘‘


ngl this one's short and sweet, so go set some fds and be free πŸ¦‹

okay that's the whole page!! this came from the Debian build, dated June 8, 2025, and you can find it filed under the SSL_SET_FD(3) section of the Library Functions Manual. mwah πŸ’–βœ¨πŸ“

πŸ“¦ where this page comes from