---
name: "libressl-SSL_CTX_set_tlsext_servername_callback"
section: "3"
platform: "linux"
package: "libressl"
version: "4.4.0-1"
release: "Arch Linux 2026-11-01"
platforms: ["linux"]
url: "https://new.carta.tech/libressl-SSL_CTX_set_tlsext_servername_callback"
---

# libressl-SSL\_CTX\_set\_tlsext\_servername\_callback(3)

handle server name indication (SNI)

## NAME

**SSL\_CTX\_set\_tlsext\_servername\_callback**, **SSL\_CTX\_set\_tlsext\_servername\_arg**, **SSL\_get\_servername\_type**, **SSL\_get\_servername**, **SSL\_set\_tlsext\_host\_name** – handle server name indication (SNI)

## SYNOPSIS

SSL Library (libssl, -lssl) libcrypto

**#include \<openssl/ssl.h\>**

*long*\

**SSL\_CTX\_set\_tlsext\_servername\_callback**(*SSL\_CTX \*ctx*, *int (\*cb)(SSL \*ssl, int \*alert, void \*arg)*);

*long*\

**SSL\_CTX\_set\_tlsext\_servername\_arg**(*SSL\_CTX \*ctx*, *void \*arg*);

*const* *char* *\**\

**SSL\_get\_servername**(*const SSL \*ssl*, *const int type*);

*int*\

**SSL\_get\_servername\_type**(*const SSL \*ssl*);

*int*\

**SSL\_set\_tlsext\_host\_name**(*SSL \*ssl*, *const char \*name*);

## DESCRIPTION

**SSL\_CTX\_set\_tlsext\_servername\_callback**() sets the application callback *cb* used by a server to perform any actions or configuration required based on the servername extension received in the incoming connection. Like the ALPN callback, it is executed during Client Hello processing. When *cb* is NULL, SNI is not used.

The servername callback should return one of the following values:

- SSL\_TLSEXT\_ERR\_OK

  This is used to indicate that the servername requested by the client has been accepted. Typically a server will call SSL\_set\_SSL\_CTX(3) in the callback to set up a different configuration for the selected servername in this case.

- SSL\_TLSEXT\_ERR\_ALERT\_FATAL

  In this case the servername requested by the client is not accepted and the handshake will be aborted. The value of the alert to be used should be stored in the location pointed to by the *alert* parameter to the callback. By default this value is initialised to SSL\_AD\_UNRECOGNIZED\_NAME.

- SSL\_TLSEXT\_ERR\_ALERT\_WARNING

  If this value is returned, then the servername is not accepted by the server. However, the handshake will continue and send a warning alert instead. The value of the alert should be stored in the location pointed to by the *alert* parameter as for SSL\_TLSEXT\_ERR\_ALERT\_FATAL above. Note that TLSv1.3 does not support warning alerts, so if TLSv1.3 has been negotiated then this return value is treated the same way as SSL\_TLSEXT\_ERR\_NOACK.

- SSL\_TLSEXT\_ERR\_NOACK

  This return value indicates that the servername is not accepted by the server. No alerts are sent and the server will not acknowledge the requested servername.

**SSL\_CTX\_set\_tlsext\_servername\_arg**() sets a context-specific argument to be passed into the callback via the *arg* parameter for *ctx*.

**SSL\_set\_tlsext\_host\_name**() sets the server name indication ClientHello extension to contain the value *name*, or clears it if *name* is NULL. The type of server name indication extension is set to TLSEXT\_NAMETYPE\_host\_name as defined in RFC 3546.

All three functions are implemented as macros.

## RETURN VALUES

**SSL\_CTX\_set\_tlsext\_servername\_callback**() and **SSL\_CTX\_set\_tlsext\_servername\_arg**() always return 1 indicating success.

**SSL\_get\_servername**() returns a servername extension value of the specified type if provided in the Client Hello, or NULL otherwise.

**SSL\_get\_servername\_type**() returns the servername type or -1 if no servername is present. Currently the only supported type (defined in RFC 3546) is TLSEXT\_NAMETYPE\_host\_name.

**SSL\_set\_tlsext\_host\_name**() returns 1 on success or 0 in case of an error.

## SEE ALSO

[ssl(3)](/ssl/3.md), SSL\_CTX\_callback\_ctrl(3), SSL\_CTX\_set\_alpn\_select\_cb(3)

## HISTORY

These functions first appeared in OpenSSL 0.9.8f and have been available since OpenBSD 4.5.
