diff --git a/components/tcp_transport/CMakeLists.txt b/components/tcp_transport/CMakeLists.txt index 65631fb461..8cbf1ec94d 100644 --- a/components/tcp_transport/CMakeLists.txt +++ b/components/tcp_transport/CMakeLists.txt @@ -8,7 +8,12 @@ list(APPEND srcs "transport_ws.c") endif() +set(req esp-tls) +if(NOT ${IDF_TARGET} STREQUAL "linux") + list(APPEND req lwip) +endif() + idf_component_register(SRCS "${srcs}" INCLUDE_DIRS "include" PRIV_INCLUDE_DIRS "private_include" - REQUIRES esp-tls lwip) + REQUIRES ${req}) diff --git a/components/tcp_transport/transport_ssl.c b/components/tcp_transport/transport_ssl.c index 4c5bd753a7..b2b41881f6 100644 --- a/components/tcp_transport/transport_ssl.c +++ b/components/tcp_transport/transport_ssl.c @@ -6,6 +6,7 @@ #include #include +#include #include "esp_tls.h" #include "esp_log.h" @@ -13,6 +14,7 @@ #include "esp_transport.h" #include "esp_transport_ssl.h" #include "esp_transport_internal.h" +#include "errno.h" #define INVALID_SOCKET (-1) diff --git a/components/tcp_transport/transport_ws.c b/components/tcp_transport/transport_ws.c index daea861390..4f5cc6d779 100644 --- a/components/tcp_transport/transport_ws.c +++ b/components/tcp_transport/transport_ws.c @@ -6,6 +6,7 @@ #include #include +#include #include #include #include @@ -16,6 +17,7 @@ #include "esp_transport_internal.h" #include "errno.h" #include "esp_tls_crypto.h" +#include static const char *TAG = "transport_ws"; @@ -145,7 +147,11 @@ static int ws_connect(esp_transport_handle_t t, const char *host, int port, int } unsigned char random_key[16]; - getrandom(random_key, sizeof(random_key), 0); + ssize_t rc; + if ((rc = getrandom(random_key, sizeof(random_key), 0)) < 0) { + ESP_LOGD(TAG, "getrandom() returned %zd", rc); + return -1; + } // Size of base64 coded string is equal '((input_size * 4) / 3) + (input_size / 96) + 6' including Z-term unsigned char client_key[28] = {0}; @@ -289,7 +295,11 @@ static int _ws_write(esp_transport_handle_t t, int opcode, int mask_flag, const if (mask_flag) { mask = &ws_header[header_len]; - getrandom(ws_header + header_len, 4, 0); + ssize_t rc; + if ((rc = getrandom(ws_header + header_len, 4, 0)) < 0) { + ESP_LOGD(TAG, "getrandom() returned %zd", rc); + return -1; + } header_len += 4; for (i = 0; i < len; ++i) {