SSL_SESSION_GET0_HOSTNAME(3ossl)
π SSL_SESSION_GET0_HOSTNAME π
okay bestie, so this one is 3ossl β it's an OpenSSL manual page, and it's literally about getting and setting the SNI and ALPN data that's chillin' inside a session. two little blobs of metadata, four functions, one very cute page. let's go β¨
πΈ NAME πΈ
so the whole fam is here: SSL_SESSION_get0_hostname, SSL_SESSION_set1_hostname, SSL_SESSION_get0_alpn_selected, SSL_SESSION_set1_alpn_selected β and what they do is get and set SNI and ALPN data associated with a session. that's it, that's the vibe check π
π¦ SYNOPSIS π¦
okay so first you gotta pull in the header, obviously:
#include <openssl/ssl.h>
then here are your four icons, character for character, no cap:
const char *SSL_SESSION_get0_hostname(const SSL_SESSION *s);
int SSL_SESSION_set1_hostname(SSL_SESSION *s, const char *hostname);
void SSL_SESSION_get0_alpn_selected(const SSL_SESSION *s,
const unsigned char **alpn,
size_t *len);
int SSL_SESSION_set1_alpn_selected(SSL_SESSION *s, const unsigned char *alpn,
size_t len);
notice how the two get0 ones hand you pointers back through the return value or through *alpn/*len, and the two set1 ones take stuff by value and give you a 1 or 0 back. main character energy on both sides ngl π«Ά
β¨ DESCRIPTION β¨
π SSL_SESSION_get0_hostname() β the SNI getter
this one retrieves the Server Name Indication (SNI) value that was sent by the client when the session was created β but only if the server acknowledged the client's SNI extension by including an empty SNI extension in response. otherwise NULL is returned. like, if the server didn't nod back, you get nothing. periodt.
bestie pls note: the value returned is a pointer to memory maintained within s and should not be free'd. it's not yours, you're just borrowing it π
π§ SSL_SESSION_set1_hostname() β the SNI setter
sets the SNI value for the hostname to a copy of the string provided in hostname. so it copies your string, meaning your original is still yours to deal with. copy, not borrow. iconic behavior honestly π
π SSL_SESSION_get0_alpn_selected() β the ALPN getter
retrieves the selected ALPN protocol for this session and its associated length in bytes. the length comes back through len, and the protocol bytes come back through *alpn.
same warning, same energy: the returned value of*alpnis a pointer to memory maintained withinsand should not be free'd. hands off, bestie β
π SSL_SESSION_set1_alpn_selected() β the ALPN setter
sets the ALPN protocol for this session to the value in alpn, which should be of length len bytes. a copy of the input value is made, and the caller retains ownership of the memory pointed to by alpn. so you keep yours, it keeps its copy. everybody wins π«Ά
π RETURN VALUES π
SSL_SESSION_get0_hostname()β returns the SNI string if available, orNULLif not. simple as that πSSL_SESSION_set1_hostname()β returns1on success or0on error. classic.SSL_SESSION_set1_alpn_selected()β returns1on success or0on error. same energy, no surprises.
ok and like, lowkey the elephant in the room:SSL_SESSION_get0_alpn_selected()isvoidup there in the synopsis, so it's not in this list. it hands you stuff through the out-params, that's its whole thing. no return value to check π₯
π₯ SEE ALSO π₯
go read these next, i'm obsessed with them for you:
π HISTORY π
not me checking the receipts: the SSL_SESSION_set1_hostname(), SSL_SESSION_get0_alpn_selected() and SSL_SESSION_set1_alpn_selected() functions were added in OpenSSL 1.1.1. the glow-up is documented π
π COPYRIGHT π
Copyright 2016-2025 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>.
fr fr read the license before you go copying things, it's giving "respect the icon" π
and that's the whole page bestie, hope SNI and ALPN are now your besties too πΈπ¦π
okay bye, this was OpenSSL 3.5.6, dated 2026-04-07 β SSL_SESSION_GET0_HOSTNAME(3ossl), signing off π«Άβ¨
π¦ 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