diff --git a/component.mk b/component.mk
index 9afdeb6f7cf713a751d571559b898daf7db4fd40..67b8abb7eda99385910871d929101d1e1b7fe9e0 100644
--- a/component.mk
+++ b/component.mk
@@ -25,7 +25,7 @@ build:
 		-DBUILD_DIR_BASE=$(BUILD_DIR_BASE) \
 		-DCMAKE_TOOLCHAIN_FILE=$(COMPONENT_PATH)/contrib/cross-esp32.cmake \
 		-DCMAKE_BUILD_TYPE=RELEASE \
-		-DLWS_MBEDTLS_INCLUDE_DIRS="${IDF_PATH}/components/openssl/include;${IDF_PATH}/components/mbedtls/include;${IDF_PATH}/components/mbedtls/port/include" \
+		-DLWS_MBEDTLS_INCLUDE_DIRS="${IDF_PATH}/components/openssl/include;${IDF_PATH}/components/mbedtls/mbedtls/include;${IDF_PATH}/components/mbedtls/port/include" \
 		-DLWS_WITH_STATS=0 \
 		-DLWS_WITH_HTTP2=1 \
 		-DLWS_WITH_RANGES=1 \
diff --git a/contrib/cross-esp32.cmake b/contrib/cross-esp32.cmake
index 6487f7648d3d204f640ba94a2ecf6072a78247b0..406763c61d97322e935e5eec23d6b455b34dc9b6 100644
--- a/contrib/cross-esp32.cmake
+++ b/contrib/cross-esp32.cmake
@@ -17,6 +17,7 @@ set(CMAKE_LINKER	"${CROSS_PATH}/bin/xtensa-esp32-elf-ld${EXECUTABLE_EXT}")
 
 SET(CMAKE_C_FLAGS "-nostdlib -Wall -Werror \
 	-I${BUILD_DIR_BASE}/include \
+	-I${IDF_PATH}/components/newlib/platform_include \
 	-I${IDF_PATH}/components/mdns/include \
 	-I${IDF_PATH}/components/heap/include \
 	-I${IDF_PATH}/components/driver/include \
diff --git a/lib/core/private.h b/lib/core/private.h
index 6766e47d6e901486ba8050a234ebfb44fd8c91ff..7b94782a058a2b2e39b3b0b0e945de3efbded83d 100644
--- a/lib/core/private.h
+++ b/lib/core/private.h
@@ -93,18 +93,12 @@
 
 #define LWS_H2_RX_SCRATCH_SIZE 512
 
-#ifndef LWS_HAVE_BZERO
- #ifndef bzero
-  #define bzero(b, len) (memset((b), '\0', (len)), (void) 0)
- #endif
-#endif
+#define lws_socket_is_valid(x) (x != LWS_SOCK_INVALID)
 
 #ifndef LWS_HAVE_STRERROR
  #define strerror(x) ""
 #endif
 
-#define lws_socket_is_valid(x) (x != LWS_SOCK_INVALID)
-
  /*
   *
   *  ------ private platform defines ------
@@ -125,6 +119,12 @@
  #endif
 #endif
 
+#ifndef LWS_HAVE_BZERO
+ #ifndef bzero
+  #define bzero(b, len) (memset((b), '\0', (len)), (void) 0)
+ #endif
+#endif
+
  /*
   *
   *  ------ public api ------
diff --git a/lib/plat/esp32/esp32-service.c b/lib/plat/esp32/esp32-service.c
index 0d1d84d63d93d7b2eb52664c586e166441c3d287..3549d9d49dd2bd5d3c209a597649c974397bba3b 100644
--- a/lib/plat/esp32/esp32-service.c
+++ b/lib/plat/esp32/esp32-service.c
@@ -126,25 +126,25 @@ _lws_plat_service_tsi(struct lws_context *context, int timeout_ms, int tsi)
 			if (pt->fds[n].fd >= max_fd)
 				max_fd = pt->fds[n].fd;
 			if (pt->fds[n].events & LWS_POLLIN)
-				FD_SET(pt->fds[n].fd - LWIP_SOCKET_OFFSET, &readfds);
+				FD_SET(pt->fds[n].fd, &readfds);
 			if (pt->fds[n].events & LWS_POLLOUT)
-				FD_SET(pt->fds[n].fd - LWIP_SOCKET_OFFSET, &writefds);
-			FD_SET(pt->fds[n].fd - LWIP_SOCKET_OFFSET, &errfds);
+				FD_SET(pt->fds[n].fd, &writefds);
+			FD_SET(pt->fds[n].fd, &errfds);
 		}
 
 		n = select(max_fd + 1, &readfds, &writefds, &errfds, ptv);
 		n = 0;
 		for (m = 0; m < pt->fds_count; m++) {
 			c = 0;
-			if (FD_ISSET(pt->fds[m].fd - LWIP_SOCKET_OFFSET, &readfds)) {
+			if (FD_ISSET(pt->fds[m].fd, &readfds)) {
 				pt->fds[m].revents |= LWS_POLLIN;
 				c = 1;
 			}
-			if (FD_ISSET(pt->fds[m].fd - LWIP_SOCKET_OFFSET, &writefds)) {
+			if (FD_ISSET(pt->fds[m].fd, &writefds)) {
 				pt->fds[m].revents |= LWS_POLLOUT;
 				c = 1;
 			}
-			if (FD_ISSET(pt->fds[m].fd - LWIP_SOCKET_OFFSET, &errfds)) {
+			if (FD_ISSET(pt->fds[m].fd, &errfds)) {
 				// lwsl_notice("errfds %d\n", pt->fds[m].fd);
 				pt->fds[m].revents |= LWS_POLLHUP;
 				c = 1;
diff --git a/lib/plat/esp32/esp32-sockets.c b/lib/plat/esp32/esp32-sockets.c
index 8f3b658a22d1c9965f841ebc81898beb68bf2039..dac37584d0769bd8af0c0bba5125cabae887a99e 100644
--- a/lib/plat/esp32/esp32-sockets.c
+++ b/lib/plat/esp32/esp32-sockets.c
@@ -48,7 +48,7 @@ lws_send_pipe_choked(struct lws *wsi)
 		return 1;
 
 	FD_ZERO(&writefds);
-	FD_SET(wsi_eff->desc.sockfd - LWIP_SOCKET_OFFSET, &writefds);
+	FD_SET(wsi_eff->desc.sockfd, &writefds);
 
 	n = select(wsi_eff->desc.sockfd + 1, NULL, &writefds, NULL, &tv);
 	if (n < 0)
@@ -64,7 +64,7 @@ lws_poll_listen_fd(struct lws_pollfd *fd)
 	struct timeval tv = { 0, 0 };
 
 	FD_ZERO(&readfds);
-	FD_SET(fd->fd - LWIP_SOCKET_OFFSET, &readfds);
+	FD_SET(fd->fd, &readfds);
 
 	return select(fd->fd + 1, &readfds, NULL, NULL, &tv);
 }