Page 1 of 1

How to get server IP for incoming HTTP request?

Posted: Mon Jan 22, 2024 5:34 pm
by trullock
I have a webserver which is bound to 0.0.0.0 so it can respond with the ESP in both Station and Access Point mode simultaneously.

When an incoming request comes in I can see how to get the clientIP using code like this:

Code: Select all

int _socket = accept(serverSocketID, (struct sockaddr * )&_sockAddr, &_addrLen);
...
struct sockaddr_in *sockAddrIn = (struct sockaddr_in *)(&_sockAddr);
IPAddress clientIp(sockAddrIn->sin_addr.s_addr);
But how can I tell what IP the request came in on, i.e. the server IP?

I need to know if the request came from a client connected to the ESP as a AP or STA

Thanks

Re: How to get server IP for incoming HTTP request?

Posted: Tue Jan 23, 2024 3:26 am
by ESP_Sprite
I think you can call getsockname() on that socket to get that info.