char name[255];//hostname
CString ip;//ip string
PHOSTENT hostinfo;//phostent struct
if (gethostname(name,sizeof(name))==0)//hostname-->name
{
if ((hostinfo=gethostbyname(name))!=NULL)//hostinfo init
{
ip=inet_ntoa(*(struct in_addr*)*hostinfo->h_addr_list);//convert member variable h_addr_list(ip) into a string in dotted format
GetDlgItem(IDC_IPADDRESS1)->SetWindowText(ip);
}
}
CIPADDRESSCTRL 获取本机IP
最新推荐文章于 2020-08-06 18:37:35 发布