BIO_PARSE_HOSTSERV(3ossl)

πŸ’– BIO_PARSE_HOSTSERV πŸ’–

okay bestie, so this is the BIO_PARSE_HOSTSERV(3ossl) page from the OpenSSL manual, and it's literally just two little utility routines that parse a standard host-and-service string. no cap, it's short and it's useful and we're gonna get through it together 🫢


✨ NAME ✨

BIO_hostserv_priorities, BIO_parse_hostserv β€” utility routines to parse a standard host and service string. that's it, that's the whole job πŸ’…


🌸 SYNOPSIS 🌸

here's the vibe, verbatim:

#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);

so we got an enum with two moods β€” BIO_PARSE_PRIO_HOST and BIO_PARSE_PRIO_SERV β€” and one function that takes four things. slay.


πŸ¦‹ DESCRIPTION πŸ¦‹

BIO_parse_hostserv() takes whatever you handed it in hostserv, parses it, builds you some fresh strings holding the hostname and the service name, and gives those back to you through host and service.

⚠️ heads up bestie: those strings need to be freed after they are used. not optional. free your memory, it's self care πŸ’–

and what's hostserv_prio for? it helps determine whether hostserv shall be interpreted primarily as a hostname or as a service name in the ambiguous cases. it's the tiebreaker, the main character deciding who wins 🌈

πŸŽ€ the syntax it recognises

BIO_parse_hostserv() recognises exactly this:

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

the host part can be a name or an IP address. and if it's a IPv6 address, it MUST be enclosed in brackets, such as '[::1]'. like, MUST must. brackets or nothing, babe 🧚

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(). the system does the translating, we just vibe ✨

🌟 what you actually get back

the returned values will depend on the given hostserv string and hostserv_prio, as follows:

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"

so '*' means "no service for you", and a lone ':' before the service means "no host, just service". the NULLs are doing a lot of heavy lifting here, ngl πŸ’€

in case no ':' is present in the string, the result depends on hostserv_prio, as follows:

when hostserv_prio == BIO_PARSE_PRIO_HOST

host                 => *host = "host", *service untouched

when hostserv_prio == BIO_PARSE_PRIO_SERV

service              => *host untouched, *service = "service"

see? ambiguous input, the prio decides. it's giving "you pick, I trust you" πŸ˜­πŸ‘‘


πŸ”₯ RETURN VALUES πŸ”₯

BIO_parse_hostserv() returns 1 on success or 0 on error. that's the whole story. one or zero. iconic simplicity, periodt ⭐


πŸ‘‘ SEE ALSO πŸ‘‘

BIO_ADDRINFO(3) β€” go read that one next, bestie, it's the sequel πŸ¦‹


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 🌸 this was the 3.5.9 version of the OpenSSL manual, dated 2026-09-29, and it's called BIO_PARSE_HOSTSERV(3ossl). mwah, take care of your strings and free them when you're done πŸ’–πŸŽ€πŸ«Ά

πŸ“¦ where this page comes from