BIO_ADDR(3ossl)
β¨ BIO_ADDR(3ossl) β the whole vibe β¨
okay so this is the BIO_ADDR(3ossl) page from OpenSSL, and honestly bestie, it's a good one. it's all about BIO_ADDR β the little wrapper that holds every kind of socket address OpenSSL fumbles with. pull up a chair, we're gonna go through it π
πΈ SYNOPSIS πΈ
#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 π¦
so BIO_ADDR is basically a glow-up wrapper around all the socket address types OpenSSL deals with. right now it's transparently serving AF_INET, AF_INET6 and AF_UNIX, depending on what your platform actually has available. no cap, it just adapts π
here's the whole friend group, one by one:
BIO_ADDR_new()β makes a brand-new, unfilledBIO_ADDR, ready to be handed to routines that fill it with info, likeBIO_accept_ex().BIO_ADDR_copy()β copies the contents ofsrcintodst. and listen: neithersrcnordstcan beNULL, periodt.BIO_ADDR_dup()β creates a freshBIO_ADDRwith a copy of the address data inap.BIO_ADDR_free()β frees aBIO_ADDRthat came fromBIO_ADDR_new()orBIO_ADDR_dup(). if you passNULL? nothing happens. very chill of it.BIO_ADDR_clear()β wipes any data inside the givenBIO_ADDRand sets it back to an uninitialised state. clean slate energy β¨BIO_ADDR_rawmake()β takes a protocol family, a byte array of sizewherelenwith an address in network byte order pointed at bywhere, and a port number in network byte order inport, then populates the givenBIO_ADDRwith all of that. β οΈ tiny exception: for theAF_UNIXprotocol family,portis meaningless and therefore ignored. and if this creates anAF_UNIXBIO_ADDR,wherelenis expected to be the length of the path string β not including the terminating NUL, like whatstrlen()gives you. more on all that under "RAW ADDRESSES" below πBIO_ADDR_family()β returns the protocol family of the givenBIO_ADDR. the possible non-error results are one of the constantsAF_INET,AF_INET6andAF_UNIX. it'll also hand youAF_UNSPECif theBIO_ADDRhasn't been initialised yet (it's giving "idk yet").BIO_ADDR_rawaddress()β writes the raw address of the givenBIO_ADDRinto the area pointed at bypifpis non-NULL, and sets*lto be the amount of bytes the raw address takes up iflis non-NULL. pro tip from the manpage itself: if you only wanna find out the size of the address, call it withpset toNULL. the raw address will be in network byte order, most significant byte first. and if this is anAF_UNIXBIO_ADDR,lgets the length of the path string (again, not including the terminating NUL, likestrlen()returns). "RAW ADDRESSES" section, we love you πBIO_ADDR_rawport()β returns the raw port of the givenBIO_ADDR. the raw port is in network byte order.BIO_ADDR_hostname_string()β returns a character string with the hostname of the givenBIO_ADDR. ifnumericis1, the string will contain the numerical form of the address. this only works forBIO_ADDRof the protocol familiesAF_INETandAF_INET6. and the returned string has been allocated on the heap, so you must free it withOPENSSL_free(). don't forget, bestie πBIO_ADDR_service_string()β returns a character string with the service name of the port of the givenBIO_ADDR. ifnumericis1, the string will contain the port number. again, only works forBIO_ADDRof the protocol familiesAF_INETandAF_INET6, and again the returned string is heap-allocated and must be freed withOPENSSL_free().BIO_ADDR_path_string()β returns a character string with the path of the givenBIO_ADDR. this one only works forBIO_ADDRof the protocol familyAF_UNIX. and yes, heap-allocated, yes,OPENSSL_free()it. every single time π«Ά
π§ RAW ADDRESSES π§
okay both BIO_ADDR_rawmake() and BIO_ADDR_rawaddress() take a pointer to a network byte order address of a specific site. internally, those get 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 girlies β BIO_ADDR_hostname_string(), BIO_ADDR_service_string() and BIO_ADDR_path_string() β will return NULL on error, and they leave an error indication on the OpenSSL error stack.
BIO_ADDR_copy() returns 1 on success or 0 on error.
all the other functions described here return 0 or NULL when the information they should return isn't available. that's it, that's the whole rule π
π SEE ALSO π
π HISTORY π
BIO_ADDR_copy() and BIO_ADDR_dup() were added in OpenSSL 3.2. newer additions to the friend group, and we're obsessed π
π COPYRIGHT π
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>.
alright bestie, that's the whole page π this was OpenSSL 3.5.0, dated 2026-09-25, signed off with love and a little sparkle β¨ mwah π«Άπ
π¦ where this page comes from
- opensuse-leap 16.0: openssl-3-doc 3.5.0-160000.11.1 Β· Apache-2.0
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms