Oct 8, 2013

[C++] How to check client`s IP address.

When you call  accept(),  you will have client`s  information in  SOCKADDR_IN structure. 
 SOCKADDR_IN clntAddr; 
int addrLen = sizeof(clntAddr);  
SOCKET hSocket = ::accept(mListenSocket, (SOCKADDR*)&clntAddr, &addrLen); 
printf("Server IP = %s\n"inet_ntoa(clntAddr.sin_addr)); 

Result will be like this:     "Server IP = 211.22.32.15" 

No comments:

Post a Comment