--- a/ptstream.c
+++ b/ptstream.c
@@ -161,13 +161,24 @@
 #ifdef USE_SSL
 	SSL *ssl;
 	SSL_CTX *ctx;
-	
+	int ret;
+
 	/* Initialise the connection */
 	SSLeay_add_ssl_algorithms();
 	SSL_load_error_strings();
 
 	ctx = SSL_CTX_new (SSLv3_client_method());
 	ssl = SSL_new (ctx);
+
+	if (args_info.verbose_flag) {
+		message("Set SNI hostname to %s\n", args_info.proxyhost_arg);
+	}
+	ret = SSL_set_tlsext_host_name(ssl, args_info.proxyhost_arg);
+	if (!ret) {
+		message("TLS SNI error, giving up: SSL_set_tlsext_host_name failed\n");
+		exit(1);
+	}
+
 	SSL_set_rfd (ssl, stream_get_incoming_fd(pts));
 	SSL_set_wfd (ssl, stream_get_outgoing_fd(pts));	
 	SSL_connect (ssl);
