获取主机IP地址
LPHOSTENT hostEntry = NULL; char hostName[BUFSIZE]; gethostname(hostName, BUFSIZE); hostEntry = gethostbyname(hostName); if (!hostEntry) { AfxMessageBox(_T("获取主机IP地址失败")); return FALSE; } // 设置sockaddr_in SOCKADDR_IN addrServ; addrServ.sin_addr = *((LPIN_ADDR)*hostEntry->h_addr_list); addrServ.sin_family = AF_INET; addrServ.sin_port = htons(SERVERPORT); char * chIP = inet_ntoa(addrServ.sin_addr); AfxMessageBox(chIP);