getClientIP() always returns 0.0.0.0
Describe the bug getClientIP() always returns 0.0.0.0. This value is returned when web server is accessed either via direct WiFi connection (AP) or via infrastructure (WiFi STA).
How To Reproduce In a HTTP requests handling function printout Client IP address. Like: void www_HandleFile(HTTPRequest *req, HTTPResponse *res) { ... Serial.println(req->getClientIP()); ... }
Expected Behavior Correct Client IP address should be returned.
Actual Behavior Client IP address is always 0.0.0.0
ESP32 Module Please provide specifications of your module
- Generic ESP32 module
Software (please complete the following information if applicable)
- IDE and Version: Arduino 1.8.13
- OS: Ubuntu 16.04 LTS
- Client used to access the server: Various (eg. Firefox 68.9.0esr, 64-bit)
Taking a brief look into HTTPConnection.cpp code a private variable _sockAddr should get initialised (probably in HTTPConnection::initialize or after accept) but it doesn't, so the function:
**IPAddress HTTPConnection::getClientIP() { if (_addrLen > 0 && _sockAddr.sa_family == AF_INET) { struct sockaddr_in sockAddrIn = (struct sockaddr_in )(&_sockAddr); return IPAddress(sockAddrIn->sin_addr.s_addr); } return IPAddress(0, 0, 0, 0); }
always returns IPAddress(0, 0, 0, 0)