I have colleagues connecting to my Rabbit 2200 module, downloading data. The Rabbit 2200 waits for connections with tcp_listen and sock_wait_established. I’d like to know who is connecting, by means of their IP address. How do I obtain the IP address of the client from my tcp_socket variable? Is there a function I can call to get details of the client?
You might want to have a look at the source for the psocket library function. It ahs the following line in it for printing out the address:
printf( “[%s:%u]”, inet_ntoa( buffer, s->tcp.hisaddr), s->tcp.hisport);
looking at that, the address is stored in the socket structure.
You will probably need to check with sock_established() first to make sure the connection is made.
Thanks for your answer. I can’t find the source code for psocket. Where is it? I would like to look at it. In the meantime, I have had success with the following code.
static tcp_Socket socket;
struct sockaddr client_info;
printf("Connection established with client %s.
On Dynamic C 10.64 it is in BSDNAME.LIB in the TCPIP lib directory. Type psocket into your source file, put the cursor on it and hit ctrl-H, then select the view source button.
I haven’t looked yet but I imagine the struct definition for the socket data type would have some info on the fields in question.