Home/Support/Support Forum/Client IP address in Web Server
Welcome to Digi Forum, where you can ask questions and receive answers from other members of the community.

Client IP address in Web Server

0 votes
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!
asked Nov 23, 2012 in NET+OS by Rubber New to the Community (11 points)
recategorized Dec 4, 2013 by tuxembb

Please log in or register to answer this question.

3 Answers

0 votes
Please, an example of setting the variable " StcpIpAddress theIpAddress * "
answered Nov 27, 2012 by Rubber New to the Community (11 points)
0 votes
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.
answered Nov 27, 2012 by dakotas_dad Veteran of the Digi Community (694 points)
0 votes
Just perfect!
Many many thanks dakotas_dad

ps: if someone need I can post my code
answered Nov 28, 2012 by Rubber New to the Community (11 points)
...