@@ -10429,6 +10429,13 @@ inline void ClientImpl::set_error_logger(ErrorLogger error_logger) {
1042910429#ifdef CPPHTTPLIB_OPENSSL_SUPPORT
1043010430namespace detail {
1043110431
10432+ inline bool is_ip_address (const std::string &host) {
10433+ struct in_addr addr4;
10434+ struct in6_addr addr6;
10435+ return inet_pton (AF_INET , host.c_str (), &addr4) == 1 ||
10436+ inet_pton (AF_INET6 , host.c_str (), &addr6) == 1 ;
10437+ }
10438+
1043210439template <typename U, typename V>
1043310440inline SSL *ssl_new (socket_t sock, SSL_CTX *ctx, std::mutex &ctx_mutex,
1043410441 U SSL_connect_or_accept, V setup) {
@@ -11087,14 +11094,18 @@ inline bool SSLClient::initialize_ssl(Socket &socket, Error &error) {
1108711094 return true ;
1108811095 },
1108911096 [&](SSL *ssl2) {
11097+ // Set SNI only if host is not IP address
11098+ if (!detail::is_ip_address (host_)) {
1109011099#if defined(OPENSSL_IS_BORINGSSL)
11091- SSL_set_tlsext_host_name (ssl2, host_.c_str ());
11100+ SSL_set_tlsext_host_name (ssl2, host_.c_str ());
1109211101#else
11093- // NOTE: Direct call instead of using the OpenSSL macro to suppress
11094- // -Wold-style-cast warning
11095- SSL_ctrl (ssl2, SSL_CTRL_SET_TLSEXT_HOSTNAME , TLSEXT_NAMETYPE_host_name,
11096- static_cast <void *>(const_cast <char *>(host_.c_str ())));
11102+ // NOTE: Direct call instead of using the OpenSSL macro to suppress
11103+ // -Wold-style-cast warning
11104+ SSL_ctrl (ssl2, SSL_CTRL_SET_TLSEXT_HOSTNAME ,
11105+ TLSEXT_NAMETYPE_host_name,
11106+ static_cast <void *>(const_cast <char *>(host_.c_str ())));
1109711107#endif
11108+ }
1109811109 return true ;
1109911110 });
1110011111
0 commit comments