Skip to content

Commit 21bc438

Browse files
author
Peter Thorson
committed
Merge branch 'develop' of github.com:zaphoyd/websocketpp into develop
2 parents 914cb7c + 46260bb commit 21bc438

File tree

1 file changed

+10
-5
lines changed
  • websocketpp/transport/asio/security

1 file changed

+10
-5
lines changed

websocketpp/transport/asio/security/tls.hpp

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -230,16 +230,21 @@ class connection : public lib::enable_shared_from_this<connection> {
230230
void pre_init(init_handler callback) {
231231
// TODO: is this the best way to check whether this function is
232232
// available in the version of OpenSSL being used?
233-
// TODO: consider case where host is an IP address
234233
#if OPENSSL_VERSION_NUMBER >= 0x90812f
235234
if (!m_is_server) {
236235
// For clients on systems with a suitable OpenSSL version, set the
237236
// TLS SNI hostname header so connecting to TLS servers using SNI
238237
// will work.
239-
long res = SSL_set_tlsext_host_name(
240-
get_socket().native_handle(), m_uri->get_host().c_str());
241-
if (!(1 == res)) {
242-
callback(socket::make_error_code(socket::error::tls_failed_sni_hostname));
238+
auto host = m_uri->get_host();
239+
lib::asio::error_code ec_addr;
240+
boost::asio::ip::address addr = boost::asio::ip::make_address(host, ec_addr);
241+
if (ec_addr) {
242+
// The SNI applies only to DNS host names, not for IP addresses
243+
long res = SSL_set_tlsext_host_name(
244+
get_socket().native_handle(), host.c_str());
245+
if (!(1 == res)) {
246+
callback(socket::make_error_code(socket::error::tls_failed_sni_hostname));
247+
}
243248
}
244249
}
245250
#endif

0 commit comments

Comments
 (0)