Getting the IP address of the local machine
#include <winsock.h>
BOOL GetIP(LPSTR straddr) { char szHostname[100]; HOSTENT *pHent; int nAdapter = 0; SOCKADDR_IN sinRemote; gethostname( szHostname, sizeof( szHostname )); pHent = gethostbyname( szHostname ); if (pHent != NULL) { sinRemote.sin_addr.s_addr = *(u_long *)pHent->h_addr; sprintf(straddr,"%d.%d.%d.%d", sinRemote.sin_addr.S_un.S_un_b.s_b1, sinRemote.sin_addr.S_un.S_un_b.s_b2, sinRemote.sin_addr.S_un.S_un_b.s_b3, sinRemote.sin_addr.S_un.S_un_b.s_b4); } else *straddr=NULL; return (pHent != NULL); }