doc/designs/ddd/ddd-01-conn-blocking.c
/*
 * The application wants to create a new outgoing connection using a given
 * SSL_CTX.
 *
 * hostname is a string like "openssl.org:443" or "[::1]:443".
 */
The application wants to create a new outgoing connection using a given
SSL_CTX.


The application wants to create a new outgoing connection using a given SSL_CTX .
BIO *new_conn(SSL_CTX *ctx, const char *hostname)
{
    BIO *out;
    SSL *ssl = NULL;
    const char *bare_hostname;
    out = BIO_new_ssl_connect(ctx);
    if (out == NULL)
        return NULL;
    if (BIO_get_ssl(out, &ssl) == 0) {
        BIO_free_all(out);
        return NULL;
    }
    if (BIO_set_conn_hostname(out, hostname) == 0) {
        BIO_free_all(out);
        return NULL;
    }
    bare_hostname = BIO_get_conn_hostname(out);
    if (bare_hostname == NULL) {
        BIO_free_all(out);
        return NULL;
    }
    if (SSL_set1_host(ssl, bare_hostname) <= 0) {
        BIO_free_all(out);
        return NULL;
    }
    return out;
}
BIO * new_conn ( SSL_CTX * ctx , const char * hostname ) { BIO * out ; SSL * ssl = NULL ; const char * bare_hostname ; out = BIO_new_ssl_connect ( ctx ) ; if ( out == NULL ) return NULL ; if ( BIO_get_ssl ( out , & ssl ) == 0 ) { BIO_free_all ( out ) ; return NULL ; } if ( BIO_set_conn_hostname ( out , hostname ) == 0 ) { BIO_free_all ( out ) ; return NULL ; } bare_hostname = BIO_get_conn_hostname ( out ) ; if ( bare_hostname == NULL ) { BIO_free_all ( out ) ; return NULL ; } if ( SSL_set1_host ( ssl , bare_hostname ) <= 0 ) { BIO_free_all ( out ) ; return NULL ; } return out ; }
The application wants to create a new outgoing connection using a given
 SSL_CTX.
The application wants to create a new outgoing connection using a given SSL_CTX .
/* Returns the parsed hostname extracted from the hostname:port string. */ /* Tell the SSL object the hostname to check certificates against. */