首页 > 其他分享 >vc-获取本机IP

vc-获取本机IP

时间:2022-11-08 10:35:35浏览次数:48  
标签:vc struct IP hostname char phost ip iplist 本机


static CString GetLocalIp()
{
struct hostent * phost;
char ip[20];
char hostname[50];

gethostname(hostname, 50);
phost = gethostbyname(hostname);
char * * names;
names = phost->h_aliases;
char * * iplist;
iplist = phost->h_addr_list;
while (* iplist)
{
strcpy(ip, inet_ntoa(* (struct in_addr *) * iplist));
iplist++;
}

CString LocalIp = ip;
return LocalIp;
}


标签:vc,struct,IP,hostname,char,phost,ip,iplist,本机
From: https://blog.51cto.com/u_13316945/5831994

相关文章