ULONG addr_ip_long = 0; WSADATA winsockData; if (WSAStartup(MAKEWORD(2, 0), &winsockData) != 0) { char szHostName[255] = {0}; if (0 == gethostname(szHostName, 255)) { hostent *ent = gethostbyname(szHostName); if (NULL != ent) { in_addr addr_ip = *(in_addr *)ent->h_addr_list[0]; addr_ip_long = addr_ip.s_addr; } } WSACleanup(); }