mirror of
https://github.com/espressif/esp-idf.git
synced 2024-10-05 20:47:46 -04:00
Merge branch 'contrib/github_pr_10967' into 'master'
[esp-tls] Add addr_family option to esp_tls_cfg_t (GitHub PR) Closes IDFGH-9620 See merge request espressif/esp-idf!22892
This commit is contained in:
commit
8d90249829
@ -170,12 +170,24 @@ esp_tls_t *esp_tls_init(void)
|
||||
return tls;
|
||||
}
|
||||
|
||||
static esp_err_t esp_tls_hostname_to_fd(const char *host, size_t hostlen, int port, struct sockaddr_storage *address, int* fd)
|
||||
static esp_err_t esp_tls_hostname_to_fd(const char *host, size_t hostlen, int port, esp_tls_addr_family_t addr_family, struct sockaddr_storage *address, int* fd)
|
||||
{
|
||||
struct addrinfo *address_info;
|
||||
struct addrinfo hints;
|
||||
memset(&hints, 0, sizeof(hints));
|
||||
hints.ai_family = AF_UNSPEC;
|
||||
|
||||
switch(addr_family) {
|
||||
case ESP_TLS_AF_INET:
|
||||
hints.ai_family = AF_INET;
|
||||
break;
|
||||
case ESP_TLS_AF_INET6:
|
||||
hints.ai_family = AF_INET6;
|
||||
break;
|
||||
default:
|
||||
hints.ai_family = AF_UNSPEC;
|
||||
break;
|
||||
}
|
||||
|
||||
hints.ai_socktype = SOCK_STREAM;
|
||||
|
||||
char *use_host = strndup(host, hostlen);
|
||||
@ -319,7 +331,7 @@ static inline esp_err_t tcp_connect(const char *host, int hostlen, int port, con
|
||||
{
|
||||
struct sockaddr_storage address;
|
||||
int fd;
|
||||
esp_err_t ret = esp_tls_hostname_to_fd(host, hostlen, port, &address, &fd);
|
||||
esp_err_t ret = esp_tls_hostname_to_fd(host, hostlen, port, cfg->addr_family, &address, &fd);
|
||||
if (ret != ESP_OK) {
|
||||
ESP_INT_EVENT_TRACKER_CAPTURE(error_handle, ESP_TLS_ERR_TYPE_SYSTEM, errno);
|
||||
return ret;
|
||||
|
@ -71,6 +71,15 @@ typedef struct tls_keep_alive_cfg {
|
||||
int keep_alive_count; /*!< Keep-alive packet retry send count */
|
||||
} tls_keep_alive_cfg_t;
|
||||
|
||||
/*
|
||||
* @brief ESP-TLS Address families
|
||||
*/
|
||||
typedef enum esp_tls_addr_family {
|
||||
ESP_TLS_AF_UNSPEC = 0, /**< Unspecified address family. */
|
||||
ESP_TLS_AF_INET, /**< IPv4 address family. */
|
||||
ESP_TLS_AF_INET6, /**< IPv6 address family. */
|
||||
} esp_tls_addr_family_t;
|
||||
|
||||
/**
|
||||
* @brief ESP-TLS configuration parameters
|
||||
*
|
||||
@ -182,6 +191,8 @@ typedef struct esp_tls_cfg {
|
||||
#ifdef CONFIG_ESP_TLS_CLIENT_SESSION_TICKETS
|
||||
esp_tls_client_session_t *client_session; /*! Pointer for the client session ticket context. */
|
||||
#endif /* CONFIG_ESP_TLS_CLIENT_SESSION_TICKETS */
|
||||
|
||||
esp_tls_addr_family_t addr_family; /*!< The address family to use when connecting to a host. */
|
||||
} esp_tls_cfg_t;
|
||||
|
||||
#ifdef CONFIG_ESP_TLS_SERVER
|
||||
|
Loading…
Reference in New Issue
Block a user