BIO_ADDR(3SSL)

πŸ’– BIO_ADDR β€” the OpenSSL socket-address glow-up πŸ’–

okay bestie, listen. This is BIO_ADDR, a page from the OpenSSL manual set (section 3SSL), and it's literally the whole squad:

BIO_ADDR, BIO_ADDR_new, BIO_ADDR_copy, BIO_ADDR_dup, BIO_ADDR_clear, BIO_ADDR_free, BIO_ADDR_rawmake, BIO_ADDR_family, BIO_ADDR_rawaddress, BIO_ADDR_rawport, BIO_ADDR_hostname_string, BIO_ADDR_service_string, BIO_ADDR_path_string β€” the BIO_ADDR routines, periodt. πŸŽ€


✨ SYNOPSIS ✨

here's the fit, verbatim, don't touch it:

#include <sys/types.h>
#include <openssl/bio.h>

typedef union bio_addr_st BIO_ADDR;

BIO_ADDR *BIO_ADDR_new(void);
int BIO_ADDR_copy(BIO_ADDR *dst, const BIO_ADDR *src);
BIO_ADDR *BIO_ADDR_dup(const BIO_ADDR *ap);
void BIO_ADDR_free(BIO_ADDR *ap);
void BIO_ADDR_clear(BIO_ADDR *ap);
int BIO_ADDR_rawmake(BIO_ADDR *ap, int family,
                     const void *where, size_t wherelen, unsigned short port);
int BIO_ADDR_family(const BIO_ADDR *ap);
int BIO_ADDR_rawaddress(const BIO_ADDR *ap, void *p, size_t *l);
unsigned short BIO_ADDR_rawport(const BIO_ADDR *ap);
char *BIO_ADDR_hostname_string(const BIO_ADDR *ap, int numeric);
char *BIO_ADDR_service_string(const BIO_ADDR *ap, int numeric);
char *BIO_ADDR_path_string(const BIO_ADDR *ap);

🌸 DESCRIPTION 🌸

The BIO_ADDR type is a little wrapper 🫢 around all the types of socket addresses OpenSSL deals with. Right now it transparently supports AF_INET, AF_INET6 and AF_UNIX β€” depending on what's actually available on the platform you're on, iykyk.

  • BIO_ADDR_new() β€” creates a brand new, unfilled BIO_ADDR, ready to be used with routines that will fill it with information, like BIO_accept_ex(). it's giving empty cup waiting for boba πŸ§‹
  • BIO_ADDR_copy() β€” copies the contents of src into dst. Neither src nor dst can be NULL. no cap, both have to exist.
  • BIO_ADDR_dup() β€” creates a whole new BIO_ADDR with a copy of the address data in ap. twin, but make it functional πŸ’…
  • BIO_ADDR_free() β€” frees a BIO_ADDR that was created with BIO_ADDR_new() or BIO_ADDR_dup(). If the argument is NULL, nothing happens. she's chill like that.
  • BIO_ADDR_clear() β€” clears any data held inside the BIO_ADDR you hand her, and sets it back to an uninitialised state. factory reset energy ✨
  • BIO_ADDR_rawmake() β€” takes a protocol family, a byte array of size wherelen with an address in network byte order pointed at by where, and a port number in network byte order in port β€” then populates the given BIO_ADDR with them. Important caveat tho: for the AF_UNIX protocol family, port is meaningless and therefore ignored πŸ™ˆ. And if this creates an AF_UNIX BIO_ADDR, wherelen is expected to be the length of the path string (not including the terminating NUL, like the result of a call to strlen()). Read on about the addresses in "RAW ADDRESSES" below πŸ‘‡
  • BIO_ADDR_family() β€” returns the protocol family of the given BIO_ADDR. The possible non-error results are one of the constants AF_INET, AF_INET6 and AF_UNIX. She will also return AF_UNSPEC if the BIO_ADDR has not been initialised. so if you get AF_UNSPEC, she's telling you she hasn't been set up yet, bestie 😭
  • BIO_ADDR_rawaddress() β€” writes the raw address of the given BIO_ADDR into the area pointed at by p if p is non-NULL, and sets *l to be the amount of bytes the raw address takes up if l is non-NULL. Here's the lil hack ✨: a technique to only find out the size of the address is to call with p set to NULL. The raw address will be in network byte order, most significant byte first. And if this is an AF_UNIX BIO_ADDR, l gets the length of the path string (not including the terminating NUL, such as the result of a call to strlen()). Read on about the addresses in "RAW ADDRESSES" below πŸ‘‡
  • BIO_ADDR_rawport() β€” returns the raw port of the given BIO_ADDR. The raw port will be in network byte order. πŸ”₯
  • BIO_ADDR_hostname_string() β€” returns a character string with the hostname of the given BIO_ADDR. If numeric is 1, the string will contain the numerical form of the address. This only works for BIO_ADDR of the protocol families AF_INET and AF_INET6. The returned string has been allocated on the heap and must be freed with OPENSSL_free(). don't forget to free her or she will haunt you πŸ‘‘πŸ’€
  • BIO_ADDR_service_string() β€” returns a character string with the service name of the port of the given BIO_ADDR. If numeric is 1, the string will contain the port number. This only works for BIO_ADDR of the protocol families AF_INET and AF_INET6. The returned string has been allocated on the heap and must be freed with OPENSSL_free(). same deal, free her 🫢
  • BIO_ADDR_path_string() β€” returns a character string with the path of the given BIO_ADDR. This only works for BIO_ADDR of the protocol family AF_UNIX. The returned string has been allocated on the heap and must be freed with OPENSSL_free(). yes. free. her. 🌈

πŸ¦‹ RAW ADDRESSES πŸ¦‹

Both BIO_ADDR_rawmake() and BIO_ADDR_rawaddress() take a pointer to a network byte order address of a specific site. Internally, those are treated as a pointer to struct in_addr (for AF_INET), struct in6_addr (for AF_INET6) or char * (for AF_UNIX) β€” all depending on the protocol family the address is for. it's giving shapeshifter πŸ’«


⭐ RETURN VALUES ⭐

  • The string producing functions BIO_ADDR_hostname_string(), BIO_ADDR_service_string() and BIO_ADDR_path_string() will return NULL on error, and leave an error indication on the OpenSSL error stack. stack said "noted." πŸ“
  • BIO_ADDR_copy() returns 1 on success or 0 on error.
  • All other functions described here return 0 or NULL when the information they should return isn't available. no info, no vibes, empty hands πŸ€·β€β™€οΈ

πŸ‘‘ SEE ALSO πŸ‘‘

BIO_connect(3), BIO_s_connect(3)


πŸ’œ HISTORY πŸ’œ

BIO_ADDR_copy() and BIO_ADDR_dup() were added in OpenSSL 3.2. the newer girls on the block, and we love them πŸŽ€


Copyright 2016-2024 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, we ate and left no crumbs πŸ“βœ¨ this was version 4.0.3, dated 2026-09-29, from the BIO_ADDR(3SSL) manual β€” mwah, love u, go free your strings πŸ’…πŸ¦‹πŸ’–

πŸ“¦ where this page comes from