Get hostname and ip address of local computer
Posted
by Jeff Lundgren
on February 9th, 1999
Requirements
#include <winsock2.h>
Link with Wsock32.lib
That's It.
{
WORD wVersionRequested;
WSADATA wsaData;
char name[255];
CString ip;
PHOSTENT hostinfo;
wVersionRequested = MAKEWORD( 2, 0 );
if ( WSAStartup( wVersionRequested, &wsaData ) == 0 )
{
if( gethostname ( name, sizeof(name)) == 0)
{
if((hostinfo = gethostbyname(name)) != NULL)
{
ip = inet_ntoa (*(struct in_addr *)*hostinfo->h_addr_list);
}
}
WSACleanup( );
}
}
Article moved from Internet section on January 26 1999

Comments
There are no comments yet. Be the first to comment!