Client IP address in Web Server

Hi to all,

I’m trying to display the ip address of the client that connects to the home page of the “HTTP Server Sample”.
I have followed the topic “Client IP address in AWS” but I do not know what to enter as parameters in function “int RpGetRemoteIpAddress (void * theTaskDataPointer, StcpIpAddress theIpAddress *).”
Someone could post a code example?

Thanks in advance!

Please, an example of setting the variable " StcpIpAddress theIpAddress * "

Look in the API reference guide under internetworking\Web Servers\Advanced Web Server\Functions. LOok for function RpHSGetServerData. If you call this function, it will hand you a void *. This is the web servers internal data structure. You are not allowed to change it, but it is used by many web server calls.

SO void * theWSPointer = RpHSGetServerData();
Make sure you check the resulk for NULL. If the call returns NULL, then the web server is not running.

StcpIpAddress theIpAddress * is the place where the address will be placed by RpGetRemoteIpAddress. So just declare a variable of type
StcpIpAddress. BTW StcpIpAddress is a sockaddr_storage. This type is also described in the API reference guide. When you call RpGetRemoteIpAddress, make sure you pass a pointer to your address variable.

BTW there is also a API called RpGetConnectionInformation that returns both ip address and port of the client.

Also please be mindful that when returned a variable of type sockaddr_storage you must (I repeat must) check the family of the address BEFORE disecting the address from the structure. The returned address could be either IPv4 or IPv6. Since starting in NET+OS V7.0 the stack supports IPv4 and IPv6 many calls now return IPv6 formatted addresses. This means that if the client is IPv4, the address is an IPv6-mapped IPv4 address.

Just perfect!
Many many thanks dakotas_dad

ps: if someone need I can post my code