Getting client IP connecting to esp_http_server
Posted: Tue Jun 25, 2019 6:58 am
Hi everybody,
I have started working on esp_http_server and I used "restful_server" example as starting point. So far so good.
I would like to know the IP of the client connecting to the esp_http_server (esp32 is NOT in softAP).
I see that in "components/esp_http_server/src/httpd_main" the function "httpd_accept_conn" accepts the incoming connection and I guess that the IP is retrieve.
Is there any method to "export" the IP of client without necessity to modifiy the esp_http_server components?
I'm using commit 9c6bec2 for esp_http_server component.
Thanks
I have started working on esp_http_server and I used "restful_server" example as starting point. So far so good.
I would like to know the IP of the client connecting to the esp_http_server (esp32 is NOT in softAP).
I see that in "components/esp_http_server/src/httpd_main" the function "httpd_accept_conn" accepts the incoming connection and I guess that the IP is retrieve.
Code: Select all
struct sockaddr_in addr_from;
socklen_t addr_from_len = sizeof(addr_from);
int new_fd = accept(listen_fd, (struct sockaddr *)&addr_from, &addr_from_len);
if (new_fd < 0) {
ESP_LOGW(TAG, LOG_FMT("error in accept (%d)"), errno);
return ESP_FAIL;
}
I'm using commit 9c6bec2 for esp_http_server component.
Thanks