SSL_SESSION_GET0_HOSTNAME(3ossl)

πŸ“¦
version 15.1 Β· 3 versions
, in freebsd 15.1

πŸ’… 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 *alpn is a pointer to memory maintained within s and 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, or NULL if not. simple as that πŸ’
  • SSL_SESSION_set1_hostname() β€” returns 1 on success or 0 on error. classic.
  • SSL_SESSION_set1_alpn_selected() β€” returns 1 on success or 0 on error. same energy, no surprises.
ok and like, lowkey the elephant in the room: SSL_SESSION_get0_alpn_selected() is void up 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 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