您的位置:首页 > 其它

CIPADDRESSCTRL 获取本机IP

2011-12-01 12:42 288 查看
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);
}
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: