vc++ 定义IP地址的函数有那些?
发布网友
发布时间:2022-05-02 11:47
我来回答
共1个回答
热心网友
时间:2022-06-19 23:00
给个函数你吧
gethostbyname 能转换IP地址
CString ResolveHostToIP(CString strHost)
{
CString strRet=_T( " ");
unsigned long ulIP;
hostent *phostent;
LPSTR szAddr;
in_addr inetAddr;
phostent=gethostbyname(strHost);
if(phostent==NULL)
{
strRet.Format( "Can 't resolve %s\r\n ",strHost);
return strRet;
}
ulIP=*(DWORD*)(*phostent-> h_addr_list);
inetAddr.S_un.S_addr=ulIP;
szAddr=inet_ntoa(inetAddr);
strRet.Format( "%s\r\n ",szAddr);
return strRet;
}