In C or C++ it is fairly simple to find the IP address of the remote end of a TCP socket.
The following example shows how to do this using the getpeername() and inet_ntoa() system calls.
int sockfd;
int len;
char * hostip;
struct sockaddr_in sin;
len = sizeof(sin);
if (0 != getpeername(sockfd, (struct sockaddr *) &sin, &len))
perror("getpeername");
}
hostip = inet_ntoa(sin.sin_addr);
printf("client IP: %s\n", hostip);