
Obtaining your IP Address
Quote:
> I was wondering if anyone knows how to obtain the local IP address of a
> machine. Is there a Winsock function to do this? (and I'm not talking about
> using winipcfg, I want to be able to do what winipcfg does)
> Thanks,
> Ben
You want to look at WSAStartup and gethostname:
HOSTENT * Host;
WSADATA wsaData;
char Str[128];
WSAStartup( MAKEWORD(2,0), &wsaData );
gethostname ( Str, sizeof(Str) );
Host = gethostbyname ( Str );
Str[0]='\0';
for( int i=0; Host->h_addr_list[i]; i++ )
sprintf( Str+strlen(Str), "%u.%u.%u.%u ",
Host->h_addr_list[i][0]&0xFF, Host->h_addr_list[i][1]&0xFF,
Host->h_addr_list[i][2]&0xFF, Host->h_addr_list[i][3]&0xFF );
MessageBox( Str );
Hope that helps,
Joe