Skip to content

Commit

Permalink
Merge branch 'bugfix/fix_esp_http_client_host_test_failures' into 'ma…
Browse files Browse the repository at this point in the history
…ster'

esp-tls: Fix esp-tls component to resolve esp_http_client example failure for Linux target.

Closes IDFCI-1646 and IDFCI-1647

See merge request espressif/esp-idf!22584
  • Loading branch information
AdityaHPatwardhan committed Mar 9, 2023
2 parents 4785284 + 866e6b0 commit 38b036e
Showing 1 changed file with 21 additions and 4 deletions.
25 changes: 21 additions & 4 deletions components/esp-tls/esp_tls.c
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
#include <netdb.h>

#include <http_parser.h>
#include "sdkconfig.h"
#include "esp_tls.h"
#include "esp_tls_private.h"
#include "esp_tls_error_capture_internal.h"
Expand All @@ -25,8 +26,16 @@
#include <linux/if.h>
#include <sys/time.h>

#define ipaddr_ntoa(ipaddr) inet_ntoa(*ipaddr)
typedef struct in_addr ip_addr_t;
typedef struct in6_addr ip6_addr_t;
#define ipaddr_ntoa(ipaddr) inet_ntoa(*ipaddr)

static inline char *ip6addr_ntoa(const ip6_addr_t *addr)
{
static char str[40];
return (char *)inet_ntop(AF_INET6, addr->s6_addr, str, 40);
}

#endif

static const char *TAG = "esp-tls";
Expand Down Expand Up @@ -85,6 +94,14 @@ static const char *TAG = "esp-tls";
#error "No TLS stack configured"
#endif

#if CONFIG_IDF_TARGET_LINUX
#define IPV4_ENABLED 1
#define IPV6_ENABLED 1
#else // CONFIG_IDF_TARGET_LINUX
#define IPV4_ENABLED CONFIG_LWIP_IPV4
#define IPV6_ENABLED CONFIG_LWIP_IPV6
#endif // !CONFIG_IDF_TARGET_LINUX

#define ESP_TLS_DEFAULT_CONN_TIMEOUT (10) /*!< Default connection timeout in seconds */

static esp_err_t create_ssl_handle(const char *hostname, size_t hostlen, const void *cfg, esp_tls_t *tls)
Expand Down Expand Up @@ -182,7 +199,7 @@ static esp_err_t esp_tls_hostname_to_fd(const char *host, size_t hostlen, int po
return ESP_ERR_ESP_TLS_CANNOT_CREATE_SOCKET;
}

#if CONFIG_LWIP_IPV4
#if IPV4_ENABLED
if (address_info->ai_family == AF_INET) {
struct sockaddr_in *p = (struct sockaddr_in *)address_info->ai_addr;
p->sin_port = htons(port);
Expand All @@ -191,11 +208,11 @@ static esp_err_t esp_tls_hostname_to_fd(const char *host, size_t hostlen, int po
}
#endif

#if defined(CONFIG_LWIP_IPV4) && defined(CONFIG_LWIP_IPV6)
#if IPV4_ENABLED && IPV6_ENABLED
else
#endif

#if CONFIG_LWIP_IPV6
#if IPV6_ENABLED
if (address_info->ai_family == AF_INET6) {
struct sockaddr_in6 *p = (struct sockaddr_in6 *)address_info->ai_addr;
p->sin6_port = htons(port);
Expand Down

0 comments on commit 38b036e

Please sign in to comment.