How to get server IP for incoming HTTP request?

trullock
Posts: 5
Joined: Tue Sep 19, 2023 7:21 pm

How to get server IP for incoming HTTP request?

Postby trullock » Mon Jan 22, 2024 5:34 pm

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

ESP_Sprite
Posts: 9730
Joined: Thu Nov 26, 2015 4:08 am

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

Postby ESP_Sprite » Tue Jan 23, 2024 3:26 am

I think you can call getsockname() on that socket to get that info.

Who is online

Users browsing this forum: Majestic-12 [Bot] and 76 guests