esp32_https_server icon indicating copy to clipboard operation
esp32_https_server copied to clipboard

getClientIP() always returns 0.0.0.0

Open IvanZilic opened this issue 4 years ago • 1 comments

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)

IvanZilic avatar Apr 20 '21 12:04 IvanZilic

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)

BojanJurca avatar May 10 '21 14:05 BojanJurca