BIO_ADDR(3ossl)
π BIO_ADDR β the whole OpenSSL address-wrapper situation (it's from the OpenSSL manual, bestie)
Okay so this is the BIO_ADDR family of routines from OpenSSL, and honestly? It's giving "one union to hold every socket address you'll ever meet" and I'm obsessed. Sit down, grab a strawberry π, we're doing this.
β¨ NAME β¨
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 β all the BIO_ADDR routines, together, as a treat π
πΈ 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 a wrapper around, like, 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 at hand. Versatile queen π
BIO_ADDR_new()β makes you a brand new, unfilledBIO_ADDR, ready to be used with routines that will fill it with info, likeBIO_accept_ex(). It's a blank canvas, main character energy.BIO_ADDR_copy()β copies the contents ofsrcintodst. Neithersrcnordstcan beNULL. No cap, they literally cannot.BIO_ADDR_dup()β creates a newBIO_ADDR, with a copy of the address data inap. Clone slay π«BIO_ADDR_free()β frees aBIO_ADDRthat was created withBIO_ADDR_new()orBIO_ADDR_dup(). If the argument isNULL, nothing is done. She's unbothered, she simply does not react.BIO_ADDR_clear()β clears any data held inside the providedBIO_ADDRand sets it back to an uninitialised state. Factory reset vibes.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(except for theAF_UNIXprotocol family, whereportis meaningless and therefore ignored π) and populates the givenBIO_ADDRwith them. In case this creates anAF_UNIXBIO_ADDR,wherelenis expected to be the length of the path string β not including the terminatingNUL, like the result of a call tostrlen(), iykyk. Read on about the addresses in "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 will also returnAF_UNSPECif theBIO_ADDRhas not been initialised. She'll tell you who she is, or she'll tell you she doesn't know 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. A technique to only find out the size of the address is a call withpset toNULL. The raw address will be in network byte order, most significant byte first. In case this is anAF_UNIXBIO_ADDR,lgets the length of the path string β again, not including the terminatingNUL, like the result of a call tostrlen(). Read on in "RAW ADDRESSES" below, bestie βBIO_ADDR_rawport()β returns the raw port of the givenBIO_ADDR. The raw port will be in network byte order. Byte order matters, don't play with her πBIO_ADDR_hostname_string()β returns a character string with the hostname of the givenBIO_ADDR. Ifnumericis 1, the string will contain the numerical form of the address. This only works forBIO_ADDRof the protocol familiesAF_INETandAF_INET6. The returned string has been allocated on the heap and must be freed withOPENSSL_free(). Heap-allocated means you free it. Not optional. Periodt.BIO_ADDR_service_string()β returns a character string with the service name of the port of the givenBIO_ADDR. Ifnumericis 1, the string will contain the port number. This only works forBIO_ADDRof the protocol familiesAF_INETandAF_INET6. The returned string has been allocated on the heap and must be freed withOPENSSL_free(). Same deal, same energy π«ΆBIO_ADDR_path_string()β returns a character string with the path of the givenBIO_ADDR. This only works forBIO_ADDRof the protocol familyAF_UNIX. The returned string has been allocated on the heap and must be freed withOPENSSL_free(). Yes, again. Free your strings, girlies π§
π 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. So like, the same pointer slot wears three different outfits depending on the family. Fashion icon behaviour π
π₯ RETURN VALUES π₯
- The string producing functions
BIO_ADDR_hostname_string(),BIO_ADDR_service_string()andBIO_ADDR_path_string()will returnNULLon error and leave an error indication on the OpenSSL error stack. So if you getNULL, check the stack, it left receipts. BIO_ADDR_copy()returns 1 on success or 0 on error.- All other functions described here return 0 or
NULLwhen the information they should return isn't available. Not a whole crisis, just the info not being there π«
π SEE ALSO π
BIO_connect(3), BIO_s_connect(3)
β HISTORY β
BIO_ADDR_copy() and BIO_ADDR_dup() were added in OpenSSL 3.2. Newer girls on the block, we love them π
πΈ 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>.
Okay that's the whole page, bestie, you ate that πβ¨ And for the sign-off: this lil beauty is from version 3.5.6, dated 2026-04-07, and it lives under the name BIO_ADDR(3ossl) in the OpenSSL fam. Go forth and wrap those socket addresses ππ
π¦ where this page comes from
- freebsd 15.1: base 15.1
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms