CIPADDRESSCTRL 獲取本機IP

 
	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);
		}
	}

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章