获取本地IP地址,直接上代码:
BOOL GetLocalPCIPAdrdr(CString& csIPAddr)
{
BOOL bRet = FALSE;
char szHostName[128] = {0};
int iRet;
WSADATA wsaData;
struct hostent *pHost;
int i;
LPCSTR psz;
WSAStartup(MAKEWORD(2, 2), &wsaData);
iRet = gethostname(szHostName , 128);
if(iRet == 0)
{
pHost = gethostbyname(szHostName);
for(i=0; pHost!=NULL&&pHost->h_addr_list[i]!=NULL;i++)
{
psz = inet_ntoa(*(struct in_addr*)pHost->h_addr_list[i]);
}
csIPAddr = psz;
bRet = TRUE;
}
return bRet;
}