BIO_PARSE_HOSTSERV(3ossl)

πŸ“¦ version 3.5.0, in opensuse-leap 16.0

πŸŽ€ BIO_PARSE_HOSTSERV πŸŽ€

okay bestie, so this one is from the OpenSSL manual, section 3ossl β€” yes the whole BIO_PARSE_HOSTSERV(3ossl) situation β€” and it's genuinely the comfiest little utility page. it's giving "small but mighty" fr fr πŸ’…

✨ NAME ✨

BIO_hostserv_priorities, BIO_parse_hostserv β€” utility routines to parse a standard host and service string πŸ¦‹

🌸 SYNOPSIS 🌸

#include <openssl/bio.h>

enum BIO_hostserv_priorities {
    BIO_PARSE_PRIO_HOST, BIO_PARSE_PRIO_SERV
};
int BIO_parse_hostserv(const char *hostserv, char **host, char **service,
                       enum BIO_hostserv_priorities hostserv_prio);

πŸ’– DESCRIPTION πŸ’–

so BIO_parse_hostserv() takes whatever string you hand it in hostserv, parses the info out of it, builds fresh strings holding the hostname and the service name, and hands them back to you through host and service. and bestie, those strings are yours now β€” you have to free them once you're done with them, no cap πŸ™ˆ

hostserv_prio is the tiebreaker: it tells the function whether an ambiguous hostserv should be read primarily as a hostname or as a service name. main character energy for a single enum, honestly πŸ‘‘

here's the syntax that BIO_parse_hostserv() recognises 🫢

host + ':' + service
host + ':' + '*'
host + ':'
       ':' + service
'*'  + ':' + service
host
service

the host part can be a name or an IP address. if it's an IPv6 address, it MUST be enclosed in brackets, like '[::1]' β€” like, that's not a suggestion, that's the law πŸ’€

the service part can be a service name or its port number. a service name gets mapped to a port number using the system function getservbyname(). slay, the system does the lookup for you ✨

so what you actually get back depends on the hostserv string and hostserv_prio, like this:

host + ':' + service  => *host = "host", *service = "service"
host + ':' + '*'      => *host = "host", *service = NULL
host + ':'            => *host = "host", *service = NULL
       ':' + service  => *host = NULL, *service = "service"
 '*' + ':' + service  => *host = NULL, *service = "service"

and in case there's no ':' anywhere in the string, the result depends on hostserv_prio, like so:

when hostserv_prio == BIO_PARSE_PRIO_HOST
host                 => *host = "host", *service untouched

when hostserv_prio == BIO_PARSE_PRIO_SERV
service              => *host untouched, *service = "service"

untouched literally means untouched, btw β€” it doesn't get written to at all, so don't be out here expecting a fresh NULL in there πŸ™ˆ

⭐ RETURN VALUES ⭐

BIO_parse_hostserv() returns 1 on success or 0 on error. cute and binary, we love a simple vibe check πŸŽ€

πŸ¦‹ SEE ALSO πŸ¦‹

BIO_ADDRINFO(3) β€” go read that one next, bestie, iykyk πŸ’œ

Copyright 2016-2021 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, no crumbs left 🌈 mwah πŸ’‹ β€” this was version 3.5.0, dated 2026-09-25, straight from the BIO_PARSE_HOSTSERV(3ossl) manual, and yes she ate πŸ“πŸ§š

πŸ“¦ where this page comes from