Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to find a clients IP 2

Status
Not open for further replies.

ForeverCode

Programmer
Dec 6, 2002
41
US
I'm having issues getting a client's IP address while using regular Sockets. Do I use "gethostbyname()" or what? Does anyone know how to do it?

-Micah
 
[tt]CString GetLocalAddress(void)
{
char* buffer="";
gethostname (buffer,strlen(buffer));
HOSTENT* lpHostEnt = gethostbyname(buffer);
if (lpHostEnt==NULL) return "127.0.0.1";
CString lpAddr = (char*)inet_ntoa(*(LPIN_ADDR)*(lpHostEnt->h_addr_list));
return lpAddr;
}[/tt]

returns 127.0.0.1 if user not connected to a network - otherwise returns local IP address
tellis.gif

programmer (prog'ram'er), n A hot-headed, anorak wearing, pimple-faced computer geek.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top